diff --git a/Prefabs/bunny.tscn b/Prefabs/bunny.tscn index 38a08f2..c4dbdfd 100644 --- a/Prefabs/bunny.tscn +++ b/Prefabs/bunny.tscn @@ -6,7 +6,6 @@ [sub_resource type="CircleShape2D" id="CircleShape2D_sedmr"] [node name="Bunny" type="CharacterBody2D"] -scale = Vector2(0.5, 0.5) collision_layer = 4 collision_mask = 11 script = ExtResource("1_1kj2b") diff --git a/Prefabs/projectile.tscn b/Prefabs/projectile.tscn index ad78eed..350abc7 100644 --- a/Prefabs/projectile.tscn +++ b/Prefabs/projectile.tscn @@ -8,7 +8,6 @@ radius = 8.57143 height = 22.8571 [node name="Projectile" type="Area2D"] -scale = Vector2(0.5, 0.5) collision_layer = 8 collision_mask = 5 script = ExtResource("1_os652") diff --git a/Scenes/Test.tscn b/Scenes/Test.tscn index aec238c..00e5ba5 100644 --- a/Scenes/Test.tscn +++ b/Scenes/Test.tscn @@ -128,9 +128,10 @@ format = 2 script = ExtResource("2_yhpwh") 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") bunny_prefab = ExtResource("4_0fyd5") +player = NodePath("../Player") [node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")] position = Vector2(1440, 810) diff --git a/Scripts/EntitySystem/BunnyGenerator.gd b/Scripts/EntitySystem/BunnyGenerator.gd index 71bcc9f..a91dc51 100644 --- a/Scripts/EntitySystem/BunnyGenerator.gd +++ b/Scripts/EntitySystem/BunnyGenerator.gd @@ -1,17 +1,32 @@ extends Node @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) -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() self.add_child(bunny) - bunny.global_position = Vector2(x,y) + bunny.global_position = pos bunny.health = health bunny.team = team return bunny + +func spawn_wave(free_tiles : Array, amount : int, health : int): -func _ready(): - 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 diff --git a/Scripts/MapGenerator.gd b/Scripts/MapGenerator.gd index d93c357..dcfda61 100644 --- a/Scripts/MapGenerator.gd +++ b/Scripts/MapGenerator.gd @@ -18,7 +18,6 @@ var tile_array : Array func _ready(): var time = generate() print("time for generation: " + str(time)) - pass @@ -39,6 +38,8 @@ func generate() -> float: set_borders_solid() tile_array_to_terrain() + + return Time.get_unix_time_from_system() - start_time func setup_tile_data_array():