def wave_loading(self, param1): log.info("Starting Wave {} Loading ...".format(param1)) self.clear_all_objects() banner = Banner("Wave {} Loading ...".format(param1), GameBase.get_font_normal(), color=invaderutils.COLOR_WHITE, pos=(250,325)) GameObjectKeeper.setup(banner, 1000)
def setup_loser_screen(self, parm1): self.clear_all_objects() bye = AnimatedSprite(200, 320, ["images/game/gameover.png"]) GameObjectKeeper.setupenemy(bye, 1000) self.set_game_mode(invaderutils.GAME_END_EVENT)
def run(self): self.set_game_mode(invaderutils.GAME_STARTED_EVENT) try: while True: self.senario_change() self.remove_terminated() events = pygame.event.get() pressed = pygame.key.get_pressed() for event in events: self.process_events(event) for go in GameObjectKeeper.runables(): for event in events: go.process_events(event) go.process_keys(pressed) self.collision_detection() for go in GameObjectKeeper.runables(): go.draw(Background.get_screen()) # Flip the drawing buffers pygame.display.flip() GameMachine.clock.tick(120) except QuitProgram as e_info: pass
def wave_winner(self, parm1): log.info("WINNER") self.clear_all_objects() banner = Banner("Winner!", GameBase.get_font_normal(), color=invaderutils.COLOR_WHITE, pos=(250,325)) GameObjectKeeper.setup(banner, 1000) self.set_game_mode(invaderutils.GAME_END_EVENT)
def wave_4(self, param): log.info("Starting Wave 4") self._wave_basics() # Setup bad guys for x in range( 0, 720, 75): enemy = enemy_smiling_vader(x,70,movex=-3) GameObjectKeeper.setupenemy(enemy, 50) self.set_game_mode(invaderutils.MODE_FIGHT_4_EVENT)
def fire_missile(self): self.mis_steps = 0 newx = int(self.x + self.get_width()/2) newy = self.y missile = AutoMovingAnimatedSprite( newx, newy, invaderutils.missile_png(), movex=0, movey=-4, msteps=1) GameObjectKeeper.setupfriendly(missile, 45)
def fire_bomb(self): newx = int(self.x + self.get_width() / 2 - 10) newy = self.y + self.get_height() self.mis_steps = 0 bomb = AutoMovingAnimatedSprite(newx, newy, invaderutils.bomb_png(), movex=0, movey=4, msteps=1) GameObjectKeeper.setupenemy(bomb, 45)
def wave_2(self, param): log.info("Starting Wave 2") self._wave_basics() # Setup bad guys for x in range( 0, 750, 75): enemy = enemy_fonzy(x, 70, movex=-2) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_fonzy(x, 120, movex=-2) GameObjectKeeper.setupenemy(enemy, 50) self.set_game_mode(invaderutils.MODE_FIGHT_2_EVENT)
def wave_3(self, param): log.info("Starting Wave 3") self._wave_basics() # Setup bad guys for x in range( 0, 400, 100): enemy = enemy_the_frig(x,70,movex=1) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_the_frig(x + 300, 140, movex=-1) GameObjectKeeper.setupenemy(enemy, 50) self.set_game_mode(invaderutils.MODE_FIGHT_3_EVENT)
def collision_detection(self): curr_state = self.get_game_mode() # Check to see if we are in FIGHT MODE if not ((curr_state > invaderutils.MODE_FIGHT_A_EVENT) and (curr_state < invaderutils.MODE_FIGHT_Z_EVENT)): return enemies = GameObjectKeeper.enemies() if len(enemies) == 0: self.set_game_mode(invaderutils.GAME_ENEMIES_DEAD_EVENT) return for enemy in enemies: for friend in GameObjectKeeper.friendlies(): if enemy.collide(friend): self.collide_action(friend, enemy) self.check_friend_hero(friend)
def collide_action(self, friend, enemy): """ TODO: really don't like this routine here. """ log.debug("COLLIDED: {0} {1}".format(type(friend),type(enemy))) Thump() friend.terminate() enemy.terminate() explosion = AutoMovingAnimatedSprite(enemy.x, enemy.y,invaderutils.explosion_png(), movex=0, movey=-1, msteps=1) if (isinstance(friend, Hero)): explosion = AutoMovingAnimatedSprite(friend.x, friend.y, invaderutils.hero_explosion_png(), movex=0, movey=-1, msteps=1) elif (not isinstance(enemy, Enemy)): explosion = AutoMovingAnimatedSprite(enemy.x, enemy.y, invaderutils.missile_explosion_png(), movex=0, movey=-1, msteps=1) GameObjectKeeper.setup(explosion, 35) # add to score if (not isinstance(friend, Hero)): myscoreboard = GameObjectKeeper.get_by_name("myscoreboard") myscoreboard.addscore(enemy.get_bonus()) self.highscorestore.set_highscore(myscoreboard.getscore())
def wave_1(self, param): log.info("Starting Wave 1") self._wave_basics() # Setup bad guys for x in range( 0, 400, 150): enemy = enemy_little_john(x, 50) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_little_john(x+125, 150) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_little_john(x, 250) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_little_john(x+125, 350) GameObjectKeeper.setupenemy(enemy, 50) self.set_game_mode(invaderutils.MODE_FIGHT_1_EVENT)
def __init__(self, width, height): invaderutils.set_game_dimensions(width, height) GameMachine.clock = pygame.time.Clock() GameObjectKeeper.special_setup(Background(), 0)
def clear_all_objects(self): for go in GameObjectKeeper.runables(): GameObjectKeeper.remove(go)
def _wave_basics(self): self.clear_all_objects() # Setup Banners for User banner = Banner("SCORE", GameBase.get_font_normal(), color=invaderutils.COLOR_WHITE, pos=(0, 10)) GameObjectKeeper.setup(banner, 1000) myscoreboard = Score( 0, 35, GameBase.get_font_normal(), invaderutils.COLOR_YELLOW) GameObjectKeeper.setup(myscoreboard, 1000, name = "myscoreboard") banner = Banner("HIGH SCORE", GameBase.get_font_normal(), color=invaderutils.COLOR_WHITE, pos=(300, 10)) GameObjectKeeper.setup(banner, 1000) banner = Banner("{0:010}".format(GameMachine.highscorestore.get_highscore()), GameBase.get_font_normal(), pos=(300, 35), color=invaderutils.COLOR_YELLOW) GameObjectKeeper.setup(banner, 1000) GameMachine.highscorestore.get_highscore() # setup the stars for star in invaderutils.star_field(20): GameObjectKeeper.setupmisc(star, 25) # setup hero GameObjectKeeper.setupfriendly(Hero(100, 710, invaderutils.hero_png(), mis_steps=75, steps=3, move_steps=2), 50)
def wave_5(self, param): log.info("Starting Wave 5") self._wave_basics() # Setup bad guys for x in range( 0, 400, 100): enemy = enemy_the_frig(x,70,movex=1) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_the_frig(x + 300, 140, movex=-1) GameObjectKeeper.setupenemy(enemy, 50) for x in range( 0, 720, 75): enemy = enemy_smiling_vader(x,70,movex=-3) GameObjectKeeper.setupenemy(enemy, 50) for x in range( 0, 750, 75): enemy = enemy_fonzy(x, 70, movex=-2) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_fonzy(x, 120, movex=-2) GameObjectKeeper.setupenemy(enemy, 50) for x in range( 0, 400, 150): enemy = enemy_little_john(x, 50) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_little_john(x+125, 150) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_little_john(x, 250) GameObjectKeeper.setupenemy(enemy, 50) enemy = enemy_little_john(x+125, 350) GameObjectKeeper.setupenemy(enemy, 50) # enemy = Enemy(x, 25, invaderutils.invader_png(4), bombclockpts=(100,250), lowermove=30, movex=-3) # GameObjectKeeper.setupenemy(enemy, 50) # enemy = Enemy(x-55, 100, invaderutils.invader_png(2), bombclockpts=(1500,3000), lowermove=40) # GameObjectKeeper.setupenemy(enemy, 50) # enemy = Enemy(x, 175, invaderutils.invader_png(1), bombclockpts=(1000,2000), lowermove=60,movex=-2) # GameObjectKeeper.setupenemy(enemy, 50) # enemy = Enemy(x+25, 275, invaderutils.invader_png(3), bombclockpts=(1000,4000), lowermove=80) # GameObjectKeeper.setupenemy(enemy, 50) self.set_game_mode(invaderutils.MODE_FIGHT_5_EVENT)
def remove_terminated(self): for go in GameObjectKeeper.runables(): if (go.removeme()): GameObjectKeeper.remove(go) break