Return to repo list

gatemender

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

commit 707147ae24f199d88aa2e3b33c4543ef8c4952e7
parent 50166ac5cec6253079fe79f5222e1691df0e4b78
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 07:48:00 -0600

Added fix button and aura

Diffstat:
Adata/fix_aura.png | 0
Msrc/constants.py | 4+++-
Msrc/game.py | 19++++++++++---------
Msrc/sprites.py | 24+++++++++++++++++++++++-
4 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/data/fix_aura.png b/data/fix_aura.png Binary files differ. diff --git a/src/constants.py b/src/constants.py @@ -29,10 +29,12 @@ IMAGE_FILES = { "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"), - "UI_Tray" : os.path.join("data", "hud_tray.png") + "UI_Tray" : os.path.join("data", "hud_tray.png"), + "Fix_Aura" : os.path.join("data", "fix_aura.png") } TURN_LEFT_KEY = pygame.K_a TURN_RIGHT_KEY = pygame.K_d BRAKE_KEY = pygame.K_s SHOOT_KEY = pygame.K_SPACE THRUST_KEY = pygame.K_w +REPAIR_KEY = pygame.K_e diff --git a/src/game.py b/src/game.py @@ -83,15 +83,6 @@ class Game(object): def shift_frames(self): self.frameclock.tick(FRAMERATE) - def handle_input(self): - - # Keyboard handling - self.ship.turning_left = self.keys[TURN_LEFT_KEY] - self.ship.turning_right = self.keys[TURN_RIGHT_KEY] - self.ship.braking = self.keys[BRAKE_KEY] - self.ship.shooting = self.keys[SHOOT_KEY] - self.ship.thrusting = self.keys[THRUST_KEY] - def handle_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -103,6 +94,16 @@ class Game(object): if event.key < len(self.keys): self.keys[event.key] = False + def handle_input(self): + + # Keyboard handling + self.ship.turning_left = self.keys[TURN_LEFT_KEY] + self.ship.turning_right = self.keys[TURN_RIGHT_KEY] + self.ship.braking = self.keys[BRAKE_KEY] + self.ship.shooting = self.keys[SHOOT_KEY] + self.ship.thrusting = self.keys[THRUST_KEY] + self.ship.fixing = self.keys[REPAIR_KEY] + def update_screen(self): self.screen.fill((44, 44, 44)) self.camera_surface.fill((0, 0, 0)) diff --git a/src/sprites.py b/src/sprites.py @@ -18,6 +18,7 @@ class CustomSprite(pygame.sprite.Sprite): self.angle = angle if angle != 0: self.rotate(angle) + self.visible = True def rotate(self, angle): self.angle = angle @@ -38,7 +39,7 @@ class CustomSprite(pygame.sprite.Sprite): def update(self, surface = None): self.act() - if surface != None: + if surface != None and self.visible: surface.blit(self.image, self.rect) class Ship(CustomSprite): @@ -56,6 +57,11 @@ class Ship(CustomSprite): self.braking = False self.turnining_left = False self.turning_right = False + self.fixing = False + + # Other + self.aura = FixAura(self.manager, self.manager.images["Fix_Aura"], self.rect.center, 0, self) + self.manager.camera_draw_group.add(self.aura) def thrust(self): if self.speed < SHIP_MAX_SPEED: @@ -99,6 +105,12 @@ class Ship(CustomSprite): else: self.shoot_cooldown -= 1 + # Fixing + if self.fixing: + self.aura.visible = True + else: + self.aura.visible = False + # Check for wrapping if not self.rect.colliderect(self.manager.camera_surface_rect): x = self.rect.centerx @@ -198,3 +210,13 @@ class AsteroidParticle(CustomSprite): self.rotate(self.angle + self.spin_speed) if not self.rect.colliderect(self.manager.screen_rect): self.kill() + +class FixAura(CustomSprite): + + def __init__(self, manager, image, pos, angle = 0, anchor = None): + super().__init__(manager, image, pos, angle) + self.anchor = anchor + + def act(self): + self.rect.center = self.anchor.rect.center + self.rotate(self.angle + 5)