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