Space Rocks! Godot Tutorial Part 9

KidsCanCode · Beginner ·🛠️ AI Tools & Apps ·9y ago

Key Takeaways

Develops a version of the classic game Asteroids using Godot Game Engine

Full Transcript

welcome back this is part 9 of space rocks the video engine game tutorial where we make a full asteroid style game this time we're gonna deal with what happens when the player dies we have them explode we're gonna restart the game and along the way we're gonna find a little bug in the Godot game engine alright let's get started alright the first thing I want to do is I want to deal with a little bug that crept in last time which is when we're playing if we hit pause when we come back from the pause the wave message is back and kind of won't go away so we don't want that and the reason for that is we look over at our script when the message timer times out we just hide the message well when we show a message we set the text to whatever that is so when we need to hide the message we're gonna just also set the text to blank that way whenever we come back if there's no message to come back to then we come back to no message okay so what we want to do now is we want to start setting up the ability to switch between scenes and when the game starts I'm gonna want some kind of title screen we're gonna want to be able to go to our main scene obviously we're gonna have a game over screen probably I want to have some sort of shop window where you can upgrade your ship and things like that so we're gonna have different scenes that we're gonna want to change between and so what I'm gonna do is I'm going to go here to the global and I'm gonna start setting up some variables for that so the game is gonna be running and there's going to be a current scene current scene that is what we're whatever scene we're looking at and then we're gonna have a new scene that's the one that we're switching to so let's go down here and add some functions so in our ready function this is where we're going to set our first scene right so we're just going to get whatever scene we're starting on so that's good tree get root and I'm going to set the root I'm gonna set the current scene to get child get child count minus one and so what that does is it's gonna set start current scene equal to the scene that we have set to the main scene in our in our project settings so when we hit run so right now if we ran this current scene will be equal to main because that's the one we have launching it's the one that's going to be right under the tree root alright and then we're going to have a I'm going to make a function called go to scene and this is I'm doing this in global so that any in any scene we can just go to another scene so we're gonna we're gonna reload we're gonna use the resource loader to load this resource loader lot load F so we're going to pass in the path of the scene that we want to switch to so new scene will be set equal to that an instance of that and then we need to add it to the chart as a child to the tree because it's going to become the new current scene so we need to add it to the tree so we need to get get root and add that as a child the new scene okay so the new scene gets added now that it's added we can use set current scene to make that new scene the current scene well now I can free I can free whatever I'm currently having as the current scene at set current scene is equal to new zine okay so the flow here is that when we whenever we call go to scene for a new you seen we load that scene make an instance of it stick it into the root of the tree and set it as the current scene then we get rid of the old current scene and the new one becomes the current so now one more function here so whenever we want to start a new game well when we start a new game we need to grab these things these things we're gonna set when the new game happens and then we're also going to and we're gonna go to the main scene right so I'll just go over here and grab the path and we can paste that in there and now from our main whenever the player dies or from our game over screen when they click restart or whatever we'll just call this new game function and it will reset everything and start us on the main scene so in our main right now what we're missing is the player just doesn't actually die so on the player right here if the shield is up we are just reducing the shield right now now what we want to do is we want to explode the player and we can do that by emitting a signal so we're gonna add a signal up here for our player called explode and down here at the bottom if something enters there something hits the player when their shield is down then we're going to admit that signal and I'm gonna get rid of this so we can do that elsewhere okay so we omit the explode signal and now over here in the main we're gonna want to do something with that so first of all in our ready and our ready we're going to take the player and connect the explode signal to a function ourselves called explode explode player and that's going to make an explosion and all the nice stuff we want to happen when the player dies so we need another explosion right now we have this explosion but what we can do is go in here and add another one you can call this the sonic explosion because that's what it's called in the art folder just go down here at the bottom here's the sonic explosion it has a ring that comes out from it looks a little more a little bit more striking than the basic explosion this is the one that we're gonna want to run when the player dies I think we want somewhere around 12 FPS it does not loop okay so just like this one yeah we're gonna run this explosion when the player dies so back to our main script we're going to make this function so let's just go down so let's just go down to the end it's blood player what do we want to do well we need to hide the player right in fact we need to more than just hide the player we want it to stop running into things and everything so we actually want to disable the player so we're going to add that onto the player script what do you do when you're disabled and then we need to make an explosion explosion instance we can add that as a child and we can set the pause and actually we're really just doing all of this except we also want to say set animation to Sonic play it we're gonna play and we'll probably want to play a different sound we'll get to that one and then we're also going to on the HUD we're going to show the message game over okay so let's go back over to global and I'm gonna set the players shield max to ten so that they'll die quickly and then when we run this what do we got here all right when we explode the player we want to set the explosion to player pause okay and then when you're gonna have to add on our disabled just realize we forgot that as well so on the player well what does player disabled do well it's gonna hide the player it's gonna set process to false so that we no longer move around or pay attention to inputs and then we're also going to set enable monitoring to false otherwise we'll still detect things entering the area and we'll see you know asteroids explode when they enter in empty space because the player is hidden so we want to just disable all those things so let's go and run into some asteroids game over okay now that explosion was a little small I think I might scale it up a little bit but let's take a look one more time get a couple small ones to just knock off my yeah so I think what we'll do is when we run the sonic explosion we're gonna scale it up just a little bit just that much let's see how that looks yeah have a look at this I'm gonna blow up now my player is still around this area so let's see when I yeah see that the meteor still hit or the asteroids still hit even though I'm supposedly set enable monitoring to false well turns out this doesn't work it does work if you have it in ready for example here right if I set enable monitoring to false when the game starts then you know my then my meteor Maitai remind my ship is not going to detect collisions but it does not work when called later on in a function so this is a problem and from looking on github this may be just a bug that we're gonna have to deal with so for now what I'm going to do is just say if is hidden so it's gonna detect the body enter but it's just basically gonna do nothing okay let's finish this up so we are showing the game over a message we don't want to restart immediately or else we're gonna you know run out of time or we're not going to have time to see the game over before the game instantly restarts so we're gonna stick a little another timer in here and this is going to be the restart restart timer and it is a one shot let's try three seconds and see how it goes and we're going to say when the player explodes we show came over and we take the restart timer and we start it and then we're going to connect that restart timers timeout and what is that gonna do we're gonna say global new game alright so we added global new game and it goes to the main scene which starts everything all over again yes so let's run this and see what happens game over restarts okay that's good enough for now until we have title screens and start buttons and everything like that so I think that'll do it for this video as always thanks so much for watching please like and subscribe and I'll see you next time you

