Return to repo list

gatemender

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

commit c999209f4cf5135ce87022717ef6ea65480f49db
parent 1c46eef2ecbae41cf78ad3b176870983511d95b3
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 10:33:23 -0600

Functional repairs

Diffstat:
Msrc/game.py | 6+++++-
Msrc/sprites.py | 26++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/game.py b/src/game.py @@ -25,6 +25,7 @@ class Game(object): self.asteroids = pygame.sprite.Group() self.bullets = pygame.sprite.Group() self.pickups = pygame.sprite.Group() + self.gate_pieces = pygame.sprite.Group() # Others self.level_factor = 1 @@ -45,6 +46,7 @@ class Game(object): self.asteroids = pygame.sprite.Group() self.bullets = pygame.sprite.Group() self.pickups = pygame.sprite.Group() + self.gate_pieces = pygame.sprite.Group() self.ship = None self.tray = None self.alpha_icon = None @@ -97,7 +99,9 @@ class Game(object): else: im = self.images["Gate_Straight_" + bstr] or_name = "Straight" - self.camera_draw_group.add(sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], n[1])) + gp = sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], n[1]) + self.gate_pieces.add(gp) + self.camera_draw_group.add(gp) x += 1 self.ship = sprites.Ship(self, self.images["Ship"], self.screen.get_rect().center) diff --git a/src/sprites.py b/src/sprites.py @@ -121,7 +121,16 @@ class Ship(CustomSprite): # Fixing if self.fixing: self.aura.visible = True + for g in self.manager.gate_pieces.sprites(): + if self.rect.colliderect(g.rect) and g.broken and self.materials[g.requirement] > 0: + self.fix_counter += 1 + if self.fix_counter > 100: + g.be_fixed() + self.fix_counter = 0 + self.materials[g.requirement] -= 1 + break else: + self.fix_counter = 0 self.aura.visible = False # Check for wrapping @@ -196,6 +205,7 @@ class GatePiece(CustomSprite): super().__init__(manager, image, pos, angle) self.broken = broken self.requirement = req + self.or_name = or_name self.needed = 0 self.needed_text = None self.needed_text_rect = None @@ -220,6 +230,22 @@ class GatePiece(CustomSprite): elif angle == 270: self.needed_text_rect.center = (self.needed_text_rect.centerx + 28, self.needed_text_rect.centery) + def be_fixed(self): + self.needed -= 1 + if self.needed > 0: + rc = self.needed_text_rect.center + self.needed_text = self.manager.font.render(str(self.needed), False, (255, 255, 255)) + self.needed_text_rect = self.needed_text.get_rect() + self.needed_text_rect.center = rc + else: + self.broken = False + self.halo_image = None + self.halo_rect = None + self.image = self.manager.images["Gate_" + self.or_name + "_Fixed"] + self.base_image = self.image + self.image.set_colorkey((255, 0, 255)) + self.rotate(self.angle) + def update(self, surface = None): if self.halo_image != None: surface.blit(self.halo_image, self.halo_rect)