-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.gd
114 lines (106 loc) · 3.66 KB
/
Player.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
extends CharacterBody2D
@export var SPEED = 240
var score = 0.0
var threshold1 = 2.0
var threshold2 = 5.0
var threshold3 = 10.0
var threshold4 = 15.0
var paused = false
# Called when the node enters the scene tree for the first time.
func _ready():
$AnimatedSprite2D.play()
$MusicSafe.play()
func pause():
paused = true
func unpause():
paused = false
$AnimatedSprite2D.play()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if paused:
return
velocity = Vector2.ZERO # The player's movement vector.
if Input.is_action_pressed("move_right"):
velocity.x += 1
#if not lockDirection:
# lookingLeft = false
if Input.is_action_pressed("move_left"):
velocity.x -= 1
#if not lockDirection:
# lookingLeft = true
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
if Input.is_action_just_pressed("emit_sound"):
$MakeSound.play()
for seeker in get_tree().get_nodes_in_group("seeker"):
seeker._on_sound_heard(global_position)
if velocity.length() > 0:
if !$AudioStreamPlayer2D.playing:
$AudioStreamPlayer2D.play()
velocity = velocity.normalized() * SPEED
look_at(global_position + velocity)
rotation = rotation + deg_to_rad(90)
if score >= threshold4:
$AnimatedSprite2D.animation = "Walk4"
elif score >= threshold3:
$AnimatedSprite2D.animation = "Walk3"
elif score >= threshold2:
$AnimatedSprite2D.animation = "Walk2"
elif score >= threshold1:
$AnimatedSprite2D.animation = "Walk1"
else:
$AnimatedSprite2D.animation = "Walk0"
else:
$AudioStreamPlayer2D.stop()
if score >= threshold4:
$AnimatedSprite2D.animation = "Idle4"
elif score >= threshold3:
$AnimatedSprite2D.animation = "Idle3"
elif score >= threshold2:
$AnimatedSprite2D.animation = "Idle2"
elif score >= threshold1:
$AnimatedSprite2D.animation = "Idle1"
else:
$AnimatedSprite2D.animation = "Idle0"
get_tree().get_nodes_in_group("camera")[0].position = global_position
move_and_slide()
func _on_food_touch(amount):
score += amount
get_tree().get_nodes_in_group("scoreLabel")[0].text = str(score)
if score >= threshold4:
SPEED = 150
$CollisionShape2D.scale = Vector2(9,9)
$AudioStreamPlayer2D.pitch_scale = 0.5
$Eating.pitch_scale = 0.75
$MakeSound.pitch_scale = 0.75
get_tree().get_nodes_in_group("progressBar")[0].scale.y = 1
get_tree().get_nodes_in_group("camera")[0].smooth_zoom(Vector2(1.6,1.6))
get_tree().root.get_child(0).big_boy_time();
elif score >= threshold3:
SPEED = 110
$CollisionShape2D.scale = Vector2(4.5,4.5)
$AudioStreamPlayer2D.pitch_scale = 0.8
$MakeSound.pitch_scale = 0.8
get_tree().get_nodes_in_group("progressBar")[0].set_scale(Vector2(1,(score-threshold3)/(threshold4-threshold3)))
get_tree().get_nodes_in_group("camera")[0].smooth_zoom(Vector2(1.8,1.8))
elif score >= threshold2:
SPEED = 130
$CollisionShape2D.scale = Vector2(3,3)
$AudioStreamPlayer2D.pitch_scale = 1
$MakeSound.pitch_scale = 1
get_tree().get_nodes_in_group("progressBar")[0].set_scale(Vector2(1,(score-threshold2)/(threshold3-threshold2)))
get_tree().get_nodes_in_group("camera")[0].smooth_zoom(Vector2(2,2))
elif score >= threshold1:
SPEED = 160
$CollisionShape2D.scale = Vector2(1.7,1.7)
$AudioStreamPlayer2D.pitch_scale = 1.5
$MakeSound.pitch_scale = 1.5
get_tree().get_nodes_in_group("progressBar")[0].set_scale(Vector2(1,(score-threshold1)/(threshold2-threshold1)))
get_tree().get_nodes_in_group("camera")[0].smooth_zoom(Vector2(2.2,2.2))
else:
get_tree().get_nodes_in_group("progressBar")[0].set_scale(Vector2(1,score/threshold1))
# It's joever
func _on_guard_touch():
get_tree().root.get_child(0).game_over();