-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
124 lines (79 loc) · 2.37 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import enum
import os
from enum import Enum
import pygame.surface
class Phase(Enum):
NORMAL = enum.auto()
SPLINTER = enum.auto()
class Size(Enum):
NORMAL = 32
SPLINTER = 16
class XSpeed(Enum):
NORMAL = 3
SPLINTER = 3
class YSpeed(Enum):
NORMAL = 0.35
SPLINTER = 8
class Player:
def __init__(self, game):
self.game = game
self.x = 100 # pos
self.y = 500
self.xsm = 1 # speed multiplier
self.ysm = 1
self.xv = 1 # velocity
self.yv = 0
self.phase: Phase = Phase.SPLINTER
self.size = Size[self.phase.name.upper()].value
self.textures = {}
for p in Phase:
self.textures[p.name] = (pygame.image.load(os.path.join("assets", "player", str(p.name).lower() + '.bmp')))
self.jump_timer = -1
self.gy = (600 - self.size)
def handle_input(self, keys):
if keys[pygame.K_SPACE] or keys[pygame.K_RETURN]:
self.jump()
def get_speeds(self):
fxs = XSpeed[self.phase.name.upper()].value
fys = YSpeed[self.phase.name.upper()].value
return fxs, fys
def update(self):
if self.x > 1000:
self.x = 0
self.size = Size[self.phase.name.upper()].value
cy = (0 + self.size) # platform
gy = (600 - self.size) # ground
fxs = self.get_speeds()[0]
fys = self.get_speeds()[1]
self.xv = (fxs * self.xsm)
if self.phase == Phase.NORMAL:
self.yv += (fys * self.ysm)
elif self.phase == Phase.SPLINTER:
self.yv = (fys * self.ysm)
self.x += self.xv
self.y += self.yv
if self.y >= gy:
self.y = gy
if self.y <= cy:
self.y = cy
print("y:", self.y)
print("vy:", self.yv)
self.game.breadcrumbs.append([
self.x,
self.y
])
def jump(self):
if self.phase == Phase.SPLINTER:
self.y -= self.get_speeds()[1] * 2
if self.jump_timer >= 0:
self.jump_timer = -1
return
if self.phase == Phase.NORMAL:
if self.y >= self.gy:
self.yv = -8
def render(self, screen: pygame.surface.Surface):
screen.blit(self.textures[self.phase.name], (self.x, self.y))
# class PlayerBase:
#
# def __init__(self):
# pass