Skip to content

Commit

Permalink
spawner by level
Browse files Browse the repository at this point in the history
  • Loading branch information
ricargoes committed Feb 18, 2024
1 parent 8d43067 commit 49d1b07
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions scenes/enemies/spawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ class_name Spawner extends Marker2D
@export
var spawning_resource: PoolManager.PoolResource = PoolManager.PoolResource.FLYING_ENEMY
@export
var spawning_frequency: float = 2.0
var spawning_frequency_by_level: Dictionary = {
1: 2.0,
2: 4.0,
3: 6.0,
4: 8.0,
5: 10.0
}
@export
var lifetime: float = 1.0
@export
Expand All @@ -22,7 +28,9 @@ func _process(delta: float) -> void:
position += velocity*delta

func enable(_by_who = null):
$SpawningCooldown.start(1.0/spawning_frequency)
var game = get_tree().current_scene

$SpawningCooldown.start(1.0/spawning_frequency_by_level[game.difficulty_level])
if lifetime > 0:
$Lifetime.start(lifetime)
velocity = Vector2.ZERO if destination == null else (destination.global_position - global_position)/lifetime
Expand Down
3 changes: 3 additions & 0 deletions scenes/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const TERRAINS_SCENES = [
preload("res://scenes/terrain/terrain_chunk_4.tscn"),
]
var last_terrain_position := Vector2.ZERO
var difficulty_level: int = 1

func _ready() -> void:
$SunsetAnimator.speed_scale = ANIMATION_BASE_RUNTIME/run_time
Expand All @@ -27,6 +28,8 @@ func _process(_delta: float) -> void:
if $Hero.position.x - terrain_chunk.position.x > 2*TERRAIN_CHUNK_LENGTH:
terrain_chunk.queue_free()

difficulty_level = min(6 - ceil($SunsetTime.time_left/$SunsetTime.wait_time*100/20), 5)

func spawn_bullet(starting_position: Vector2, orientation: float, is_player: bool, lifetime: float = 1):
var bullet = PoolManager.get_instance(PoolManager.PoolResource.BULLET)
bullet.global_position = starting_position
Expand Down
2 changes: 2 additions & 0 deletions scenes/global/pool_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ enum PoolResource {
BULLET,
BASIC_ENEMY,
FLYING_ENEMY,
BIKER_ENEMY,
}

const resources_scenes = {
PoolResource.BULLET: preload("res://scenes/bullet.tscn"),
PoolResource.BASIC_ENEMY: preload("res://scenes/enemies/enermy.tscn"),
PoolResource.FLYING_ENEMY: preload("res://scenes/enemies/flying_enemy.tscn"),
PoolResource.BIKER_ENEMY: preload("res://scenes/enemies/enemy_biker.tscn"),
}

var pool: Dictionary = {}
Expand Down
5 changes: 0 additions & 5 deletions scenes/terrain/terrain_chunk_1.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ size = Vector2(1054.5, 49.5)

[node name="Spawner1" parent="Enemies" index="0" node_paths=PackedStringArray("destination", "activator") instance=ExtResource("3_eakqu")]
position = Vector2(3575, 81)
spawning_frequency = 4.0
destination = NodePath("../../Helpers/Dest1")
activator = NodePath("../../Helpers/Activator")

[node name="Spawner2" parent="Enemies" index="1" node_paths=PackedStringArray("destination", "activator") instance=ExtResource("3_eakqu")]
position = Vector2(4326, 327)
spawning_resource = 1
spawning_frequency = 4.0
destination = NodePath("../../Helpers/Dest2")
activator = NodePath("../../Helpers/Activator")

Expand All @@ -59,15 +57,12 @@ position = Vector2(2515, 729)

[node name="EnemyBiker" parent="Enemies" index="7" instance=ExtResource("4_l4pkk")]
position = Vector2(153, 547)
speed = 800.0

[node name="EnemyBiker2" parent="Enemies" index="8" instance=ExtResource("4_l4pkk")]
position = Vector2(301, 547)
speed = 800.0

[node name="EnemyBiker3" parent="Enemies" index="9" instance=ExtResource("4_l4pkk")]
position = Vector2(64, 543)
speed = 800.0

[node name="Dest1" type="Marker2D" parent="Helpers" index="0"]
position = Vector2(3594, 795)
Expand Down

0 comments on commit 49d1b07

Please sign in to comment.