0 votes

I have completed most of the dodge the creeps game, to the point where it is playable. However, there are two problems. First of all, the creeps don't play their animation and stay the same, even though i put in all of the frames for all the animations. Secondly, when i die the creeps keep spawning and the score keeps counting. I suspect it is because the Game_Over function in Main doesn't get called since it controls both those things when it triggers, but idk where the problem could be. Here is the main code if it helps:

extends Node

export (PackedScene) var Mob
var score

func _ready():
    randomize()

func new_game():
    score = 0;
    $Player.start($StartPosition.position)
    $StartTimer.start()
    $HUD.show_message("Get Ready")
    $HUD.update_score(score)

func _on_StartTimer_timeout():
    $MobTimer.start()
    $ScoreTimer.start()
    $HUD.update_score(score)

func Game_Over():
    $ScoreTimer.stop();
    $MobTimer.stop();
    $HUD.Game_Over()

func _on_ScoreTimer_timeout():
    score += 1


func _on_MobTimer_timeout():
    $MobPath/MobSpawnLocation.set_offset(randi())
    var mob = Mob.instance()
    add_child(mob)
    var direction = $MobPath/MobSpawnLocation.rotation+PI/2
    mob.position = $MobPath/MobSpawnLocation.position
    direction += rand_range(-PI/4, PI/4)
    mob.rotation = direction
    mob.set_linear_velocity(Vector2(rand_range(mob.MIN_SPEED, mob.MAX_SPEED), 0).rotated(direction))

edit: i have solved the problem with the animation. I forgot to check the "play" box. I still need help with the second problem. If you need any more information, leave a comment asking for it.

in Engine by (243 points)
edited by

I see you have a HUD method called GameOver() as well as a Main method called GameOver(). Perhaps you are accidentally calling the HUD method when you should be calling the Main method.

The Game_Over function is triggered whenever the player is hit via a signal. Nothing else connects to it. Even if i lowercase it and redo the connection to it, it still does the same thing.

2 Answers

0 votes

The Game_Over() function (I would point out here that you're being inconsistent with your capitalization) is called by the player's hit signal. It seems you're not correctly connecting it. When you click connect on the signal and you type in the name of the target method, make sure you're not using ().

You can also make the connection in code by putting this in the Main.gd's _ready():

$Player.connect('hit', self, 'Game_Over')

Make sure the spelling/capitalization of the function matches.

by (20,923 points)

I'm pretty sure i'm calling the function correctly since the HUD comes up for it. I'll try the .connect method though

0 votes

Hi,

Maybe is late, but I have the same problem with my game and after a few hours I get the answer.

You have to check the "One Shot" box of start timer you use in the project. I expect this solution works for you.

Greetings!

by (14 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.