def draw(self): # Draw components (order is important) self.mainmap.draw() for effect in self.effects: effect.update() for monster in self.monsters: monster.update() game.player.draw()
def update(self, dt): for m in self.monsters: m.new_objects = [] m.loot = [] if m.dead: self.world.cases[m.pos_x][m.pos_y].detach(m) self.monsters = [m for m in self.monsters if not m.dead and not m.loot] for monster in self.monsters: monster.update(dt, self.world)
def execute(self): # Process pending events for event in pygame.event.get(): if hasattr(event, 'key') and event.type == pygame.KEYDOWN: # One time operations if event.key == pygame.K_SPACE: game.player.jump() elif event.key == pygame.K_ESCAPE: game.run = 0 elif event.key == pygame.K_r: # reload map self.mainmap = tilemap.NewMap("level1.txt") elif hasattr(event, 'button') and event.type == pygame.MOUSEBUTTONDOWN: # Mouse buttons (left = 1, right = 3, wheel up = 4, wheel down = 5) if event.button == 1: game.player.attack(mob.ATTACK_PRIMARY) elif event.button == 3: game.player.attack(mob.ATTACK_SECONDARY) elif event.type == pygame.QUIT: game.run = 0 # Process move keys (only one can work) keys = pygame.key.get_pressed() if keys[pygame.K_RIGHT] or keys[pygame.K_d]: game.player.move(mob.MOVE_RIGHT) elif keys[pygame.K_LEFT] or keys[pygame.K_a]: game.player.move(mob.MOVE_LEFT) elif keys[pygame.K_UP] or keys[pygame.K_w]: game.player.move(mob.MOVE_UP) elif keys[pygame.K_DOWN] or keys[pygame.K_s]: game.player.move(mob.MOVE_DOWN) # Process attack keys (only one can work) if keys[pygame.K_1]: game.player.attack(mob.ATTACK_PRIMARY) if keys[pygame.K_2]: game.player.attack(mob.ATTACK_SECONDARY) if keys[pygame.K_3]: game.player.attack(mob.ATTACK_AUX1) if keys[pygame.K_4]: game.player.attack(mob.ATTACK_AUX2) # Update components (order is important) game.player.update() for effect in self.effects: effect.update() for monster in self.monsters: monster.update() self.mainmap.update() # Return new scene (if required) return None
def update(self, **kwargs): time = kwargs['time'] self.player.update(**kwargs) if not self.end: self.player.active() if not self.check_end(): for monster in self.monsters: if monster.dead: continue monster.update(**kwargs) monster.active() if self.check_end(): break for child in self.child: child.update(**kwargs)