-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
29 lines (26 loc) · 865 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
class Player:
def __init__(self):
#pygame.sprite.Sprite.__init__(self)
self.movex = 0 # move along X
self.movey = 0 # move along Y
self.frame = 0 # count frames
def control(self,x,y):
""" control player movement """
self.movex += x
self.movey += y
def update(self):
""" Update sprite position"""
self.rect.x = self.rect.x + self.movex
self.rect.y = self.rect.y + self.movey
# moving left
if self.movex < 0:
self.frame += 1
if self.frame > 3*ani:
self.frame = 0
self.image = self.images[self.frame//ani]
# moving right
if self.movex > 0:
self.frame += 1
if self.frame > 3*ani:
self.frame = 0
self.image = self.images[self.frame//ani]