add virus spawner
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=6 format=4 uid="uid://c5qbqj52kr0aw"]
|
||||
[gd_scene load_steps=7 format=4 uid="uid://c5qbqj52kr0aw"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dhhnr3xkxbxlu" path="res://player.tscn" id="1_vonw3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bsv3h2lpv7h77" path="res://virus.tscn" id="2_oi3di"]
|
||||
[ext_resource type="PackedScene" uid="uid://bldi3fw0vmlu3" path="res://music.tscn" id="3_oi3di"]
|
||||
[ext_resource type="TileSet" uid="uid://c20bl25rqyf68" path="res://assets/tiles/new_tile_set.tres" id="4_0b4ue"]
|
||||
[ext_resource type="PackedScene" uid="uid://cpp7v4jp8kt74" path="res://hand.tscn" id="5_f2txt"]
|
||||
[ext_resource type="PackedScene" uid="uid://co8jnr2dew5ts" path="res://hand.tscn" id="5_f2txt"]
|
||||
[ext_resource type="Script" uid="uid://dycpk6lxabn1l" path="res://virus_spawner.gd" id="6_1ainy"]
|
||||
|
||||
[node name="Level" type="Node2D"]
|
||||
|
||||
@@ -16,8 +17,6 @@ tile_set = ExtResource("4_0b4ue")
|
||||
[node name="Player" parent="." instance=ExtResource("1_vonw3")]
|
||||
position = Vector2(-1200, 0)
|
||||
|
||||
[node name="Virus" parent="." instance=ExtResource("2_oi3di")]
|
||||
|
||||
[node name="MusicMixer" parent="." instance=ExtResource("3_oi3di")]
|
||||
scale = Vector2(2, 2)
|
||||
|
||||
@@ -25,3 +24,12 @@ scale = Vector2(2, 2)
|
||||
|
||||
[node name="Hand" parent="CanvasLayer" instance=ExtResource("5_f2txt")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="VirusSpawner" type="Node" parent="."]
|
||||
script = ExtResource("6_1ainy")
|
||||
Virus = ExtResource("2_oi3di")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="Timer" to="VirusSpawner" method="_on_timer_timeout"]
|
||||
|
||||
@@ -99,3 +99,7 @@ func _process(delta):
|
||||
move_state = MoveState.Still;
|
||||
|
||||
move_and_slide();
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
pass # Replace with function body.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Node2D
|
||||
|
||||
@export var speed = 400 # How fast the virus will move (pixels/sec).
|
||||
@export var attack_range = 200 # virus vision radius (pixels)
|
||||
@export var speed = 200 # How fast the virus will move (pixels/sec).
|
||||
@export var attack_range = 1000 # virus vision radius (pixels)
|
||||
|
||||
# a virus is instantiated as Spawning and transitions (matures) into Spawned
|
||||
# after a timer timeout, after which it is activated and ready to do its thing.
|
||||
@@ -13,7 +13,8 @@ enum ActionState {Blocked, Waiting, Running}
|
||||
var spawning_state
|
||||
var action_state
|
||||
|
||||
var targets = [] # who the virus will attack
|
||||
# temp 0 because of if len == 0 in process
|
||||
var targets = [0] # who the virus will attack
|
||||
|
||||
func _ready():
|
||||
self.spawning_state = SpawningState.Spawning
|
||||
@@ -27,15 +28,9 @@ func _process(delta):
|
||||
return # do nothing if no set targets
|
||||
|
||||
# --- determine nearest target
|
||||
var nearest_target = self.targets[0]
|
||||
var shortest_distance = 0
|
||||
for i in range(1, self.targets.size()):
|
||||
var target = self.targets[i]
|
||||
var distance = self.position.distance_to(target)
|
||||
if distance < shortest_distance:
|
||||
shortest_distance = distance
|
||||
nearest_target = target
|
||||
|
||||
var nearest_target = get_node("../../Player").position
|
||||
var shortest_distance = nearest_target.distance_to(self.position)
|
||||
|
||||
# --- attack the nearest target, if within range
|
||||
if self.action_state != ActionState.Blocked:
|
||||
if shortest_distance < self.attack_range:
|
||||
|
||||
18
growth/virus_spawner.gd
Normal file
18
growth/virus_spawner.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
extends Node
|
||||
|
||||
@export var Virus : PackedScene
|
||||
@export var spawn_distance = 1000
|
||||
|
||||
var player
|
||||
|
||||
func _ready():
|
||||
self.player = get_node("../Player")
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_timer_timeout():
|
||||
var virus = Virus.instantiate()
|
||||
var direction = Vector2.RIGHT.rotated(randf_range(0, 2*PI))
|
||||
virus.position = player.position + direction * spawn_distance
|
||||
add_child(virus)
|
||||
1
growth/virus_spawner.gd.uid
Normal file
1
growth/virus_spawner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dycpk6lxabn1l
|
||||
Reference in New Issue
Block a user