-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
44 lines (32 loc) · 816 Bytes
/
player.py
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
37
38
39
40
41
42
43
44
import pygame
import pygame.sprite
import assets
import location
from location import Location
from pygame import *
from pygame.sprite import *
from assets import *
class Player(Sprite):
def __init__(self, x, y):
super().__init__()
self.image = Surface([15, 15])
self.image.fill(WHITE)
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.dx = 0
self.dy = 0
self.cur_loc = Location(x, y)
self.prev_loc = Location()
def ismoving(self):
return self.dx != 0 or self.dy != 0
def change_speed(self, vx=0, vy=0):
if not self.ismoving():
self.prev_loc = self.cur_loc.make_copy()
self.dx += vx
self.dy += vy
def update(self):
self.cur_loc.setx(self.rect.x)
self.cur_loc.sety(self.rect.y)
self.rect.x += self.dx
self.rect.y += self.dy