Return to repo list

gatemender

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

commit 1c46eef2ecbae41cf78ad3b176870983511d95b3
parent c14883393203c6a375beaa23a0c5af558dc3046c
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 10:15:50 -0600

spawn pickups and display in hud

Diffstat:
Adata/alpha_material_big.png | 0
Adata/beta_material_big.png | 0
Adata/gamma_material_big.png | 0
Msrc/constants.py | 3+++
Msrc/game.py | 30++++++++++++++++++++++++++++++
Msrc/sprites.py | 17+++++++++++++++++
6 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/data/alpha_material_big.png b/data/alpha_material_big.png Binary files differ. diff --git a/data/beta_material_big.png b/data/beta_material_big.png Binary files differ. diff --git a/data/gamma_material_big.png b/data/gamma_material_big.png Binary files differ. diff --git a/src/constants.py b/src/constants.py @@ -29,6 +29,9 @@ IMAGE_FILES = { "Alpha_Icon" : os.path.join("data", "alpha_material.png"), "Beta_Icon" : os.path.join("data", "beta_material.png"), "Gamma_Icon" : os.path.join("data", "gamma_material.png"), + "Big_Alpha_Icon" : os.path.join("data", "alpha_material_big.png"), + "Big_Beta_Icon" : os.path.join("data", "beta_material_big.png"), + "Big_Gamma_Icon" : os.path.join("data", "gamma_material_big.png"), "UI_Tray" : os.path.join("data", "hud_tray.png"), "Fix_Aura" : os.path.join("data", "fix_aura.png"), "Vortex" : os.path.join("data", "vortex.png") diff --git a/src/game.py b/src/game.py @@ -24,6 +24,7 @@ class Game(object): self.camera_draw_group = pygame.sprite.Group() self.asteroids = pygame.sprite.Group() self.bullets = pygame.sprite.Group() + self.pickups = pygame.sprite.Group() # Others self.level_factor = 1 @@ -43,7 +44,15 @@ class Game(object): self.camera_draw_group = pygame.sprite.Group() self.asteroids = pygame.sprite.Group() self.bullets = pygame.sprite.Group() + self.pickups = pygame.sprite.Group() self.ship = None + self.tray = None + self.alpha_icon = None + self.beta_icon = None + self.gamma_icon = None + self.num_alpha = None + self.num_beta = None + self.num_gamma = None self.asteroid_spawn_timer = 100 def load_level(self): @@ -96,6 +105,11 @@ class Game(object): self.tray = sprites.CustomSprite(self, self.images["UI_Tray"], (self.screen_rect.centerx, 700)) self.screen_draw_group.add(self.tray) + 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) + def change_mode(self, mode): self.mode = mode if mode == MODES.Play: @@ -107,6 +121,18 @@ class Game(object): elif mode == MODES.GameOver: self.transition_timer = self.transition_timer_max + def render_hud(self): + if self.mode == MODES.Play: + self.num_alpha = self.font.render(str(self.ship.materials[MATERIALS.Alpha]), False, (255, 255, 255)) + self.num_alpha_rect = self.num_alpha.get_rect() + self.num_alpha_rect.center = (440, 710) + self.num_beta = self.font.render(str(self.ship.materials[MATERIALS.Beta]), False, (255, 255, 255)) + self.num_beta_rect = self.num_beta.get_rect() + self.num_beta_rect.center = (520, 710) + 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) + def shift_frames(self): self.frameclock.tick(FRAMERATE) @@ -138,8 +164,12 @@ class Game(object): self.camera_surface.fill((0, 0, 0)) self.camera_surface.blit(self.images["Space_Background"], (0, 0)) self.camera_draw_group.update(self.camera_surface) + self.render_hud() self.screen.blit(self.camera_surface, self.camera_surface_rect) self.screen_draw_group.update(self.screen) + 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) elif self.mode == MODES.Transition: self.screen.fill((0, 0, 0)) self.screen.blit(self.lives_text, (100, 100)) diff --git a/src/sprites.py b/src/sprites.py @@ -242,7 +242,22 @@ class Asteroid(CustomSprite): def be_damaged(self): self.hp -= 1 if self.hp <= 0: + self.spawn_pickup() self.destroy() + + def spawn_pickup(self): + if self.contents == 0: + p = Pickup(self.manager, self.manager.images["Alpha_Icon"], self.rect.center, 0, MATERIALS.Alpha) + self.manager.pickups.add(p) + self.manager.camera_draw_group.add(p) + elif self.contents == 1: + p = Pickup(self.manager, self.manager.images["Beta_Icon"], self.rect.center, 0, MATERIALS.Beta) + self.manager.pickups.add(p) + self.manager.camera_draw_group.add(p) + elif self.contents == 2: + p = Pickup(self.manager, self.manager.images["Gamma_Icon"], self.rect.center, 0, MATERIALS.Gamma) + self.manager.pickups.add(p) + self.manager.camera_draw_group.add(p) def destroy(self): x = -1 @@ -292,6 +307,8 @@ class Pickup(CustomSprite): self.material = material def act(self): + self.rotate(self.angle + 1) if self.rect.colliderect(self.manager.ship.rect): self.manager.ship.materials[self.material] += 1 self.kill() +