-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
56 lines (46 loc) · 2.17 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
import pygame
class Player(pygame.sprite.Sprite):
def __init__(self, width, height, ):
pygame.sprite.Sprite.__init__(self)
# self.image = pygame.Surface([width, height])
self.image = pygame.transform.scale(pygame.image.load("pixelsprite.png").convert_alpha(), (width, height))
# self.image.fill((255,255,255))
self.rect = self.image.get_rect()
self.orientation = "right"
def face(self, direction):
# left
if direction == "left":
if self.orientation == "right":
self.image = pygame.transform.flip(self.image, True, False)
if self.orientation == "down":
self.image = pygame.transform.rotate(self.image, -90)
if self.orientation == "up":
self.image = pygame.transform.rotate(self.image, 90)
self.orientation = "left"
# right
elif direction == "right":
if self.orientation == "left":
self.image = pygame.transform.flip(self.image, True, False)
if self.orientation == "down":
self.image = pygame.transform.rotate(self.image, 90)
if self.orientation == "up":
self.image = pygame.transform.rotate(self.image, -90)
self.orientation = "right"
# up
elif direction == "up":
if self.orientation == "left":
self.image = pygame.transform.rotate(self.image, -90)
if self.orientation == "right":
self.image = pygame.transform.rotate(self.image, 90)
if self.orientation == "down":
self.image = pygame.transform.rotate(self.image, 180)
self.orientation = "up"
# down
elif direction == "down":
if self.orientation == "right":
self.image = pygame.transform.rotate(self.image, -90)
if self.orientation == "left":
self.image = pygame.transform.rotate(self.image, 90)
if self.orientation == "up":
self.image = pygame.transform.rotate(self.image, 180)
self.orientation = "down"