-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_player.gd
More file actions
188 lines (146 loc) · 4.4 KB
/
main_player.gd
File metadata and controls
188 lines (146 loc) · 4.4 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
extends CharacterBody2D
var bullet = preload("res://bullet.tscn")
var enemy = preload("res://enemy.tscn").instantiate()
@onready
#onready var bullet = $bullet
var WHO = 0
var it = 0
var SPEED = 2000
var bulletspeed = 2000
var hp = 100
var hit = 1
var acceptance = false
var heal1 = true
var heal2 = true
var heal3 = true
var heal4 = true
var heal5 = true
# Get the gravity from the project settings to be synced with RigidBody nodes.
func _ready():
$MultiplayerSynchronizer.set_multiplayer_authority(str(name).to_int())
@onready var anim = get_node("AnimationPlayer")
func _physics_process(_delta):
# print(EditorSceneFormatImporterBlend)
# Add the gravity.
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
if $MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id():
var ydirection = Input.get_axis("W", "S")
if Input.is_action_just_pressed("SHIFT"):
SPEED = 100000
if ydirection:
velocity.y = ydirection * SPEED
if velocity.x == 0:
if velocity.y < 0:
anim.play("Up")
if velocity.y > 0:
anim.play("Down")
else: velocity.y = move_toward(velocity.y, 0, SPEED)
var direction = Input.get_axis("A", "D")
if direction:
velocity.x = direction * SPEED
if velocity.y ==0:
if velocity.x > 0:
anim.play("Right")
if velocity.x < 0:
anim.play("Left")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y ==0:
anim.play("Idle")
move_and_slide()
SPEED = 500
if Input.is_action_just_pressed("LMB"):
# WHO += 1
shoot.rpc()
if hp < 0:
get_tree().change_scene_to_file("res://game_over.tscn")
# var player = get_tree().get_nodes_in_group("player")[0]
# var playerpos = player.get_position()
# print(playerpos)
# if WHO%2 == 0:
# shoot()
# #print(WHO)
# bullet.visible = true
# it = 0
# else:
# if it == 0:
# bullet.visible = false
# it += 1
#
@rpc("any_peer","call_local")
func shoot():
var factor = 2.5
var temp = bullet.instantiate()
temp.position.y += 1000
temp.global_position = global_position
var target = get_global_mouse_position()
var direction = target - global_position
temp.set_linear_velocity(direction*factor)
get_parent().add_child(temp)
#func shoot():
# if !SOMEONE:
# get_parent().add_child(bullet)
# bullet_to_my_head = bullet
# bullet.global_position = global_position
# var target = get_global_mouse_position()
# var direction = target - global_position
# bullet.set_linear_velocity(direction)
# SOMEONE = true
## bullet.play("default")
# else:
# var target = get_global_mouse_position()
# var direction = target - global_position
# bullet.set_linear_velocity(direction)
func _on_area_2d_body_entered(body):
var player = get_tree().get_nodes_in_group("player")[0]
var playerpos = player.get_position()
if playerpos.x >= 2200 and playerpos.x <= 2400:
if playerpos.y >= 700 and playerpos.y <= 850:
if heal1:
print("healed")
$hpbar.value +=10
heal1 = false
func _on_area_1_stpotion_body_entered(body):
var player = get_tree().get_nodes_in_group("player")[0]
var playerpos = player.get_position()
if playerpos.x >= 2000 and playerpos.x <= 2500:
if playerpos.y >= 2225 and playerpos.y <= 3000:
print("boundary")
if heal3:
print("healed")
$hpbar.value +=10
heal3 = false
func _on_area_2d_2_body_entered(body):
var player = get_tree().get_nodes_in_group("player")[0]
var playerpos = player.get_position()
if playerpos.x >= 4000 and playerpos.x <= 4175:
if playerpos.y >= 375 and playerpos.y <= 525:
if heal2:
print("healed")
$hpbar.value +=10
heal2 = false
func _on_areasecondpotion_body_entered(body):
var player = get_tree().get_nodes_in_group("player")[0]
var playerpos = player.get_position()
if playerpos.x >= 1450 and playerpos.x <= 1900:
if playerpos.y >= 950 and playerpos.y <= 1400:
if heal4:
print("healed")
$hpbar.value +=10
heal4 = false
func _on_area_2d_3_body_entered(body):
var player = get_tree().get_nodes_in_group("player")[0]
var playerpos = player.get_position()
if playerpos.x >= 3400 and playerpos.x <= 3800:
if playerpos.y >= -600 and playerpos.y <= -200:
if heal5:
print("healed")
$hpbar.value +=10
heal5 = false
func _on_playerhitbox_body_entered(_body):
$hpbar.value = hp
# hit += 5
hp = 100 - hit
# print("real hp is", hp)
# acceptance = false