Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porblem with Tutorial #19

Open
Bl4nkPixel opened this issue May 21, 2021 · 3 comments
Open

Porblem with Tutorial #19

Bl4nkPixel opened this issue May 21, 2021 · 3 comments

Comments

@Bl4nkPixel
Copy link

Bl4nkPixel commented May 21, 2021

I did everything equal to your programm. yours working, my isnt working. The last thing what i need to implement is the music all other i finisched but my Enemies didnt spawn i cant find the issue.

Hope u can look over it.

Main:

extends Node

export (PackedScene) var Mob
var score

func _ready():
randomize()

func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
#get_tree().call_group("mobs", "queue_free")

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

func _on_MobTimer_timeout():
$MobPath/MobSpawnLocation.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.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = mob.linear_velocity.rotated(direction)

func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()

func _on_ScoreTimer_timeout():
score += 1
$HUD.update_score(score)

Player:

extends Area2D

signal hit

export var speed = 400
var screen_size #size of the game window

func _ready():
screen_size = get_viewport_rect().size
hide()

func _process(delta):
var velocity = Vector2() #The players movment
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if velocity.length() >0:
velocity = velocity.normalized() * speed
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()

position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)

if velocity.x != 0:
$AnimatedSprite.animation = "Walk"
$AnimatedSprite.flip_v = false
# See the note below about boolean assignment
$AnimatedSprite.flip_h = velocity.x < 0
elif velocity.y != 0:
$AnimatedSprite.animation = "up"
$AnimatedSprite.flip_v = velocity.y > 0

func _on_Player_body_entered(body):
hide()
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)

func start(pos):
position = pos
show()
$CollisionShape2D.disabled = false

Mob:

extends RigidBody2D

export var min_speed = 150 # Minimum speed range.
export var max_speed = 250 # Maximum speed range.

func _ready():
var mob_types = $AnimatedSprite.frames.get_animation_names()
$AnimatedSprite.animation = mob_types[randi() % mob_types.size()]

func _on_VisibilityNotifier2D_screen_exited():
queue_free()

HUD:

extends CanvasLayer

signal start_game

func show_message(text):
$Message.text = text
$Message.show()
$MessageTimer.start()

func show_game_over():
show_message("Game Over")
# Wait until the MessageTimer has counted down.
yield($MessageTimer, "timeout")
$Message.text = "Dodge the\nCreeps!"
$Message.show()
yield(get_tree().create_timer(1), "timeout")
$StartButton.show()

func update_score(score):
$ScoreLabel.text = str(score)

func _on_StartButton_pressed():
$StartButton.hide()
emit_signal("start_game")

func _on_MessageTimer_timeout():
$Message.hide()

Main:
grafik

Player:
grafik

Mob:
grafik

HUD:
grafik

@Uradamus
Copy link

Uradamus commented Sep 9, 2021

I'm having a similar issue. Though I stopped at the point where the hud is implemented, since the game fails to spawn enemies at that point where it says to test it out. One thing I noticed over the last few hours of trying to figure out why it might not be working is that I can't use the documentation lookup shortcut on the following line.
var mob = Mob.instance()

In fact, while typing it out, I wasn't offered any sort of autocomplete, which was also strange. Makes me think something has changed since this tutorial was made in regards to either how PackedScenes are handled, or at least the way they should be instanced.

This is really frustrating though, as I've rechecked all the code so far in all the scripts and the node layouts dozens of times and nothing looks out of place and there are no errors, beyond the following warning.
`W 0:00:01.075 The argument 'body' is never used in the function '_on_Player_body_entered'. If this is intended, prefix it with an underscore: '_body'
<C++ Error> UNUSED_ARGUMENT

Player.gd:45`

Which I assume is just down to something not being covered yet at this point in the tutorial, and since it is in relation to the Player, which is working just fine, it seems unrelated.

@Uradamus
Copy link

Uradamus commented Sep 9, 2021

As a minor update, I found myself looking into the Godot demo repo to see what was going on with that version, and I see there have been several changes to the Main.gd over there, and I tried all the relevant changes to the mob spawning portions, but they don't seem to make any difference. Still not seeing any mobs spawn.

Oh well, throwing in the towel on this one as a lost cause for now, and going to look for other tutorials instead until this is straightened out. I've spent too many hours at this point to be worth continuing until the tutorial is updated to something that properly works every step of the way. It's a real shame too, as this looked really promising and informative, but no use if it isn't going to run as presented in the tutorial.

Getting this fixed should be a priority, considering how the tutorial is so prominently positioned as a "Your First Game" tutorial on the official documentation site. Making it something that is likely to negatively impact a fairly large portion of the new user base coming to the engine for the first time. And it was promoted as one of the better starter tutorials by Terry Cavanagh in the intro page for his recent Stop Waiting for Godot game jam, which was what actually brought this tutorial to my attention (even though I only heard about the jam after it ended >.<).

I took a break from the engine for a while, and was just looking for some quick refreshers to get back up to speed. I thought I'd be done with the tutorial within an hour or two, but that has ballooned into 5+ hours now and still don't have a working game out of it. So it has been a real disappointment, and I'd hate for something similar happening to those just testing the waters and being turned off by the engine over it, especially with this being an official tutorial.

@theotherjasonrainbird
Copy link

I've just gone through the same frustrating experience as @Uradamus above.

After having carefully entered everything on the tutorial I saw had made a mistake with the collision code, so I came to this repo to double check what I had entered.

Only by entirely cloning the repo did I finally get something working, and even then what's in master isn't identical to what's in the tutorial (the Enter shortcut to start the game is missing).

This has been an off-putting experience and is not a welcome introduction to Godot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants