Return to repo list

gatemender

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

commit 16fca828239d760b110ce183e673536e9efa67bb
parent 987ad56de5032c9c94d928755c30eac29651a2c6
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun,  6 Dec 2020 22:32:11 -0600

Further improvements to gate

Diffstat:
Mdata/alpha_halo_straight.png | 0
Mdata/beta_halo_straight.png | 0
Mdata/gamma_halo_straight.png | 0
Mdata/white_halo_straight.png | 0
Msrc/game.py | 13+++++++++++--
Msrc/sprites.py | 19++++++++++++++++---
6 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/data/alpha_halo_straight.png b/data/alpha_halo_straight.png Binary files differ. diff --git a/data/beta_halo_straight.png b/data/beta_halo_straight.png Binary files differ. diff --git a/data/gamma_halo_straight.png b/data/gamma_halo_straight.png Binary files differ. diff --git a/data/white_halo_straight.png b/data/white_halo_straight.png Binary files differ. diff --git a/src/game.py b/src/game.py @@ -24,11 +24,20 @@ class Game(object): # Others self.level_factor = 1 self.asteroid_spawn_timer = 100 + self.gate_defs = [ + [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (416, 100) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (480, 100) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 100) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 164) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (544, 228) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (480, 228) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 228) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 164) ], + ] 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: @@ -61,7 +70,7 @@ class Game(object): else: im = self.images["Gate_Straight_" + bstr] or_name = "Straight" - self.drawables.add(sprites.GatePiece(self, im, (16 * x, 16 * x), n[2], or_name, n[0], rqstr)) + self.drawables.add(sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], rqstr)) x += 1 def shift_frames(self): diff --git a/src/sprites.py b/src/sprites.py @@ -102,8 +102,15 @@ class Ship(CustomSprite): # Bullet class class Bullet(CustomSprite): + def check_collision(self): + for s in self.manager.asteroids.sprites(): + if self.rect.colliderect(s.rect): + s.be_damaged() + self.kill() + def act(self): self.direction_move(BULLET_SPEED) + self.check_collision() if not self.rect.colliderect(self.manager.screen_rect): self.kill() @@ -133,18 +140,24 @@ class Asteroid(CustomSprite): def __init__(self, manager, image, pos, angle = 0, size = 0): super().__init__(manager, image, pos, angle) self.size = size # 0 = small; 1 = medium; 2 = large + self.hp = size + 1 self.spin_speed = random.randint(-7, 7) self.speed = random.randint(1, manager.level_factor + 1) self.entered_screen = False self.contents = random.randint(0, 9) + def be_damaged(self): + self.hp -= 1 + if self.hp <= 0: + self.destroy() + def destroy(self): x = -1 y = -1 for p in range(0, 4): - self.manager.drawables.add(AsteroidParticle(self, self.manager.images["Asteroid_Particle"], self.rect.center, 0, (x, y))) + self.manager.drawables.add(AsteroidParticle(self.manager, self.manager.images["Asteroid_Particle"], self.rect.center, 0, (x, y))) y += 1 - if y % 0 != 0: + if y % 2 != 0: x += 2 self.kill() @@ -161,7 +174,7 @@ class AsteroidParticle(CustomSprite): def __init__(self, manager, image, pos, angle = 0, offset = (1, 1)): super().__init__(manager, image, pos, angle) self.spin_speed = random.randint(-7, 7) - self.offset = (offset[0] * 4, offset[1] * 4) + self.offset = (offset[0] * random.randint(1, 4), offset[1] * random.randint(1, 4)) def act(self): self.offset_move(self.offset)