def __init__(self): gameobject.GameObject.__init__(self) self.image = config.SPRITES.subsurface(pygame.Rect(32, 64, 64, 32)).copy() # The UFO image; by default, the plain white one (it will be recolored) self.frames = tuple(color.blend_color(self.image.copy(), c) for c in color.LIST[: config.NUM_COLORS]) # The colors that the UFO cycles through self.rect = pygame.Rect(START_POS, self.image.get_size()) # The collision boundary of the USO self.position = list(START_POS) for c in self.frames: # For all colored UFO sprites... c.set_colorkey(c.get_at((0, 0)), config.FLAGS) self.state = UFO.STATES.IDLE
import pygame.mixer import pygame.rect import core.color as color import core.config as config import balloflight import gameobject import ingame FRAMES = [pygame.Rect( 0, 32, 32, 32), pygame.Rect(32, 32, 32, 32)] START_POS = (32, 32) SAFE_SPOT = (0, config.screen.get_height()*3) enemy_frames = dict([(id(c), color.blend_color(config.SPRITES.subsurface(FRAMES[0]).copy(), c)) for c in color.LIST]) ''' Algorithm for storing one colored Enemy per color (with all animations) 1. Create as many copies of the Enemy frames (that is, properly animated) as there are colors for the desired difficulty 2: Paint them their respective colors 3: Store them in a dict({pygame.Color : pygame.Surface}) 4: When an enemy's color is assigned, simply have it draw its Surface from the dict ''' hurt = pygame.mixer.Sound("./sfx/enemyhurt.wav") class Enemy(gameobject.GameObject): STATES = config.Enum('IDLE', 'APPEARING', 'LOWERING', 'ACTIVE', 'DYING', 'SHOOTING', 'CHEERING') acceleration = [0.0, 0.0]