Random enemy spawn

This commit is contained in:
2024-10-26 13:51:02 +02:00
parent 40b841e7af
commit 2e2e0c4468
6 changed files with 56 additions and 84 deletions

View File

@ -1,6 +1,6 @@
extends CharacterBody2D
var health = 5
var health = 2
@onready var player = get_node("/root/Game/player")
func _physics_process(delta: float) -> void:

15
scripts/game.gd Normal file
View File

@ -0,0 +1,15 @@
extends Node2D
func spawn_mob():
var new_mob = preload("res://scenes/enemy.tscn").instantiate()
%PathFollow2D.progress_ratio = randf()
new_mob.global_position = %PathFollow2D.global_position
add_child(new_mob)
func _on_timer_timeout() -> void:
spawn_mob()

20
scripts/gun.gd Normal file
View File

@ -0,0 +1,20 @@
extends Area2D
func _physics_process(delta: float) -> void:
var enemies_in_range = get_overlapping_bodies()
if enemies_in_range.size() > 0:
var closest_target = enemies_in_range.front()
look_at(closest_target.global_position)
func shoot():
const BULLET = preload("res://scenes/bullet.tscn")
var new_bullet = BULLET.instantiate()
new_bullet.global_position = %shootingPoint.global_position
new_bullet.global_rotation = %weponPivot.global_rotation
%shootingPoint.add_child(new_bullet)
func _on_timer_timeout() -> void:
shoot()