Return to repo list

gatemender

Arcade game about fixing warp gates. LibreJam Dec 2020 Entry.
Return to HMagellan.com

commit b093800183eb7195f6c35650f75ad3e525a72ab9
parent d89b7ad48fc46c626cf0624911c25cfda090fc2b
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 12:34:46 -0600

added main menu

Diffstat:
Msrc/game.py | 31++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/game.py b/src/game.py @@ -38,8 +38,16 @@ class Game(object): self.game_over_text = self.font.render("GAME OVER", False, (255, 255, 255)) self.lives_text = self.font.render(str(self.lives), False, (255, 255, 255)) self.level_text = self.font.render("GATE " + str(self.level_factor), False, (255, 255, 255)) - - self.change_mode(MODES.Play) + self.start_button = self.font.render("START", False, (255, 255, 255), (20, 20, 20)) + self.start_button_rect = self.start_button.get_rect() + self.start_button_rect.center = (self.screen_rect.centerx, self.screen_rect.centery + 10) + self.instructions_button = self.font.render("INSTRUCTIONS", False, (255, 255, 255), (20, 20, 20)) + self.instructions_button_rect = self.instructions_button.get_rect() + self.instructions_button_rect.center = (self.screen_rect.centerx, self.screen_rect.centery + 50) + self.options_button = self.font.render("OPTIONS", False, (255, 255, 255), (20, 20, 20)) + self.options_button_rect = self.options_button.get_rect() + self.options_button_rect.center = (self.screen_rect.centerx, self.screen_rect.centery + 90) + self.change_mode(MODES.Menu) def clear_level(self): self.screen_draw_group = pygame.sprite.Group() @@ -138,6 +146,10 @@ class Game(object): self.transition_timer = self.transition_timer_max elif mode == MODES.GameOver: self.transition_timer = self.transition_timer_max + elif mode == MODES.Menu: + self.lives = 2 + self.score = 0 + self.level_factor = 1 def render_hud(self): if self.mode == MODES.Play: @@ -209,6 +221,11 @@ class Game(object): self.ship.thrusting = self.keys[THRUST_KEY] self.ship.fixing = self.keys[REPAIR_KEY] self.ship.bursting = self.keys[BURST_KEY] + elif self.mode == MODES.Menu: + if pygame.mouse.get_pressed()[0]: + mousepos = pygame.mouse.get_pos() + if self.start_button_rect.collidepoint(mousepos): + self.change_mode(MODES.Play) def update_screen(self): if self.mode == MODES.Play: @@ -230,6 +247,11 @@ class Game(object): self.screen.blit(self.burst_meter_fill, self.burst_meter_fill_rect) self.screen.blit(self.burst_heading, self.burst_heading_rect) self.screen.blit(self.score_surface, self.score_surface_rect) + elif self.mode == MODES.Menu: + self.screen.fill((0, 0, 0)) + self.screen.blit(self.start_button, self.start_button_rect) + self.screen.blit(self.instructions_button, self.instructions_button_rect) + self.screen.blit(self.options_button, self.options_button_rect) elif self.mode == MODES.Transition: self.screen.fill((0, 0, 0)) self.screen.blit(self.lives_text, (100, 100)) @@ -243,7 +265,7 @@ class Game(object): if self.mode == MODES.Play: self.spawn_asteroids() self.check_gate_complete() - if self.mode == MODES.Transition: + elif self.mode == MODES.Transition: if self.transition_timer > 0: self.transition_timer -= 1 else: @@ -252,8 +274,7 @@ class Game(object): if self.transition_timer > 0: self.transition_timer -= 1 else: - #self.change_mode(MODES.Play) - self.on = False + self.change_mode(MODES.Menu) def spawn_asteroids(self): if self.asteroid_spawn_timer <= 0: