Пример #1
0
	def __init__(self, 
				 position, 
				 image,
				 padding=(0,0,0,0), 
				 action='No action', 
				 camera_target=None,
				 physical=False,
				 physical_padding=(0,0)):
		#self.padding = padding
		self.position = position
		self.padding = padding
		self.action = action
		self.physical = physical

		image = pyglet.resource.image(image)
		
		normal_image 	= image.get_region(0,	image.height*2//3,	image.width,	image.height*1//3)
		hover_image 	= image.get_region(0,	image.height*1//3,	image.width,	image.height*1//3)
		press_image 	= image.get_region(0,	0,					image.width,	image.height*1//3)

		self.box_size = normal_image.width+physical_padding[0], normal_image.height+physical_padding[1]
		self.sprite = loaders.image_sprite_loader(normal_image,
														anchor = ('center','center'),
														pos = position,
														linear_interpolation = True)
		self.hover_sprite = loaders.image_sprite_loader(hover_image,
														placeholder = 'empty.png',
														anchor = ('center','center'),
														pos = position,
														linear_interpolation = True)
		self.hover_sprite.visible = False
		self.press_sprite = loaders.image_sprite_loader(press_image,
														placeholder = 'empty.png',
														anchor = ('center','center'),
														pos = position,
														linear_interpolation = True)
		self.press_sprite.visible = False

		
		alpha = 255
		self.color = (200,0,0,alpha)
		self.color2 = (0,200,0,alpha)
		self.color3 = (200,200,0,alpha)

		self.clicked = False

		if camera_target != None:
			self.camera_target_x = camera_target[0]
			self.camera_target_y = camera_target[1]
		else:
			self.camera_target_x = None
			self.camera_target_y = None
		self.camera_move = False
		self.do_action = False
		self.pressed = False
Пример #2
0
 def __init__(self,age,img,batch=None,group=None,*strategies,age_offset=(0,100)):
     self.x,self.y = 0,0
     self.vel = Vec2d(0,0)
     self.sprite = loaders.image_sprite_loader(img,
                                               pos = (self.x,self.y),
                                               anchor = ('center', 'center'),
                                               batch = batch, 
                                               group = group,
                                               linear_interpolation = True)
     self.age = age + randint(age_offset[0],age_offset[1])
     self.alive = age 
     self.strategies = strategies
Пример #3
0
	def setup_pyglet_batch(self, level_batch, ui_batch, ordered_group, ordered_group2, ordered_group3, screen_res, ordered_group_bg=None):
		self.ui_batch = ui_batch
		self.sprite.batch = level_batch
		self.sprite.group = ordered_group3
		self.screen_res = screen_res


		self.mask_width = 200
		self.orig_mask_width = self.mask_width
		self.mask_height = 10

		self.mask_x = (screen_res[0]//2)-(self.mask_width//2)
		self.mask_y = self.bar_pos

		###

		img = pyglet.resource.image('p_b.png')
		bar_height = img.height//2
		bar_width = (img.width//2)

		self.mask_group = GroupWithMask(self.mask_x,self.mask_y,
										self.mask_width,bar_height, 
										parent=ordered_group2)
		
		l_cap_b_img = img.get_region(0,0,img.width//2,bar_height)
		self.l_cap_b = loaders.image_sprite_loader(l_cap_b_img, 
												   pos 						= (self.mask_x,self.mask_y),
												   batch 					= ui_batch,
												   group 					= ordered_group,
												   anchor 				    = (bar_width,0),
												   linear_interpolation 	= True)
		r_cap_b_img = img.get_region(bar_width+1,0,bar_width,bar_height)
		self.r_cap_b = loaders.image_sprite_loader(r_cap_b_img, 
												   pos 						= (self.mask_x+self.mask_group.width,self.mask_y),
												   batch 					= ui_batch,
												   group 					= ordered_group,
												   anchor 				    = (0,0),
												   linear_interpolation 	= True)

		b_meter = pyglet.image.Texture.create(self.mask_group.width,bar_height)
		b_meter_img = img.get_region(bar_width,0,1,bar_height).get_image_data()
		offset = 0
		while offset <= self.mask_group.width:
			b_meter.blit_into(b_meter_img,offset,0,0)
			offset += 1
		self.b_meter = loaders.image_sprite_loader(b_meter, 
												   pos 						= (self.mask_x,self.mask_y),
												   batch 					= ui_batch,
												   group 					= ordered_group,
												   anchor 					= (0,0),
												   linear_interpolation 	= True)

		##

		l_cap_f_img = img.get_region(0,bar_height,bar_width,bar_height)
		self.l_cap_f = loaders.image_sprite_loader(l_cap_f_img, 
												   pos 						= (self.mask_x,self.mask_y),
												   batch 					= ui_batch,
												   group 					= ordered_group2,
												   anchor 				    = (bar_width,0),
												   linear_interpolation 	= True)
		r_cap_f_img = img.get_region(bar_width+1,bar_height,bar_width,bar_height)
		self.r_cap_f = loaders.image_sprite_loader(r_cap_f_img, 
												   pos 						= (self.mask_x+self.mask_group.width,self.mask_y),
												   batch 					= ui_batch,
												   group 					= ordered_group2,
												   anchor 				    = (0,0),
												   linear_interpolation 	= True)

		f_meter = pyglet.image.Texture.create(self.mask_group.width,bar_height)
		f_meter_img = img.get_region(bar_width,bar_height,1,bar_height).get_image_data()
		offset = 0
		while offset <= self.mask_group.width:
			f_meter.blit_into(f_meter_img,offset,0,0)
			offset += 1
		self.f_meter = loaders.image_sprite_loader(f_meter, 
												   pos 						= (self.mask_x,self.mask_y),
												   batch 					= ui_batch,
												   group 					= self.mask_group,
												   anchor 					= (0,0),
												   linear_interpolation 	= True)

		if self.bar_blend != (255,255,255):
			self.l_cap_f.color,self.r_cap_f.color,self.f_meter.color = self.bar_blend,self.bar_blend,self.bar_blend

		self.sprite_list = [self.l_cap_b,self.r_cap_b,self.b_meter,
							self.l_cap_f,self.r_cap_f,self.f_meter]


		self.power_label = pyglet.text.Label(text = self.pwr_type,
											 font_name = 'Calibri', font_size = 8, bold = True,
											 x = screen_res[0]//2, y = self.mask_y+16, 
											 anchor_x = 'center', anchor_y = 'center',
											 color = (255,255,255,255),
											 batch = ui_batch,
											 group=ordered_group2)

		self.power_label_shadow = pyglet.text.Label(text = self.pwr_type,
											 		font_name = 'Calibri', font_size = 8, bold = True,
											 		x = screen_res[0]//2, y = self.mask_y+16, 
											 		anchor_x = 'center', anchor_y = 'center',
											 		color = (0,0,0,240),
											 		batch = ui_batch,
											 		group=ordered_group)

		self.background_sprite = loaders.spriteloader('progress_bar_container.png', 
								  					  pos 						= (screen_res[0]//2,-20),
								  					  anchor 					= ('center','center'),
								  					  batch 					= ui_batch,
								  					  group 					= ordered_group_bg,
								  					  linear_interpolation 	=	 True)

		self.flash = False

		self.smooth = self.bar_pos

		self.a = 1
		self.emitter = particles2D.Emitter(pos = self.position)
		particle_img = pyglet.resource.image('spark.png')
		self.factory = particles2D.powerup(.5,
										   ((-1,1),(.1,2.5)),
										   particle_img,
										   color_overlay=self.blend_img,
										   batch=level_batch,
										   group=ordered_group3)
		self.emitter_spurt = particles2D.Spurt(self.emitter)
Пример #4
0
	def __init__(self, 
				 position, 
				 image,
				 padding=(0,0,0,0), 
				 action='No action', 
				 camera_target=None,
				 physical=False):
		#self.padding = padding
		self.position = position
		self.action = action
		self.physical = physical

		image = pyglet.resource.image(image)
		
		normal_image 	= image.get_region(0,	image.height*2//3,	image.width,	image.height*1//3)
		hover_image 	= image.get_region(0,	image.height*1//3,	image.width,	image.height*1//3)
		press_image 	= image.get_region(0,	0,					image.width,	image.height*1//3)

		self.box_size = normal_image.width,normal_image.height
		'''
		normal_image 	= image.get_region(0,74,103,37)
		hover_image 	= image.get_region(0,37,103,37)
		press_image 	= image.get_region(0,0,103,37)
		'''
		self.sprite = loaders.image_sprite_loader(normal_image,
														anchor = ('center','center'),
														pos = position,
														linear_interpolation = True)
		self.hover_sprite = loaders.image_sprite_loader(hover_image,
														placeholder = 'empty.png',
														anchor = ('center','center'),
														pos = position,
														linear_interpolation = True)
		self.hover_sprite.visible = False
		self.press_sprite = loaders.image_sprite_loader(press_image,
														placeholder = 'empty.png',
														anchor = ('center','center'),
														pos = position,
														linear_interpolation = True)
		self.press_sprite.visible = False

		padding_left = self.sprite.image.width//2 + padding[0]
		padding_bottom = self.sprite.image.height//2 + padding[1]
		padding_right = self.sprite.image.width//2 + padding[2]
		padding_top = self.sprite.image.height//2 + padding[3]

		self.left = (position[0] - padding_left, position[1] + padding_top)
		self.bottom = (position[0] - padding_left, position[1]- padding_bottom)
		self.right = (position[0] + padding_right, position[1]- padding_bottom)
		self.top = (position[0] + padding_right, position[1] + padding_top)

		self.bb = pymunk.BB(position[0] - padding_left, #- hinge_pos[0], # left
							position[1] - padding_bottom, #  - hinge_pos[1], # bottom
							position[0] + padding_right, # - hinge_pos[0], # right
							position[1] + padding_top) # - hinge_pos[1]) # top
		alpha = 255
		self.color = (200,0,0,alpha)
		self.color2 = (0,200,0,alpha)
		self.color3 = (200,200,0,alpha)

		self.clicked = False

		if camera_target != None:
			self.camera_target_x = camera_target[0]
			self.camera_target_y = camera_target[1]
		else:
			self.camera_target_x = None
			self.camera_target_y = None
		self.camera_move = False
		self.do_action = False
		self.pressed = False
		self.n_scroll = 0