Update bunny spawning
This commit is contained in:
parent
b7811cebea
commit
128abc60b8
5 changed files with 24 additions and 9 deletions
|
@ -6,7 +6,6 @@
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_sedmr"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_sedmr"]
|
||||||
|
|
||||||
[node name="Bunny" type="CharacterBody2D"]
|
[node name="Bunny" type="CharacterBody2D"]
|
||||||
scale = Vector2(0.5, 0.5)
|
|
||||||
collision_layer = 4
|
collision_layer = 4
|
||||||
collision_mask = 11
|
collision_mask = 11
|
||||||
script = ExtResource("1_1kj2b")
|
script = ExtResource("1_1kj2b")
|
||||||
|
|
|
@ -8,7 +8,6 @@ radius = 8.57143
|
||||||
height = 22.8571
|
height = 22.8571
|
||||||
|
|
||||||
[node name="Projectile" type="Area2D"]
|
[node name="Projectile" type="Area2D"]
|
||||||
scale = Vector2(0.5, 0.5)
|
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
collision_mask = 5
|
collision_mask = 5
|
||||||
script = ExtResource("1_os652")
|
script = ExtResource("1_os652")
|
||||||
|
|
|
@ -128,9 +128,10 @@ format = 2
|
||||||
script = ExtResource("2_yhpwh")
|
script = ExtResource("2_yhpwh")
|
||||||
start_area_corner_size = 3
|
start_area_corner_size = 3
|
||||||
|
|
||||||
[node name="Bunny Generator" type="Node" parent="."]
|
[node name="Bunny Generator" type="Node" parent="." node_paths=PackedStringArray("player")]
|
||||||
script = ExtResource("3_dvklj")
|
script = ExtResource("3_dvklj")
|
||||||
bunny_prefab = ExtResource("4_0fyd5")
|
bunny_prefab = ExtResource("4_0fyd5")
|
||||||
|
player = NodePath("../Player")
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
|
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
|
||||||
position = Vector2(1440, 810)
|
position = Vector2(1440, 810)
|
||||||
|
|
|
@ -1,17 +1,32 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
@export var bunny_prefab : Resource
|
@export var bunny_prefab : Resource
|
||||||
|
@export var player : CharacterBody2D
|
||||||
|
@export var player_save_distance : float = 32.0
|
||||||
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
||||||
|
|
||||||
func spawn_bunny(x : float, y : float, team : int, health : int) -> Bunny:
|
func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
|
||||||
var bunny = BunnyPrefab.instantiate()
|
var bunny = BunnyPrefab.instantiate()
|
||||||
self.add_child(bunny)
|
self.add_child(bunny)
|
||||||
bunny.global_position = Vector2(x,y)
|
bunny.global_position = pos
|
||||||
bunny.health = health
|
bunny.health = health
|
||||||
bunny.team = team
|
bunny.team = team
|
||||||
return bunny
|
return bunny
|
||||||
|
|
||||||
func _ready():
|
func spawn_wave(free_tiles : Array, amount : int, health : int):
|
||||||
var bunny = spawn_bunny(960, 512, TEAM.EVIL, 3)
|
|
||||||
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
|
||||||
|
|
||||||
|
# Make Sure that no possitions to near to the player are insdie of the list
|
||||||
|
for tile in free_tiles:
|
||||||
|
if tile.distance_to(player.global_position) <= player_save_distance:
|
||||||
|
free_tiles.erase(tile)
|
||||||
|
|
||||||
|
# Make sure amount isnt bigger then available positions
|
||||||
|
if free_tiles.size() < amount: amount = free_tiles.size()
|
||||||
|
|
||||||
|
# Spawn at random psoitions of the list
|
||||||
|
for i in amount:
|
||||||
|
var pos = free_tiles.pick_random()
|
||||||
|
free_tiles.erase(pos)
|
||||||
|
var bunny = spawn_bunny(pos, TEAM.EVIL, 3)
|
||||||
|
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
||||||
|
pass
|
||||||
|
|
|
@ -18,7 +18,6 @@ var tile_array : Array
|
||||||
func _ready():
|
func _ready():
|
||||||
var time = generate()
|
var time = generate()
|
||||||
print("time for generation: " + str(time))
|
print("time for generation: " + str(time))
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +38,8 @@ func generate() -> float:
|
||||||
set_borders_solid()
|
set_borders_solid()
|
||||||
|
|
||||||
tile_array_to_terrain()
|
tile_array_to_terrain()
|
||||||
|
|
||||||
|
|
||||||
return Time.get_unix_time_from_system() - start_time
|
return Time.get_unix_time_from_system() - start_time
|
||||||
|
|
||||||
func setup_tile_data_array():
|
func setup_tile_data_array():
|
||||||
|
|
Reference in a new issue