Return to repo list

gatemender

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

commit 2fe20f281828514b42c1a296c6727adb3dd43ce5
parent 042bcc6649743727b0d9e7a16fb13eb5d199083f
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 08:39:08 -0600

vortex graphic and enumify material

Diffstat:
Adata/vortex.png | 0
Msrc/constants.py | 6++++--
Msrc/game.py | 24+++++++++---------------
Msrc/sprites.py | 14+++++++++++++-
4 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/data/vortex.png b/data/vortex.png Binary files differ. diff --git a/src/constants.py b/src/constants.py @@ -1,4 +1,4 @@ -import pygame, os +import pygame, os, enum SCREEN_DIM = (1024, 768) FRAMERATE = 60 @@ -30,7 +30,8 @@ IMAGE_FILES = { "Beta_Icon" : os.path.join("data", "beta_material.png"), "Gamma_Icon" : os.path.join("data", "gamma_material.png"), "UI_Tray" : os.path.join("data", "hud_tray.png"), - "Fix_Aura" : os.path.join("data", "fix_aura.png") + "Fix_Aura" : os.path.join("data", "fix_aura.png"), + "Vortex" : os.path.join("data", "vortex.png") } FONTPATH = os.path.join("data", "Segment7Standard.otf") TURN_LEFT_KEY = pygame.K_a @@ -39,3 +40,4 @@ BRAKE_KEY = pygame.K_s SHOOT_KEY = pygame.K_SPACE THRUST_KEY = pygame.K_w REPAIR_KEY = pygame.K_e +MATERIALS = enum.Enum("MATERIALS", "Alpha Beta Gamma") diff --git a/src/game.py b/src/game.py @@ -28,14 +28,14 @@ class Game(object): self.level_factor = 1 self.asteroid_spawn_timer = 100 self.gate_defs = [ - [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (416, 200) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (480, 200) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 200) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 264) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (544, 328) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (480, 328) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 328) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 264) ], + [ 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) ], ] self.load_level() @@ -57,12 +57,6 @@ class Game(object): x = 0 for n in self.gate_defs: - if n[1] == 0: - rqstr = "Alpha" - elif n[1] == 1: - rqstr = "Beta" - else: - rqstr = "Gamma" if not n[0]: bstr = "Fixed" else: @@ -73,7 +67,7 @@ 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], rqstr)) + self.camera_draw_group.add(sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], n[1])) 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 @@ -67,6 +67,7 @@ class Ship(CustomSprite): self.blinking_timer = self.blinking_timer_max self.aura = FixAura(self.manager, self.manager.images["Fix_Aura"], self.rect.center, 0, self) self.manager.camera_draw_group.add(self.aura) + self.materials = { m : 0 for m in MATERIALS } def thrust(self): if self.speed < SHIP_MAX_SPEED: @@ -184,7 +185,7 @@ class GatePiece(CustomSprite): self.halo_image = None self.halo_rect = None if self.broken: - self.halo_image = pygame.transform.rotate(self.manager.images[self.requirement + "_Halo_" + or_name], self.angle) + self.halo_image = pygame.transform.rotate(self.manager.images[self.requirement.name + "_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 @@ -266,3 +267,14 @@ class FixAura(CustomSprite): def act(self): self.rect.center = self.anchor.rect.center self.rotate(self.angle + 5) + +class Pickup(CustomSprite): + + def __init__(self, manager, image, pos, angle = 0, material = MATERIALS.Alpha): + super().__init__(manager, image, pos, angle) + self.material = material + + def act(self): + if self.rect.colliderect(self.manager.ship.rect): + self.manager.ship.materials[self.material] += 1 + self.kill()