Return to repo list

gatemender

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

commit 815ce8abb74fe12ff3c8934f140433dafd04027c
parent 5f37184c3c8937f25dc92bfd03956a3614f6bf80
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed, 16 Dec 2020 16:54:41 -0600

added thrusting graphic to ship

Diffstat:
Mdata/fire.png | 0
Msrc/sprites.py | 40++++++++++++++++++++++++++++++++++++----
2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/data/fire.png b/data/fire.png Binary files differ. diff --git a/src/sprites.py b/src/sprites.py @@ -71,6 +71,8 @@ class Ship(CustomSprite): self.be_dead_timer = 60 self.burst_counter = 100 self.burst_delay = 2 + self.manager.level_factor + self.thrust_sprite = ThrustSprite(self.manager, self.manager.images["Ship_Fire"], self.rect.center, 0, self) + self.prev_pos = [ self.rect.center for i in range(0, 6) ] def thrust(self): self.manager.play_sound("Thrust", 2, False, 0, False) @@ -112,12 +114,21 @@ class Ship(CustomSprite): self.turn(-4) #Thrusting / Braking / Slowing + self.thrust_sprite.rect.center = self.rect.center if self.thrusting: self.thrust() - elif self.braking: - self.decelerate(5 * self.thrust_factor) - elif self.speed > 0: - self.decelerate(2 * self.thrust_factor) + self.prev_pos.pop(5) + self.prev_pos.insert(0, self.rect.center) + if self.speed > 2: + self.thrust_sprite.visible = True + self.thrust_sprite.rect.center = self.prev_pos[int(self.speed) // 2] + else: + if self.braking: + self.decelerate(5 * self.thrust_factor) + elif self.speed > 0: + self.decelerate(2 * self.thrust_factor) + self.prev_pos = [ self.rect.center for i in range(0, 6) ] + self.thrust_sprite.visible = False self.direction_move(self.speed) #Shooting @@ -173,6 +184,7 @@ class Ship(CustomSprite): # Damage blink and asteroid col if self.blinking: if (self.blinking_timer // 10) % 2 != 0: + self.thrust_sprite.visible = False self.visible = False else: self.visible = True @@ -195,6 +207,7 @@ class Ship(CustomSprite): # If dead else: + self.thrust_sprite.visible = False self.visible = False self.manager.preserve_gate = True if self.be_dead_timer > 0: @@ -205,6 +218,10 @@ class Ship(CustomSprite): self.manager.change_mode(MODES.Transition) else: self.manager.change_mode(MODES.GameOver) + + def update(self, surface = None): + self.thrust_sprite.update(surface) + super().update(surface) # Bullet class class Bullet(CustomSprite): @@ -447,3 +464,18 @@ class Checkbox(CustomSprite): def act(self): if self.check_cooldown > 0: self.check_cooldown -= 1 + +class ThrustSprite(CustomSprite): + + def __init__(self, manager, image, pos, angle = 0, ship = None): + super().__init__(manager, image, pos, angle) + self.ship = ship + self.flip_timer = 10 + + def act(self): + if self.flip_timer > 0: + self.flip_timer -= 1 + else: + self.base_image = pygame.transform.flip(self.base_image, True, False) + self.flip_timer = 10 + self.rotate(self.ship.angle)