-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer1.gd
140 lines (115 loc) · 2.93 KB
/
player1.gd
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
extends KinematicBody2D
signal riseWater(yposition)
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
const GRAVITY = 350.0
const SPEED = 200
const AUTO_JUMP = true
var loop_on_x = true setget set_loop_on_x, get_loop_on_x
var velocity = Vector2()
var onPlatform = false
export var health = 100
signal game_over
var timer
var can_jump = false
func enable_jumping():
$Timer.start()
can_jump = true
func get_loop_on_x():
return loop_on_x
func set_loop_on_x(new_val):
loop_on_x = new_val
func _physics_process(delta):
apply_gravity(delta)
rise_water(delta)
if can_jump:
if Input.is_action_pressed("ui_up") and is_on_floor():
print("Jumped")
velocity.y -= 600
$JumpSound.play()
elif AUTO_JUMP and is_on_floor():
print("AutoJumped")
velocity.y -= 600
$JumpSound.play()
if Input.is_action_pressed("ui_left") and not is_on_floor():
velocity.x = -SPEED
elif Input.is_action_pressed("ui_right") and not is_on_floor():
velocity.x = SPEED
else:
velocity.x = velocity.x / 1.2
if loop_on_x:
if position.x <= 0 and velocity.x < 0:
position.x = get_viewport().get_visible_rect().size[0]
if position.x >= get_viewport().get_visible_rect().size[0] and velocity.x > 0:
position.x = 0
else:
if position.x <= 0 and velocity.x < 0:
position.x = 0
velocity.x = 0
if position.x >= get_viewport().get_visible_rect().size[0] and velocity.x > 0:
position.x = get_viewport().get_visible_rect().size[0]
velocity.x = 0
move_and_slide(velocity, Vector2(0, -1)) # Move down 1 pixel per physics frame
# if get_slide_count() == 0:
# onPlatform = false
# for i in range(get_slide_count()):
# var collision = get_slide_collision(i)
# onPlatform = true
func apply_gravity(delta):
if is_on_floor():
velocity.y = 0
else:
velocity.y += delta * GRAVITY
# Called when the node enters the scene tree for the first time.
func _ready():
Global.Player = self
update_player_state()
pass
func rise_water(delta):
if velocity.y <= 0:
emit_signal("riseWater", position.y)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_player_body_entered(body):
pass # Replace with function body.
func update_player_state():
if health >= 70:
$AnimatedSprite.animation = "large"
elif health >= 30:
$AnimatedSprite.animation = "medium"
elif health > 0:
$AnimatedSprite.animation = "small"
else:
emit_signal("game_over")
hide()
can_jump = false
pass
func _on_player_water_death(body):
health = 0
update_player_state()
func _on_player_coal(body):
if health >= 70:
health = 100
else:
health += 30
update_player_state()
func _on_player_log(body):
if health >= 90:
health = 100
else:
health += 10
update_player_state()
func _on_player_water(body):
if health <= 30:
health = 0
else:
health -= 30
update_player_state()
func _on_Timer_timeout():
if health <= 5:
health = 0
else:
health -= 5
update_player_state()