From 1e2ef59d5ee4de0c02c86b09064bda22e8e4e896 Mon Sep 17 00:00:00 2001 From: Maxime FRANCK Date: Sun, 15 Nov 2020 16:36:18 +0100 Subject: [PATCH] Avoid signal lost in case of project oppening without compiled library Resolves #4 --- 2d/dodge_the_creeps/Main.tscn | 2 -- 2d/dodge_the_creeps/pkg/dtc/main.go | 15 +++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/2d/dodge_the_creeps/Main.tscn b/2d/dodge_the_creeps/Main.tscn index 468ad57..71b54db 100644 --- a/2d/dodge_the_creeps/Main.tscn +++ b/2d/dodge_the_creeps/Main.tscn @@ -54,8 +54,6 @@ stream = ExtResource( 5 ) [node name="DeathSound" type="AudioStreamPlayer" parent="."] stream = ExtResource( 6 ) -[connection signal="hit" from="Player" to="." method="game_over"] [connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"] [connection signal="timeout" from="ScoreTimer" to="." method="_on_ScoreTimer_timeout"] [connection signal="timeout" from="StartTimer" to="." method="_on_StartTimer_timeout"] -[connection signal="start_game" from="HUD" to="." method="new_game"] diff --git a/2d/dodge_the_creeps/pkg/dtc/main.go b/2d/dodge_the_creeps/pkg/dtc/main.go index e0f05f1..95908ba 100644 --- a/2d/dodge_the_creeps/pkg/dtc/main.go +++ b/2d/dodge_the_creeps/pkg/dtc/main.go @@ -37,6 +37,15 @@ func (p *Main) OnClassRegistered(e gdnative.ClassRegisteredEvent) { func (p *Main) Ready() { rng.Randomize() + + binds := gdnative.NewArray() + defer binds.Destroy() + + hud := NewHUDWithOwner(p.FindNode("HUD", true, true).GetOwnerObject()) + hud.Connect("start_game", p, "new_game", binds, 0) + + player := NewPlayerWithOwner(p.FindNode("Player", true, true).GetOwnerObject()) + player.Connect("hit", p, "game_over", binds, 0) } func (p *Main) GameOver() { @@ -50,7 +59,6 @@ func (p *Main) GameOver() { gdnative.NewAudioStreamPlayerWithOwner(p.FindNode("DeathSound", true, true).GetOwnerObject()).Play(0.0) } - func (p *Main) NewGame() { p.score = 0 pos := gdnative.NewPosition2DWithOwner(p.FindNode("StartPosition", true, true).GetOwnerObject()).GetPosition() @@ -63,7 +71,6 @@ func (p *Main) NewGame() { gdnative.NewAudioStreamPlayerWithOwner(p.FindNode("Music", true, true).GetOwnerObject()).Play(0.0) } - func (p *Main) OnMobTimerTimeout() { mobSpawnLocationNodePath := gdnative.NewNodePath("MobPath/MobSpawnLocation") mobSpawnLocation := gdnative.NewPathFollow2DWithOwner(p.GetNode(mobSpawnLocationNodePath).GetOwnerObject()) @@ -82,11 +89,11 @@ func (p *Main) OnMobTimerTimeout() { tau := float32(math.Pi * 2) - direction := mobSpawnLocation.GetRotation() + tau / 4 + direction := mobSpawnLocation.GetRotation() + tau/4 mob.SetPosition(mobSpawnLocation.GetPosition()) - direction += randRange(-tau / 8, tau / 8) + direction += randRange(-tau/8, tau/8) mob.SetRotation(direction)