Original Description

This is a complete end-to-end game development tutorial using the Godot Game Engine. We're going to be making a version of the classic game "Asteroids". We're making it as we go, so there will be bugs, mistakes, etc. - but this is how real development works, exploring possible solutions, refactoring (this means going back and changing code you already wrote). I hope you enjoy it and learn something. Code for each part can be found here: https://github.com/kidscancode/godot_tutorials/tree/master/Space_Rocks_tutorial
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from KidsCanCode · KidsCanCode · 0 of 60

← Previous Next →
1 Learning to Code with Python: Lesson 1.1 - What is Programming?
Learning to Code with Python: Lesson 1.1 - What is Programming?
KidsCanCode
2 Learning to Code with Python: Lesson 1.2 - Drawing with Turtles
Learning to Code with Python: Lesson 1.2 - Drawing with Turtles
KidsCanCode
3 Learning to Code with Python: Lesson 1.3 - Variables
Learning to Code with Python: Lesson 1.3 - Variables
KidsCanCode
4 Learning to Code with Python: Lesson 1.4 - Loops (and more turtles!)
Learning to Code with Python: Lesson 1.4 - Loops (and more turtles!)
KidsCanCode
5 Learning to Code with Python: Lesson 1.5 - Saving and Running Programs
Learning to Code with Python: Lesson 1.5 - Saving and Running Programs
KidsCanCode
6 Learning to Code with Python: Lesson 1.6 - Functions
Learning to Code with Python: Lesson 1.6 - Functions
KidsCanCode
7 Learning to Code with Python: Lesson 1.7 - Input and Conditional Statements
Learning to Code with Python: Lesson 1.7 - Input and Conditional Statements
KidsCanCode
8 Learning to Code with Python: Lesson 1.8 - Number Guessing Game
Learning to Code with Python: Lesson 1.8 - Number Guessing Game
KidsCanCode
9 KidsCanCode - Patreon Intro Video
KidsCanCode - Patreon Intro Video
KidsCanCode
10 Learning to Code with Python: Lesson 1.9 - Rock Paper Scissors Game
Learning to Code with Python: Lesson 1.9 - Rock Paper Scissors Game
KidsCanCode
11 Learning to Code with Python: Lesson 1.10 - Secret Codes
Learning to Code with Python: Lesson 1.10 - Secret Codes
KidsCanCode
12 Learning to Code with Python: Lesson 2.1 Creating Computer Graphics
Learning to Code with Python: Lesson 2.1 Creating Computer Graphics
KidsCanCode
13 Learning to Code with Python: Lesson 2.2 Simple Animation
Learning to Code with Python: Lesson 2.2 Simple Animation
KidsCanCode
14 Learning to Code with Python: Lesson 2.3: Animating More Objects
Learning to Code with Python: Lesson 2.3: Animating More Objects
KidsCanCode
15 Learning to Code with Python: Lesson 2.4: More Fun with Animation
Learning to Code with Python: Lesson 2.4: More Fun with Animation
KidsCanCode
16 Extra: Setting up the Atom Editor for Python
Extra: Setting up the Atom Editor for Python
KidsCanCode
17 Game Development 1-1: Getting Started with Pygame
Game Development 1-1: Getting Started with Pygame
KidsCanCode
18 Game Development 1-2: Working with Sprites
Game Development 1-2: Working with Sprites
KidsCanCode
19 Game Development 1-3: More About Sprites
Game Development 1-3: More About Sprites
KidsCanCode
20 Pygame Shmup Part 1: Player Sprite and Controls
Pygame Shmup Part 1: Player Sprite and Controls
KidsCanCode
21 Pygame Shmup Part 2: Enemy Sprites
Pygame Shmup Part 2: Enemy Sprites
KidsCanCode
22 Pygame Shmup Part 3: Collisions (and Bullets!)
Pygame Shmup Part 3: Collisions (and Bullets!)
KidsCanCode
23 Pygame Shmup Part 4: Adding Graphics
Pygame Shmup Part 4: Adding Graphics
KidsCanCode
24 Pygame Shmup Part 5: Improved Collisions
Pygame Shmup Part 5: Improved Collisions
KidsCanCode
25 Pygame Shmup Part 6: Sprite Animation
Pygame Shmup Part 6: Sprite Animation
KidsCanCode
26 Pygame Shmup Part 7: Score (and Drawing Text)
Pygame Shmup Part 7: Score (and Drawing Text)
KidsCanCode
27 Pygame Shmup Part 8: Sound and Music
Pygame Shmup Part 8: Sound and Music
KidsCanCode
28 Pygame Shmup Part 9: Shields
Pygame Shmup Part 9: Shields
KidsCanCode
29 Pygame Shmup Part 10: Explosions
Pygame Shmup Part 10: Explosions
KidsCanCode
30 Pygame Shmup Part 11: Player Lives
Pygame Shmup Part 11: Player Lives
KidsCanCode
31 Pygame Shmup Part 12: Powerups
Pygame Shmup Part 12: Powerups
KidsCanCode
32 Pygame Shmup Part 13: Powerups (part 2)
Pygame Shmup Part 13: Powerups (part 2)
KidsCanCode
33 Pygame Shmup Part 14: Game Over Screen
Pygame Shmup Part 14: Game Over Screen
KidsCanCode
34 Pygame Platformer Part 1: Setting Up
Pygame Platformer Part 1: Setting Up
KidsCanCode
35 Pygame Platformer Part 2: Player Movement
Pygame Platformer Part 2: Player Movement
KidsCanCode
36 Pygame Platformer Part 3: Gravity and Platforms
Pygame Platformer Part 3: Gravity and Platforms
KidsCanCode
37 Pygame Platformer Part 4: Jumping
Pygame Platformer Part 4: Jumping
KidsCanCode
38 Pygame Platformer Part 5: Scrolling the Window
Pygame Platformer Part 5: Scrolling the Window
KidsCanCode
39 Pygame Platformer Part 6: Game Over
Pygame Platformer Part 6: Game Over
KidsCanCode
40 Pygame Platformer Part 7: Splash & End Screens
Pygame Platformer Part 7: Splash & End Screens
KidsCanCode
41 Pygame Platformer Part 8: Saving High Score
Pygame Platformer Part 8: Saving High Score
KidsCanCode
42 Pygame Platformer Part 9: Using Spritesheets
Pygame Platformer Part 9: Using Spritesheets
KidsCanCode
43 Pygame Platformer Part 10: Character Animation (part 1)
Pygame Platformer Part 10: Character Animation (part 1)
KidsCanCode
44 Pygame Platformer Part 11: Character Animation (part 2)
Pygame Platformer Part 11: Character Animation (part 2)
KidsCanCode
45 Pygame Platformer Part 12: Platform Graphics
Pygame Platformer Part 12: Platform Graphics
KidsCanCode
46 Pygame Platformer Part 13: Improved Jumping
Pygame Platformer Part 13: Improved Jumping
KidsCanCode
47 Pygame Platformer Part 14: Sound and Music
Pygame Platformer Part 14: Sound and Music
KidsCanCode
48 Pygame Platformer Part 15: Powerups
Pygame Platformer Part 15: Powerups
KidsCanCode
49 Pygame Platformer Part 16: Enemies
Pygame Platformer Part 16: Enemies
KidsCanCode
50 Pygame Platformer Part 17: Using Collision Masks
Pygame Platformer Part 17: Using Collision Masks
KidsCanCode
51 Pygame Platformer Part 18: Scrolling Background
Pygame Platformer Part 18: Scrolling Background
KidsCanCode
52 Pygame Platformer Part 19: Wrapping Up
Pygame Platformer Part 19: Wrapping Up
KidsCanCode
53 Gamedev In-depth Topics: 4-way vs. 8-way Movement
Gamedev In-depth Topics: 4-way vs. 8-way Movement
KidsCanCode
54 Gamedev In-depth Topics: Time-based vs. Frame-based Movement
Gamedev In-depth Topics: Time-based vs. Frame-based Movement
KidsCanCode
55 Gamedev In-depth Topics: Non-integer Movement
Gamedev In-depth Topics: Non-integer Movement
KidsCanCode
56 Tile-based game Part 1: Setting up
Tile-based game Part 1: Setting up
KidsCanCode
57 Tile-based game Part 2: Collisions and Tilemap
Tile-based game Part 2: Collisions and Tilemap
KidsCanCode
58 Tile-based game Part 3: Smooth Movement
Tile-based game Part 3: Smooth Movement
KidsCanCode
59 Tile-based game Part 4: Scrolling Map / Camera
Tile-based game Part 4: Scrolling Map / Camera
KidsCanCode
60 Tile-based game Part 5: Player Graphics
Tile-based game Part 5: Player Graphics
KidsCanCode

Related Reads

📰
Three Token-2022 Mints in One Week: Fees, Yield, and Soulbound
Learn how to build three different Token-2022 mints on Solana devnet in one week, including fee-bearing, interest-accruing, and soulbound tokens
Dev.to · atharv shukla
📰
Maximize Google Workspace AI Power: Safeguard Data and Boost Performance in 2026
Maximize Google Workspace AI power by safeguarding data and boosting performance to stay ahead in 2026
Dev.to AI
📰
What is Gemini Spark, and what can it actually do for you?
Gemini Spark integrates AI into daily Google apps to enhance productivity, learn how to leverage it
TechCabal
📰
How I use python to save hours every week
Learn how to use Python to automate tasks and save hours every week, with practical steps for beginners and experienced users alike.
Dev.to AI
Up next
Implement Microsoft Entra ID Auth with Delegated Graph API Calls in ASP.NET Core Web App Razor Pages
Dewiride Technologies
Watch →