0 votes

Hi all. I have an idea, but I'm not sure how to go about it.

In my game, I have a score-keeping Label & Timer duo for keeping track of how long a player has survived. I also have a timer for spawning enemies.

func _on_SpawnTimer_timeout():
var enemy = eyeworm.instance()
enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
add_child(enemy)

func _on_SurvivalTimer_timeout():
    score += 1
    $HUD.score_count(score)

How would I make the enemies spawn more and more often as time goes on?

in Engine by (197 points)

Here's the whole of Level.gd, for those who want to see.

extends Node2D

const SCREEN_HEIGHT = 580
const SCREEN_WIDTH = 1010

signal game_over
var score
var finalscore
var EnergyShot = preload ('res://player-side/EnergyShot.tscn')
var eyeworm = preload ('res://Enemy.tscn')

func _ready():
    randomize()


func _on_SpawnTimer_timeout():
    var enemy = eyeworm.instance()
    enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
    add_child(enemy)

func _on_SurvivalTimer_timeout():
    score += 1
    $HUD.score_count(score)


func _on_BaseArea_area_entered(area):
    $Node/SpawnTimer.stop()
    $Node/SurvivalTimer.stop()
    $HUD.player_loss() 
    emit_signal('game_over')
    $BaseArea/CollisionShape2D.disabled = true
    get_tree().call_group("EyeWorms", "queue_free")


func _on_HUD_play_game():
    score = 0
    $Node/SurvivalTimer.start()
    $Node/SpawnTimer.start() 
    $HUD.show_message("Survive!")
    $BaseArea/CollisionShape2D.disabled = false

1 Answer

+1 vote

You could have a SpawnWaitTime variable that decrease every time a new enemy is spawned, something like this(i guess that SpawnTimer is a Timer node):

...
var SpawnWaitTime=10

...

func _on_SpawnTimer_timeout():
    var enemy = eyeworm.instance()
    enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
    add_child(enemy)
    SpawnWaitTime-=0.1
    if(SpawnWaitTime<0.1): 
        SpawnWaitTime=0.1
    SpawnTimer.set_wait_time(SpawnWaitTime)
by (198 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.