-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.py
More file actions
124 lines (108 loc) · 2.97 KB
/
Player.py
File metadata and controls
124 lines (108 loc) · 2.97 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
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
from Rectangle import *
from texture import *
G.squirrel = Rec(80, 0 ,530, 470)
"""move player in x direction"""
def player_mover_x(player):
global man_path
G.ball_x_velocity = 0 # reset x velocity
if G.keystates[0] or G.keystates[1]:
G.factor += 1
else:
G.factor=1
if G.keystates[0] == True and player.left > 0: # LEFT OR right
G.ball_x_velocity += G.factor * 0.25 * G.ball_dir_x
G.index=14+(G.factor // 5) % 4
if G.keystates[1] == True and player.right < 800:
G.index=10+(G.factor // 5) % 4
G.ball_x_velocity += G.factor * 0.25 * G.ball_dir_x
player.left +=G.ball_x_velocity
player.right += G.ball_x_velocity
def player_mover_y(player):
"""jump in y direction"""
if G.jumping == True:
if G.moving_up <= 0:
G.jumping = False
else:
if G.stand_left:
G.index=8
else:
G.index=9
G.jump_texture=G.index
if G.ball_x_velocity < 0:
G.ball_x_velocity *= -1
G.ball_y_velocity = 0.5 * G.ball_x_velocity + G.moving_up
G.moving_up -= 10 * G.dtime
player.bottom += G.ball_y_velocity
player.top = player.bottom + 80
else:
"""fall"""
for plate in G.plates:
# collison detection
if (player.left >= plate.left - 25 and player.right <= plate.right + 25 and
plate.top>= player.bottom+10 >= plate.bottom):
player.bottom = plate.top - 35
player.top = player.bottom + 80
player.left += G.stair_step_x * plate.direction
player.right += G.stair_step_x * plate.direction
"""check score"""
if plate.landed == False:
G.score += 1
plate.landed = True
if G.hight_score < G.score:
G.hight_score = G.score
"""check if the first jump has been done successfully"""
if G.first_jump:
G.first_jump=False
""" collison detection with plate hazelnuts"""
if plate.hazelnut:
if player.right > plate.hazelnut.left and player.left < plate.hazelnut.right :
plate.hazelnut=None
G.score += 5
"""reset values"""
G.moving_up = 16
G.moving_down = 0
G.ball_y_velocity = 0
G.on_plate = True
if G.keystates[0]== False and G.keystates[1] == False:
if G.stand_left:
G.index=6
else:
G.index=7
break
else:
G.on_plate = False ##used for movinf ball down
if player.bottom > G.frastom_bottom and not G.on_plate:
if G.stand_left:
G.index=18
else:
G.index=19
G.ball_y_velocity = G.moving_down
G.moving_down += 10 * G.dtime
player.bottom -= G.ball_y_velocity
player.top = player.bottom + 80
if player.bottom < G.frastom_bottom:
player.bottom = 0
player.top = player.bottom + 80
G.moving_down = 0
G.moving_up = 16
G.ball_y_velocity = 0
G.on_plate = False
G.first_jump=True
if G.stand_left:
G.index=6
else:
G.index=7
if G.score>3:
G.gamestart = False
G.gameover = True
G.score = 0
G.frastom_y = 0
G.frastom_bottom = 0
G.frastom_top = 800
G.plates = []
G.stair_step_x = 0
G.index=6
def player():
player_mover_x(G.squirrel)
player_mover_y(G.squirrel)
G.squirrel.drawrec(G.index)