-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.py
More file actions
102 lines (78 loc) · 2.86 KB
/
Copy pathPlayer.py
File metadata and controls
102 lines (78 loc) · 2.86 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pygame
#Defineerime värvid
BLACK = (0, 0, 0)
class Player(pygame.sprite.Sprite):
""" Mängija klass"""
# Kiirus
change_x = 0
change_y = 5
# Punktid
points = 0
def __init__(self, x, y):
""" Constructor funktsioon """
# Kõrgema konstruktori kutsumine
super().__init__()
# Laius,kõrgus
self.img_file = "./sprites/player/p3_front.png"
self.img_move = []
for queue in range(1,12):
if queue < 10:
self.img_move.append(pygame.image.load("./sprites/player/PNG/p3_walk0"+str(queue)+".png"))
else:
self.img_move.append(pygame.image.load("./sprites/player/PNG/p3_walk" + str(queue) + ".png"))
self.image = pygame.image.load(self.img_file)
self.image = pygame.transform.scale(self.image, (48,48))
self.rect = self.image.get_rect()
self.rect.y = y
self.rect.x = x
self.jumping_allowed = 0
self.col = 0
self.is_jumping = 0
def collision(self):
if self.col == 0:
self.col = 1
def changespeed(self, x, y):
""" Muudab mängija kiirust, nupuvahetusega"""
self.change_x += x
self.change_y += y
def move(self, walls):
""" Liigutab mängijat"""
# Liigub paremale/vasakule
self.rect.x += self.change_x
# Kas me tabasime seina?
wall_collision_list = pygame.sprite.spritecollide(self, walls, False)
for block in wall_collision_list:
# Ei muuda asukohta
if self.change_x > 0:
self.rect.right = block.rect.left
else:
# Ei muuda asukohta
self.rect.left = block.rect.right
# Liigub üles/alla
self.rect.y += self.change_y
# Kas me tabasime seina?
wall_collision_list = pygame.sprite.spritecollide(self, walls, False)
if wall_collision_list == []:
self.col = 0
for block in wall_collision_list:
# Ei muuda asukohta
if self.change_y > 0:
self.rect.bottom = block.rect.top
self.collision()
else:
self.rect.top = block.rect.bottom
self.collision()
if self.is_jumping == 1 and self.change_y <= 5:
pass
else:
self.is_jumping = 0
if self.is_jumping == 1:
self.change_y += 1
if self.change_x > 0:
for movement in self.img_move:
self.image = pygame.transform.scale(movement, (48,48))
elif self.change_x < 0:
for movement in self.img_move:
self.image = pygame.transform.flip(pygame.transform.scale(movement,(48,48)),True,False)
elif self.change_x == 0:
self.image = pygame.transform.scale(pygame.image.load(self.img_file),(48,48))