z-hack/Main.gd

40 lines
1.0 KiB
GDScript

extends Node2D
export(PackedScene) var zombie_scene
var relic_left = 5
func add_zombie():
var zombie = zombie_scene.instance()
var zombie_spawn_location = get_node("Enemies/zombiePath/zombieSpawnLocation")
zombie_spawn_location.offset = randi()
zombie.position = zombie_spawn_location.position
if zombie.position.distance_to($Player.position) > 40:
zombie.look_at($Player.position)
zombie.linear_velocity = Vector2(100, 0).rotated(zombie.rotation)
zombie.connect("hit", self, 'player_got_hit')
add_child(zombie)
else:
add_zombie()
func _ready():
VisualServer.set_default_clear_color(Color(0.0,0.0,0.0,1.0))
randomize()
$Player.relic_left(relic_left)
func _on_SpawnEnemy_timeout():
add_zombie()
func player_got_hit():
$Player.player_die()
func score_increase():
print("found a relic")
relic_left -= 1
$Player.relic_left(relic_left)
$Player.light_increase()
print("still " + str(relic_left) + " to find")
func _on_Player_restart():
get_tree().change_scene(get_tree().current_scene.filename)