Exemplo n.º 1
0
def register_entity(entity, sprite_group, sprite_name, scale=1, smooth_draw=True):
	if display.RABBYT:
		entity['image'] = sprite_name
	else:
		entity['image'] = display.load_image(sprite_name)
	
	entity['sprite'] = display.create_sprite(entity['image'], 0, 0, sprite_group)
	entity['sprite_group'] = sprite_group
	entity['last_rotation'] = 0
	entity['next_rotation'] = 0
	entity['rotation_speed'] = 0
	entity['last_scale'] = scale
	entity['next_scale'] = scale
	entity['smooth_draw'] = smooth_draw
	entity['scale_only'] = False
	
	entities.create_event(entity, 'redraw')
	entities.create_event(entity, 'set_scale')
	entities.create_event(entity, 'set_rotation')
	entities.create_event(entity, 'rotate_by')
	entities.create_event(entity, 'fade_by')
	entities.register_event(entity, 'tick', tick)
	entities.register_event(entity, 'redraw', lambda _entity: entities.register_event(_entity, 'loop', loop))
	entities.register_event(entity, 'delete', display.delete_sprite)
	entities.register_event(entity, 'set_scale', set_scale)
	entities.register_event(entity, 'set_rotation', set_rotation)
	entities.register_event(entity, 'rotate_by', rotate_by)
	entities.register_event(entity, 'fade_by', fade_by)
	entities.register_event(entity, 'loop', loop)
Exemplo n.º 2
0
    def __init__(self, ip, player_xy):
        pygame.sprite.Sprite.__init__(self)
        
        #calculate trajectory for X, Y of direction.
        #This code is still wonky and needs some work. 
        step = -5
        opp = float(ip[1] - player_xy[1])   
        #Calculates Tangent. Needs opposite side of right triangle
        adj = float(ip[0] - player_xy[0])
        #And adjacent side Tangent = Opposite or Adjacent
        tang = opp / adj
        
        bigstep = tang * step #Modifies STEP to get a proportional x,y step each update 
        #a 45* angle will have an equal step and bigstep
        
        if adj > 0: 
            direction = (step, bigstep)
        else:
            direction = (bigstep, step)

        self.dir = direction            #Keeping this a seperate line for now 
        self.image, self.rect = display.load_image("bullet.png", -1) #Loads bullet graphic 
        if self.dir[0] < 0:                                          #Bullet is going other way
            self.image = pygame.transform.flip(self.image, True, False)
        self.rect.bottomleft = ip       # Starts at top of the Target graphic    
        self.next_update_time = 0       
        self.power = 20                 #How much power the bullet has to damage the player
Exemplo n.º 3
0
 def __init__(self, ip):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = display.load_image("redball.png", -1)   
     #Just a simple red ballon graphic
     self.rect.topleft = ip              
     #Sets the balloon start position to the bottom center of the player graphic                                           
     self.next_update_time = 0           #Sets the update timer
Exemplo n.º 4
0
def new_game_object(pos, image_name, data=None):
    # Function to handle loading of image and initialisation of class.
    # data is an optional argument
    img_idx = display.load_image(image_name)
    width = display.images[img_idx].get_width()
    height = display.images[img_idx].get_height()
    return Game_object(pos, img_idx, height, width, data)
Exemplo n.º 5
0
def convert(file):
    "Convert a PBM file into a one-liner of Python code for generating the corresponding framebuf object"
    print( "_xx_s = b'", end="")
    b = BitStr()
    f, w, h = display.load_image(file)
    for y in range(0, h):
        for x in range(0, w):
            b.push(f.pixel(x,y))
        b.newline()
    b.print()
    print("'\nxx = (_xx_s, {},{})".format(w, h))
Exemplo n.º 6
0
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        
        self.image, self.rect = display.load_image("balloon.png", -1)
        
        self.rect.topleft = display.env.initial_position    #sets the balloon start at IP 
        self.score = 0                                      #points total over game
        self.points = 0                                     #points this round
        self.health = display.env.max_health                #current health is 100
        self.hbarpos = (0,20)                               #Health bar initial position
#        self.pause_map = False                              #used for testing

        self.vert_state = 0
        self.horz_state = 0
        self.fire_timer = 0
Exemplo n.º 7
0
 def __init__(self, d, images, state_callback, pos=None):
     """
     Manage one display indicator icon.
     The icon to be displayed at any time is determined by the state_callback funtion.
     pos is the position (in pixels) on the screen. If blank, the next slot will be allocated from the display.
     the indicator registers itself with Display. No need to keep a variable for it.
     """
     self.d = d  #Display
     self.callback = state_callback
     self.last_img = None
     self.img = []
     for i in images:
         img, width, height = display.load_image(i)
         self.img.append(img)
     self.x_pos = d.register_indicator(self, 0 if pos else width + 2)
Exemplo n.º 8
0
 def get_graphic(self):
     self.graphic, self.rect = display.load_image("popcornstand.png", -1)
Exemplo n.º 9
0
 def get_graphic(self):
     self.graphic, self.rect = display.load_image("gang1.png", -1)
Exemplo n.º 10
0
 def get_graphic(self):
     self.graphic, self.rect = display.load_image("oldlady.png", -1)
Exemplo n.º 11
0
 def get_graphic(self):
     self.graphic, self.rect = display.load_image("bullseye.png", -1)
Exemplo n.º 12
0
 def __init__(self, ip):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = display.load_image("splashmod.png", -1) #Dorky graphic for splash
     self.rect.topleft = ip                                      #Replaces the ballon IP
     self.next_update_time = 0                                   
     self.create_time = pygame.time.get_ticks()  #Sets a creation time