Return to repo list

gatemender

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

commit 491aa5468fe466fef45336763d3d83dcd5d2b530
parent 6cdb2c88fb5612b428f1ccb2dbefa2e5cc69bd57
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon, 14 Dec 2020 17:02:17 -0600

Gate puzzle now preserved between deaths

Diffstat:
Msrc/game.py | 64+++++++++++++++++++++++++++++++++-------------------------------
Msrc/sprites.py | 1+
2 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/src/game.py b/src/game.py @@ -16,6 +16,7 @@ class Game(object): self.mode = MODES.Play self.show_info = False self.just_pressed = False + self.preserve_gate = False # Loading self.images = { i : pygame.image.load(IMAGE_FILES[i]).convert() for i in IMAGE_FILES } @@ -59,7 +60,6 @@ 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.vortex = None self.tray = None @@ -84,31 +84,39 @@ class Game(object): # First, restore to default self.clear_level() - self.gate_defs = [ - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 0, (416, 200) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 0, (480, 200) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 270, (544, 200) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 270, (544, 264) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 180, (544, 328) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 180, (480, 328) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 90, (416, 328) ], - [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 90, (416, 264) ], - ] + if not self.preserve_gate: + + # Definitions + self.gate_defs = [ + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 0, (416, 200), "Angle" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 0, (480, 200), "Straight" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 270, (544, 200), "Angle" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 270, (544, 264), "Straight" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 180, (544, 328), "Angle" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 180, (480, 328), "Straight" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 90, (416, 328), "Angle" ], + [ bool(random.getrandbits(1)), MATERIALS(random.randint(1, 3)), 90, (416, 264), "Straight" ], + ] + self.gate_pieces = pygame.sprite.Group() - # Next, load level - broke = min(self.level_factor + 1, 5) - bc = 0 - for i in self.gate_defs: - if i[0]: - if bc < broke: + # Next, load level + broke = min(self.level_factor + 1, 5) + bc = 0 + for i in self.gate_defs: + if i[0]: + if bc < broke: + bc += 1 + else: + i[0] = False + while bc < broke: + ind = random.randint(0, 7) + if not self.gate_defs[ind][0]: + self.gate_defs[ind][0] = True bc += 1 - else: - i[0] = False - while bc < broke: - ind = random.randint(0, 7) - if not self.gate_defs[ind][0]: - self.gate_defs[ind][0] = True - bc += 1 + else: + self.preserve_gate = False + self.gate_defs = [ [ g.broken, g.requirement, g.angle, g.rect.center, g.or_name] for g in self.gate_pieces ] + self.gate_pieces = pygame.sprite.Group() x = 0 for n in self.gate_defs: @@ -116,13 +124,7 @@ class Game(object): bstr = "Fixed" else: bstr = "Broken" - if x % 2 == 0: - im = self.images["Gate_Angle_" + bstr] - or_name = "Angle" - else: - im = self.images["Gate_Straight_" + bstr] - or_name = "Straight" - gp = sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], n[1]) + gp = sprites.GatePiece(self, self.images["Gate_" + n[4] + "_" + bstr], n[3], n[2], n[4], n[0], n[1]) self.gate_pieces.add(gp) self.camera_draw_group.add(gp) x += 1 diff --git a/src/sprites.py b/src/sprites.py @@ -193,6 +193,7 @@ class Ship(CustomSprite): # If dead else: self.visible = False + self.manager.preserve_gate = True if self.be_dead_timer > 0: self.be_dead_timer -= 1 else: