import pygame import numpy as np from . import actor class Player(actor.Actor): def __init__(self, world): super().__init__(world) def phy_update(self, dt): pass def update(self, dt): delta = np.array([0.0, 0.0]) keys = pygame.key.get_pressed() if keys[pygame.K_z] or keys[pygame.K_w]: delta[1] -= 1.0 if keys[pygame.K_s]: delta[1] += 1.0 if keys[pygame.K_q] or keys[pygame.K_a]: delta[0] -= 1.0 if keys[pygame.K_d]: delta[0] += 1.0 norm = np.linalg.norm(delta) if norm > 0: delta /= norm delta *= self.speed self.pos += delta * dt