-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
53 lines (45 loc) · 1.63 KB
/
player.py
File metadata and controls
53 lines (45 loc) · 1.63 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
class Player():
def __init__(self, row, col, fall_rate, default_fall_rate):
self.row = row
self.col = col
self.up_distance = 0
self.command_left_right = 0
self.fall_rate = fall_rate
self.default_fall_rate = default_fall_rate
self.used_jump = False
self.mode = 'EASY'
def process_command(self, command_lateral, command_up_y, command_up_z):
self.command_left_right += command_lateral
if self.mode == 'EASY':
if (command_up_y != 0 or command_up_z != 0) and not self.used_jump:
self.used_jump = True
self.up_distance = -250
elif self.mode == 'REGULAR':
if command_up_z != 0 and not self.used_jump:
self.used_jump = True
self.up_distance = -250
def update_location(self, max_cols):
# Update horizontal location
self.col += self.command_left_right
if self.col < 0:
self.col = 0
elif self.col > max_cols:
self.col = max_cols
self.command_left_right = 0
# Update vertical location
if self.up_distance < 0:
self.row -= 10
self.up_distance += 10
def constant_fall(self, on_pad):
if on_pad:
self.row += self.default_fall_rate
self.used_jump = False
else:
self.row += self.fall_rate
if self.mode == 'EASY':
if self.row + 60 >= 960:
self.row = 960 - 60
def has_died(self, death_row):
if self.mode == 'EASY':
return False
return self.row > death_row