Return to repo list

gatemender

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

commit 987ad56de5032c9c94d928755c30eac29651a2c6
parent 6b7cb94403b4c17d4d4d817bc0517d6563c954de
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun,  6 Dec 2020 21:30:11 -0600

More work on gate pieces and their halos

Diffstat:
Mdata/alpha_halo_straight.png | 0
Mdata/beta_halo_straight.png | 0
Mdata/gamma_halo_straight.png | 0
Adata/white_halo_angle.png | 0
Adata/white_halo_straight.png | 0
Msrc/constants.py | 8++++++++
Msrc/game.py | 12++++++++++--
Msrc/sprites.py | 40++++++++++++++++++++++++++++++++++++++--
8 files changed, 56 insertions(+), 4 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_angle.png b/data/white_halo_angle.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/constants.py b/src/constants.py @@ -18,6 +18,14 @@ IMAGE_FILES = { "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_Halo_Straight" : os.path.join("data", "alpha_halo_straight.png"), + "Alpha_Halo_Angle" : os.path.join("data", "alpha_halo_angle.png"), + "Beta_Halo_Straight" : os.path.join("data", "beta_halo_straight.png"), + "Beta_Halo_Angle" : os.path.join("data", "beta_halo_angle.png"), + "Gamma_Halo_Straight" : os.path.join("data", "gamma_halo_straight.png"), + "Gamma_Halo_Angle" : os.path.join("data", "gamma_halo_angle.png"), + "White_Halo_Straight" : os.path.join("data", "white_halo_straight.png"), + "White_Halo_Angle" : os.path.join("data", "white_halo_angle.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") diff --git a/src/game.py b/src/game.py @@ -40,20 +40,28 @@ class Game(object): while bc < broke: ind = random.randint(0, 7) if self.gate_defs[ind][0]: - self.gates_def[ind][0] = False + self.gate_defs[ind][0] = False bc += 1 x = 0 for n in self.gate_defs: + if n[1] == 0: + rqstr = "Alpha" + elif n[1] == 1: + rqstr = "Beta" + else: + rqstr = "Gamma" if n[0]: 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] - self.drawables.add(sprites.GatePiece(self, im, (16 * x, 16 * x), n[2], n[1])) + or_name = "Straight" + self.drawables.add(sprites.GatePiece(self, im, (16 * x, 16 * x), n[2], or_name, n[0], rqstr)) x += 1 def shift_frames(self): diff --git a/src/sprites.py b/src/sprites.py @@ -99,6 +99,7 @@ class Ship(CustomSprite): else: self.shoot_cooldown -= 1 +# Bullet class class Bullet(CustomSprite): def act(self): @@ -109,11 +110,22 @@ class Bullet(CustomSprite): # Gate components class GatePiece(CustomSprite): - def __init__(self, manager, image, pos, angle = 0, req = None): + def __init__(self, manager, image, pos, angle = 0, or_name = "Straight", broken = False, req = None): super().__init__(manager, image, pos, angle) + self.broken = broken self.requirement = req self.needed = 0 - self.halo = None + if self.broken: + self.halo_image = pygame.transform.rotate(self.manager.images[self.requirement + "_Halo_" + or_name], self.angle) + else: + self.halo_image = pygame.transform.rotate(self.manager.images["White_Halo_" + or_name], self.angle) + self.halo_image.set_colorkey(COLORKEY) + self.halo_rect = self.halo_image.get_rect() + self.halo_rect.center = self.rect.center + + def update(self, surface = None): + surface.blit(self.halo_image, self.halo_rect) + super().update(surface) # Asteroids class Asteroid(CustomSprite): @@ -124,6 +136,17 @@ class Asteroid(CustomSprite): 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 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))) + y += 1 + if y % 0 != 0: + x += 2 + self.kill() def act(self): self.offset_move((0, self.speed)) @@ -132,3 +155,16 @@ class Asteroid(CustomSprite): self.entered_screen = True elif self.entered_screen == True: self.kill() + +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) + + def act(self): + self.offset_move(self.offset) + self.rotate(self.angle + self.spin_speed) + if not self.rect.colliderect(self.manager.screen_rect): + self.kill()