Return to repo list

gatemender

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

commit 30617441378ea023e57ff5bf4b8c3078c9c16867
parent c73bfac2e26b72c8ce0190882a26f2f41e9f73f9
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun,  6 Dec 2020 18:39:43 -0600

Gate pieces now semi-functional

Diffstat:
Msrc/constants.py | 9++++++++-
Msrc/game.py | 31+++++++++++++++++++++++++++++++
Msrc/sprites.py | 4++--
3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/constants.py b/src/constants.py @@ -13,7 +13,14 @@ IMAGE_FILES = { "Medium_Asteroid" : os.path.join("data", "asteroid_medium.png"), "Big_Asteroid" : os.path.join("data", "asteroid_big.png"), "Asteroid_Particle" : os.path.join("data", "asteroid_particle.png"), - "Space_Background" : os.path.join("data", "space_background.png") + "Space_Background" : os.path.join("data", "space_background.png"), + "Gate_Angle_Fixed" : os.path.join("data", "gate_angle_fixed.png"), + "Gate_Angle_Broken" : os.path.join("data", "gate_angle_broken.png"), + "Gate_Straight_Fixed" : os.path.join("data", "gate_straight_fixed.png"), + "Gate_Straight_Broken" : os.path.join("data", "gate_straight_broken.png"), + "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") } TURN_LEFT_KEY = pygame.K_a TURN_RIGHT_KEY = pygame.K_d diff --git a/src/game.py b/src/game.py @@ -23,6 +23,37 @@ class Game(object): self.level_factor = 1 self.asteroid_spawn_timer = 100 + self.load_level() + + def load_level(self): + self.gate_defs = [ [bool(random.getrandbits(1)), random.randint(0, 2), 90 * int(round(j - (j % 2)) / 2)] for j in range(0, 8) ] + broke = min(self.level_factor + 2, 5) + bc = 0 + for i in self.gate_defs: + if not i[0]: + if bc >= broke: + i[0] = True + else: + bc += 1 + while bc < broke: + ind = random.randint(0, 7) + if self.gate_defs[ind][0]: + self.gates_def[ind][0] = False + bc += 1 + + x = 0 + for n in self.gate_defs: + if n[0]: + bstr = "Fixed" + else: + bstr = "Broken" + if x % 2 == 0: + im = self.images["Gate_Angle_" + bstr] + else: + im = self.images["Gate_Straight_" + bstr] + self.drawables.add(sprites.GatePiece(self, im, (16 * x, 16 * x), n[2], n[1])) + x += 1 + def shift_frames(self): self.frameclock.tick(FRAMERATE) diff --git a/src/sprites.py b/src/sprites.py @@ -107,9 +107,9 @@ class Bullet(CustomSprite): # Gate components class GatePiece(CustomSprite): - def __init__(self, manager, image, pos, angle = 0): + def __init__(self, manager, image, pos, angle = 0, req = None): super().__init__(manager, image, pos, angle) - self.requirement = None + self.requirement = req self.needed = 0 self.halo = None