Return to repo list

gatemender

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

commit 9abae80cee0bfaad77e9691d629cba4eef692598
parent 22b59e96c9b262b3060214f14f5ee07cf3ee5427
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun,  6 Dec 2020 17:02:18 -0600

Added turning and braking

Diffstat:
Msrc/game.py | 33+++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/game.py b/src/game.py @@ -13,8 +13,12 @@ IMAGE_FILES = { "Small_Asteroid" : os.path.join("data", "asteroid_small.png"), "Medium_Asteroid" : os.path.join("data", "asteroid_medium.png"), "Big_Asteroid" : os.path.join("data", "asteroid_big.png"), + "Asteroid_Particle" : os.path.join("data", "asteroid_particle.png"), "Space_Background" : os.path.join("data", "space_background.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 @@ -67,23 +71,37 @@ class Ship(CustomSprite): # Bools self.shooting = False self.thrusting = False + self.braking = False + self.turnining_left = False + self.turning_right = False def thrust(self): if self.speed < SHIP_MAX_SPEED: self.speed += self.thrust_factor - def decelerate(self): - self.speed -= 2 * self.thrust_factor + def decelerate(self, amount = 1): + self.speed -= amount if self.speed < 0: self.speed = 0 + def turn(self, amount): + self.rotate(self.angle + amount) + def act(self): - #Thrusting + # Turning + if self.turning_left: + self.turn(2) + if self.turning_right: + self.turn(-2) + + #Thrusting / Braking / Slowing if self.thrusting: self.thrust() + elif self.braking: + self.decelerate(5 * self.thrust_factor) elif self.speed > 0: - self.decelerate() + self.decelerate(2 * self.thrust_factor) self.direction_move(self.speed) #Shooting @@ -127,10 +145,13 @@ class Game(object): def handle_input(self): # Mouse handling - mx, my = pygame.mouse.get_pos() - self.ship.rotate(math.degrees(math.atan2(-(my - self.ship.rect.centery), mx - self.ship.rect.centerx))) + #mx, my = pygame.mouse.get_pos() + #self.ship.rotate(math.degrees(math.atan2(-(my - self.ship.rect.centery), mx - self.ship.rect.centerx))) # 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]