def update(self, dTime): MovingSprite.update(self, dTime) if self.target and not self.target.alive(): self.kill() for e in pygame.sprite.spritecollide(self, self.dpTop.enemies, False): e.hurt(self.harm) self.kill() break
def __init__(self, dpTop): if not Gem.image: Gem.image = load_image('gem.png', (32, 32)) self.image = Gem.image self.rect = self.image.get_rect() self.done = False self.dpTop = dpTop self.pickedUp = False self.target = (self.rect.centerx, self.rect.centery - self.RISE_AMOUNT) MovingSprite.__init__(self, self.target, self.SPEED)
def update(self, dTime): MovingSprite.update(self, dTime) if not self.target: if self.waypoints: self.target = self.waypoints[0] del self.waypoints[0] else: self.dpTop.health -= self.harm self.dpTop.healthField.st = "Health: " + str(self.dpTop.health) self.dpTop.healthField.createImage() self.kill()
def __init__(self, dpTop): MovingSprite.__init__(self, None, 200) self.waypoints = dpTop.enemyPath[:] self.image = random.choice(Parasprite.images) self.rect = self.image.get_rect() self.speed = 200 self.health = 10 self.harm = 19 self.dpTop = dpTop self.pos = Vec2d((0, 0))
def __init__(self, target, dpTop): print "Apple created!" MovingSprite.__init__(self, target, 1000) if not Apple.images: Apple.images['idle'] = pygame.image.load(os.path.join('data', 'images', 'apple.png')) Apple.images['idle'].convert_alpha() Apple.images['idle'] = pygame.transform.scale(Apple.images['idle'], (16, 16)) self.image = Apple.images['idle'] self.rect = self.image.get_rect() self.target = target self.pos = Vec2d((0,0)) self.harm = 10 self.dpTop = dpTop
def __init__(self, dpTop): Pony.__init__(self) self.dpTop = dpTop if not Derpy.frames: Derpy.frames = [load_image('derpyFlying-'+str(i)+'.png', (PONY_SIZE, PONY_SIZE)).convert_alpha() for i in xrange(7)] AnimatedSprite.__init__(self, Derpy.frames) self.rect = self.image.get_rect() MovingSprite.__init__(self, None, 200) self.range = 500 self.attacking = False self.cooldown = 4000
def move(self, direction, group): if self.games_group is not None: self.last_game_indexes[self.current] = self.games_group.current ImageGroup.move(self, direction, group) current_emulator = self.backing[self.current] values = (current_emulator.data['id'], ) games = [] for row in self.db.execute( 'select * from Games where emulator == ? order by name', values): games.append(MovingSprite(row, current_emulator.datadir)) game_locations = { 'current': (712 - .5 * games[0]['image_width'], 308), 'before': (425, 50), 'after': (999 - (games[0]['image_width'] / 2), 50) } game_sizes = { 'current': (games[0]['image_width'], 360), 'before': (games[0]['image_width'] / 2, 180), 'after': (games[0]['image_width'] / 2, 180) } self.games_group = ImageGroup(game_locations, game_sizes, self.last_game_indexes[self.current], *games) return self.games_group
def update(self, dTime): AnimatedSprite.update(self, dTime) if not self.ghost: MovingSprite.update(self, dTime) if not self.target or not self.target.alive(): print "finding new target" #find a suitable target ens = self.dpTop.enemiesWithinRange(self.rect.center, self.range) ens.sort(key=lambda x: -x.health) if ens: self.target = ens[0] else: self.target = None self.cooldown -= dTime #check whether we can drop an anvil if pygame.sprite.spritecollideany(self, self.dpTop.enemies) and self.cooldown <= 0: a = Anvil(self.dpTop) a.place(self.rect.center) self.dpTop.sprites.add(a) self.cooldown = 4000
def __init__(self): self.config = FrontendConfig('frontend-pygame') pygame.init() pygame.mixer.init() pygame.key.set_repeat(500, 150) self.screen = pygame.display.set_mode((1024, 768)) self.background = pygame.Surface(self.screen.get_size()) self.game_font = pygame.font.Font(None, 48) self.click = pygame.mixer.Sound('%s/sounds/light2.wav' % self.config['DataDir']) self.clock = pygame.time.Clock() self.db = sqlite3.connect('%s/Arcade.db' % self.config['DataDir']) emu_locations = { 'current': (50, 284), 'before': (100, 50), 'after': (100, 584) } emu_sizes = { 'current': (300, 200), 'before': (201, 134), 'after': (201, 134) } self.background.fill((0, 0, 0)) self.screen.blit(self.background, (0, 0)) self.db.row_factory = sqlite3.Row emus = [] for row in self.db.execute('select * from Emulators order by name'): emus.append(MovingSprite(row, self.config['DataDir'])) self.emulators = EmulatorImageGroup(emu_locations, emu_sizes, self.db, *emus) self.games = self.emulators.move(0, 'games') # Spawn an unclutter process to hide the mouse pointer. if self.config['HidePointer']: self.unclutter_child = os.fork() if self.unclutter_child == 0: while (True): os.system('unclutter') # Set fullscreen. TODO: Test this! Doesn't work on mac, but docs say # it's only valid for X11. if self.config['Fullscreen']: pygame.display.toggle_fullscreen()
def update(self, dTime): MovingSprite.update(self, dTime) if self.pickedUp and not self.target: print "Killed!" self.kill()