From 392f97be4fc94295385b14a98d03117398fba59c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 29 Apr 2015 09:48:26 +0100 Subject: [PATCH] stupid indenting, updated logic, and upped FPS --- game.py | 66 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/game.py b/game.py index 24bfb11..f16ec67 100644 --- a/game.py +++ b/game.py @@ -9,7 +9,7 @@ from target import Target PLAYING_GAME = False WINDOW_SIZE = (640,480) -FPS = 60 +FPS = 120 def rounding(x, base): return int(base * round(float(x)/base)) @@ -18,11 +18,9 @@ def initialise(menu, options): pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() window = pygame.display.set_mode(WINDOW_SIZE) - window_rect = window.get_rect() - exit_code = play(window) # Run main game loop - + if exit_code = pygame.quit() # Reshow the main menu @@ -41,10 +39,13 @@ def generate_targets(): def play(window): - player = Shooter() - player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.9) + window_rect = window.get_rect() + + player = Shooter(window=window) + player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.93) player_group = pygame.sprite.Group() player_group.add(player) + player_group.draw(window) target_group = generate_targets() bullet_group = pygame.sprite.Group() @@ -54,8 +55,7 @@ def play(window): while PLAYING_GAME: window.fill((0,0,0)) - target_group.update() - bullet_group.update() + player_group.update() for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -67,36 +67,36 @@ def play(window): temp = Bullet(player) bullet_group.add(temp) - keys = pygame.key.get_pressed() - if keys[pygame.K_RIGHT]: - player.move(player.speed) + keys = pygame.key.get_pressed() + if keys[pygame.K_RIGHT] or keys[pygame.K_d]: + player.move(player.speed) - if keys[pygame.K_LEFT]: - player.move(-player.speed) + if keys[pygame.K_LEFT] or keys[pygame.K_a]: + player.move(-player.speed) - if keys[pygame.K_s]: - temp = Bullet(player) - bullet_group.add(temp) + if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6]: + temp = Bullet(player) + bullet_group.add(temp) - for sprite in bullet_group: - if not sprite.at_goal(): - sprite.to_goal() - if sprite.rect.y < 0: - bullet_group.remove(sprite) + for sprite in bullet_group: + if not sprite.at_top(): + sprite.update() + if sprite.rect.y < 0: + bullet_group.remove(sprite) - for bullet in bullet_group: - hit_list = pygame.sprite.spritecollide(bullet, target_group, True) - for target in hit_list: - target_group.remove(target) - bullet_group.remove(bullet) - logging.info("Hit Target!") + for bullet in bullet_group: + hit_list = pygame.sprite.spritecollide(bullet, target_group, True) + for target in hit_list: + target_group.remove(target) + bullet_group.remove(bullet) + logging.info("Hit Target!") - - bullet_group.draw(window) - target_group.draw(window) - player_group.draw(window) - pygame.display.update() - clock.tick(FPS) + player_group.update() + bullet_group.draw(window) + target_group.draw(window) + player_group.draw(window) + pygame.display.update() + clock.tick(FPS) if __name__ == "__main__":