summaryrefslogtreecommitdiffstats
path: root/Game/player.py
blob: 941d62d75e66a060b863e07f91fd6bb56e893186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from setup import *


class Player:
    movement_acceleration = 0.0025
    horizontal_resistance = 0.005
    skin = pygame.image.load('textures/player.png')
    width, height = skin.get_width(), skin.get_height()

    def __init__(self, x, y):
        self.position = pygame.Vector2(x, y)
        self.velocity = pygame.Vector2(0, 0)
        self.acceleration = pygame.Vector2(0, 0)

    def move_left(self):
        self.acceleration.x -= self.movement_acceleration

    def move_right(self):
        self.acceleration.x += self.movement_acceleration

    def move_forward(self):
        self.acceleration.y -= self.movement_acceleration

    def move_backwards(self):
        self.acceleration.y += self.movement_acceleration

    def update(self, delta_time):
        self.position += self.velocity * delta_time
        self.velocity += self.acceleration * delta_time

        self.velocity.xy *= max(0, 1 - (delta_time * self.horizontal_resistance))
        self.acceleration.xy = 0, 0

    def draw(self, window):
        middle = (SCREEN_WIDTH / 2 - Player.width / 2, SCREEN_HEIGHT / 2 - Player.height / 2)
        window.blit(self.skin, middle)