Return to repo list

gatemender

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

commit fe93875bf1507de7090fe4339eff806460904170
parent c999209f4cf5135ce87022717ef6ea65480f49db
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 11:38:28 -0600

gameplay and hud in good shape

Diffstat:
Msrc/game.py | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/sprites.py | 16+++++++++++++++-
2 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/src/game.py b/src/game.py @@ -28,8 +28,9 @@ class Game(object): self.gate_pieces = pygame.sprite.Group() # Others + self.score = 0 self.level_factor = 1 - self.lives = 0 + self.lives = 2 self.transition_timer_max = 200 self.transition_timer = self.transition_timer_max self.asteroid_spawn_timer = 100 @@ -48,6 +49,7 @@ class Game(object): self.pickups = pygame.sprite.Group() self.gate_pieces = pygame.sprite.Group() self.ship = None + self.vortex = None self.tray = None self.alpha_icon = None self.beta_icon = None @@ -55,6 +57,14 @@ class Game(object): self.num_alpha = None self.num_beta = None self.num_gamma = None + self.hud_lives_icon = None + self.num_lives = None + self.hp_heading = None + self.burst_heading = None + self.hp_meter = None + self.hp_meter_fill = None + self.burst_meter = None + self.burst_meter_fill = None self.asteroid_spawn_timer = 100 def load_level(self): @@ -73,18 +83,18 @@ class Game(object): ] # Next, load level - broke = min(self.level_factor + 2, 5) + broke = min(self.level_factor + 1, 5) bc = 0 for i in self.gate_defs: - if not i[0]: - if bc >= broke: - i[0] = True - else: + if i[0]: + if bc < broke: bc += 1 + else: + i[0] = False while bc < broke: ind = random.randint(0, 7) if self.gate_defs[ind][0]: - self.gate_defs[ind][0] = False + self.gate_defs[ind][0] = True bc += 1 x = 0 @@ -104,15 +114,18 @@ class Game(object): self.camera_draw_group.add(gp) x += 1 - self.ship = sprites.Ship(self, self.images["Ship"], self.screen.get_rect().center) + self.ship = sprites.Ship(self, self.images["Ship"], self.screen_rect.center) self.camera_draw_group.add(self.ship) self.tray = sprites.CustomSprite(self, self.images["UI_Tray"], (self.screen_rect.centerx, 700)) self.screen_draw_group.add(self.tray) + self.vortex = sprites.Vortex(self, self.images["Vortex"], (480, 264)) + self.camera_draw_group.add(self.vortex) self.alpha_icon = sprites.CustomSprite(self, self.images["Big_Alpha_Icon"], (410, 710)) self.beta_icon = sprites.CustomSprite(self, self.images["Big_Beta_Icon"], (490, 710)) self.gamma_icon = sprites.CustomSprite(self, self.images["Big_Gamma_Icon"], (570, 710)) - self.screen_draw_group.add(self.alpha_icon, self.beta_icon, self.gamma_icon) + self.hud_lives_icon = sprites.CustomSprite(self, self.images["Ship"], (130, 720)) + self.screen_draw_group.add(self.alpha_icon, self.beta_icon, self.gamma_icon, self.hud_lives_icon) def change_mode(self, mode): self.mode = mode @@ -136,6 +149,21 @@ class Game(object): self.num_gamma = self.font.render(str(self.ship.materials[MATERIALS.Gamma]), False, (255, 255, 255)) self.num_gamma_rect = self.num_gamma.get_rect() self.num_gamma_rect.center = (600, 710) + self.num_lives = self.font.render("X " + str(self.lives), False, (255, 255, 255)) + self.num_lives_rect = self.num_lives.get_rect() + self.num_lives_rect.center = (180, 720) + self.hp_heading = self.font.render("HP", False, (255, 255, 255)) + self.hp_heading_rect = self.hp_heading.get_rect() + self.hp_heading_rect.center = (61, 720) + self.hp_meter = pygame.Surface((32, 80)) + self.hp_meter.fill((135, 0, 22)) + self.hp_meter_rect = self.hp_meter.get_rect() + self.hp_meter_fill = pygame.Surface((32, round((self.ship.hp / 3) * 80))) + self.hp_meter_fill.fill((0, 200, 0)) + self.hp_meter_fill_rect = self.hp_meter_fill.get_rect() + self.hp_meter_rect.center = (60, 720) + self.hp_meter_fill_rect.bottom = self.hp_meter_rect.bottom - 1 + self.hp_meter_fill_rect.centerx = self.hp_meter_rect.centerx def shift_frames(self): self.frameclock.tick(FRAMERATE) @@ -174,6 +202,10 @@ class Game(object): self.screen.blit(self.num_alpha, self.num_alpha_rect) self.screen.blit(self.num_beta, self.num_beta_rect) self.screen.blit(self.num_gamma, self.num_gamma_rect) + self.screen.blit(self.num_lives, self.num_lives_rect) + self.screen.blit(self.hp_meter, self.hp_meter_rect) + self.screen.blit(self.hp_meter_fill, self.hp_meter_fill_rect) + self.screen.blit(self.hp_heading, self.hp_heading_rect) elif self.mode == MODES.Transition: self.screen.fill((0, 0, 0)) self.screen.blit(self.lives_text, (100, 100)) @@ -186,6 +218,7 @@ class Game(object): def update_logic(self): if self.mode == MODES.Play: self.spawn_asteroids() + self.check_gate_complete() if self.mode == MODES.Transition: if self.transition_timer > 0: self.transition_timer -= 1 @@ -211,9 +244,22 @@ class Game(object): a = sprites.Asteroid(self, im, spawnpos, 270, size) self.camera_draw_group.add(a) self.asteroids.add(a) - self.asteroid_spawn_timer = 10 * (10 / self.level_factor) + self.asteroid_spawn_timer = 10 * (10 // self.level_factor) else: self.asteroid_spawn_timer -= 1 + + def check_gate_complete(self): + for g in self.gate_pieces.sprites(): + if g.broken: + return + self.vortex.visible = True + self.vortex.passthru = True + + def increment_level(self): + for m in self.ship.materials: + self.score += self.ship.materials[m] * 100 * self.level_factor + self.level_factor += 1 + self.change_mode(MODES.Transition) def run(self): while self.on: diff --git a/src/sprites.py b/src/sprites.py @@ -68,7 +68,7 @@ class Ship(CustomSprite): self.blinking_timer = self.blinking_timer_max self.aura = FixAura(self.manager, self.manager.images["Fix_Aura"], self.rect.center, 0, self) self.manager.camera_draw_group.add(self.aura) - self.materials = { m : 0 for m in MATERIALS } + self.materials = { m : 5 for m in MATERIALS } self.be_dead_timer = 60 def thrust(self): @@ -270,6 +270,7 @@ class Asteroid(CustomSprite): if self.hp <= 0: self.spawn_pickup() self.destroy() + self.manager.score += 10 * self.manager.level_factor def spawn_pickup(self): if self.contents == 0: @@ -338,3 +339,16 @@ class Pickup(CustomSprite): self.manager.ship.materials[self.material] += 1 self.kill() +class Vortex(CustomSprite): + + def __init__(self, manager, image, pos, angle = 0): + super().__init__(manager, image, pos, angle) + self.visible = False + self.passthru = False + self.passrect = pygame.Rect((0, 0), (self.rect.width // 3, self.rect.height // 3)) + self.passrect.center = self.rect.center + + def act(self): + self.rotate(self.angle + 3) + if self.passthru and self.passrect.colliderect(self.manager.ship.rect): + self.manager.increment_level()