Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | System_Error |
Hi all, I had a little question I’ve been thinking over for a day now.
In my game, I have the main scene. in it, I’m instancing a Particles2D, and I want to be able to toggle it on and off with the signals emitted for pressing the “Play” button, and when an enemy enters a certain area.
Level.gd
extends Node2D
const SCREEN_HEIGHT = 580
const SCREEN_WIDTH = 1010
signal game_over
var timescore
var kills
var finalscore
var EnergyShot = preload ('res://player-side/EnergyShot.tscn')
var eyeworm = preload ('res://Enemy.tscn')
var SpawnWaitTime = 5
var highscore = 0.0
func _ready():
randomize()
func _on_SpawnTimer_timeout():
var enemy = eyeworm.instance()
enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
enemy.connect("kill", self, "_on_kill")
add_child(enemy)
SpawnWaitTime -= 0.15
if (SpawnWaitTime < 0.4):
SpawnWaitTime += 4.85
$Node/SpawnTimer.set_wait_time(SpawnWaitTime)
func _on_SurvivalTimer_timeout():
timescore += 1
$HUD.score_count(timescore)
func _on_kill():
kills += 1
$HUD.kill_count(kills)
func _on_BaseArea_area_entered(area):
$Node/SpawnTimer.stop()
$Node/SurvivalTimer.stop()
finalscore = timescore + kills*5
if highscore < finalscore:
highscore = finalscore
$HUD.player_loss(finalscore, highscore)
emit_signal('game_over')
$BaseArea/CollisionShape2D.disabled = true
get_tree().call_group("EyeWorms", "queue_free")
func _on_HUD_play_game():
timescore = 0
kills = 0
SpawnWaitTime = 5
finalscore = 0
$Node/SurvivalTimer.start()
$Node/SpawnTimer.start()
$HUD.show_message("Survive!")
$BaseArea/CollisionShape2D.disabled = false
func _on_HUD_credits():
get_tree().change_scene("Credits.tscn")
HUD.gd
extends CanvasLayer
signal play_game
signal credits
func show_message(text):
$SystemMessage.text = text
$SystemMessage.show()
$MessageDuration.start()
func _on_MessageDuration_timeout():
$SystemMessage.hide()
func player_loss(finalscore, highscore):
show_message("Game Over")
yield($MessageDuration, "timeout")
$Interactive/PlayButton.show()
$SystemMessage.text = "Play Again?"
$SystemMessage.show()
$HighScore.show()
$CurrentScore.show()
$HighScore.text = str(highscore)
$CurrentScore.text = str(finalscore)
$Interactive/HelpButton.show()
$Interactive/CreditsButton.show()
func score_count(score):
$TimeSurvived.text = str(score)
func kill_count(count):
$Kills.text = str(count)
func _on_Button_pressed():
$Interactive/PlayButton.hide()
$Interactive/HelpButton.hide()
$Interactive/CreditsButton.hide()
$CurrentScore.hide()
$TimeSurvived.text = str("0")
$Kills.text = str("0")
emit_signal('play_game')
func _on_HelpButton_pressed():
$Help/ShowHelpDuration.start()
$Help/Worm.show()
$Help/HelpLabel1.show()
$Help/HelpLabel2.show()
$Help/HelpLabel3.show()
$Help/HelpLabel4.show()
$Help/HelpLabel5.show()
$HelpfulLabel.show()
$SystemMessage.hide()
$Interactive/PlayButton.hide()
yield($Help/ShowHelpDuration, "timeout")
$Help/Worm.hide()
$Help/HelpLabel1.hide()
$Help/HelpLabel2.hide()
$Help/HelpLabel3.hide()
$Help/HelpLabel4.hide()
$Help/HelpLabel5.hide()
$HelpfulLabel.hide()
$SystemMessage.show()
$Interactive/PlayButton.show()
func _on_CreditsButton_pressed():
emit_signal("credits")
func _on_HUD_credits():
get_tree().change_scene("Credits.tscn")
Thruster.gd (This is the Particles2D node)
extends Particles2D
var playing = false