Implemented proper player movement
This commit is contained in:
parent
e184e6417b
commit
6efd5652dd
@ -21,10 +21,18 @@ class Player(Entity):
|
||||
self.rotate(rotation)
|
||||
# Otherwise, move one tile to a given direction
|
||||
else:
|
||||
return 1
|
||||
# TODO: Collision checks
|
||||
if rotation.value == Rotations.NORTH.value:
|
||||
self.rect.y -= self.rect.w
|
||||
elif rotation.value == Rotations.EAST.value:
|
||||
self.rect.x += self.rect.w
|
||||
elif rotation.value == Rotations.SOUTH.value:
|
||||
self.rect.y += self.rect.w
|
||||
elif rotation.value == Rotations.WEST.value:
|
||||
self.rect.x -= self.rect.w
|
||||
|
||||
def rotate(self, rotation):
|
||||
self.image = pygame.transform.rotate(self.image, (abs(self.rotation.value - rotation.value) * 90))
|
||||
self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90))
|
||||
self.rotation = rotation
|
||||
|
||||
|
||||
|
@ -2,12 +2,15 @@ import pygame
|
||||
|
||||
from src.entities.Player import Rotations
|
||||
|
||||
|
||||
# Player can move every given milliseconds
|
||||
TIMEOUT = 100
|
||||
class EventManager:
|
||||
keyTimeout = 0
|
||||
|
||||
def __init__(self, gameObject, player):
|
||||
self.game = gameObject
|
||||
self.player = player
|
||||
|
||||
self.keyTimer = pygame.time.Clock()
|
||||
# Player controls
|
||||
|
||||
# TODO
|
||||
@ -21,12 +24,15 @@ class EventManager:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
self.game.running = False
|
||||
|
||||
self.handlePlayerControls(keys)
|
||||
self.keyTimeout += self.keyTimer.tick()
|
||||
if self.keyTimeout >= TIMEOUT:
|
||||
self.handlePlayerControls(keys)
|
||||
self.keyTimeout = 0
|
||||
|
||||
def handlePlayerControls(self, keys):
|
||||
# Key names are temporary
|
||||
# TODO: Load key bindings from JSON
|
||||
|
||||
if keys[pygame.K_w]:
|
||||
self.player.move(Rotations.NORTH)
|
||||
if keys[pygame.K_s]:
|
||||
|
Loading…
Reference in New Issue
Block a user