Circle Jump: A Godot Mobile Game (Part 7)

KidsCanCode · Intermediate ·📰 AI News & Updates ·7y ago

Key Takeaways

Adds a score and HUD to a mobile game in Godot using GDScript and Godot's built-in features

Full Transcript

welcome back to part 7 of circle jump we're still working out in our Godot Engine mobile game and this time we're gonna make the circles move which is going to add some difficulty to the progression of the game alright let's get started okay the first thing we need to do is we need to fix a bug and when we run the game and we're at the title screen if we spam this button you see it triggers more than once and we wind up crashing we're sending out the signal the press's signal on the button multiple times but our code isn't accounting for that and so there's a couple things we can do about that but I think the easiest is going to be we go to our base screen script here and after we have clicked the button and we call the disappear method we're gonna disable all the buttons because we don't want to capture any more button presses and since we have them all in a group that should be pretty easy we can just say call group to call the same function on every group and the function we're going to call on the buttons group is set disabled and we're going to set it to true and then we want them to come back and be enabled again when they appear so we'll set this to false on up here and that should prevent us from being able to yeah see I'm clicking a bunch of times I can't multiply I can't multiple click on these buttons yeah that fixes the problem ok on to new features so over here in the main we are getting points whenever we get captured but we are gonna use that score to handle the progression the difficulty progression and we want to spawn different types of circles and that kind of thing but we might have other things that give us points besides just being captured and we're gonna want to check that score and when we cross certain thresholds change the the spawn rate of circles and things like that so to make this easier I'm going to take score here and I'm going to make it as set get so we have a function that we can call when we change the score and that means here we can do set score zero now you can do it this way you can say set score zero or if you want to call the set get locally you can say self dot score equals zero now the drawback of that is there is a small performance hit and calling self because you're generating a reference to the to this node in the case of this game performance is far from an issue and I like the clarity of the code looking like this so in this case I'm not going to call the set get directly and then here we'll say self dot square plus equals one and then what we want to do in the set score function is update the score so func set score we pass it's gonna be passed a value we're going to set the score we're going to set the score equal to that value and we're gonna update the HUD so that should be fine that shouldn't change anything at all let's see the score is just going up the same as before but what we also want to do is keep track of what level we're on and that's going to go up every certain number of rings which we put here on setting circles per level five so every five circles that we hit or every five points we get currently that's going to move us up a level we'll check that and they set score as well so if we our score is greater than zero and score we'll divide by circles per level and if the remainder is zero we're at a multiple of five so we will increase the level by one and we should show a message to that effect we moved up to level whatever okay we make sure to initialize level when we're starting a new game and that should do it let's give it a shot here yeah went to level two okay over to the circle where we want to add movement I want the circles to move back and forth so that as the game gets harder we have moving targets that we have to jump to so we're going to do that by using a between and I'm going to call this move between and then in the script we're going to get a reference to it and then moving is going to be separate from the modes right we might have a static circle that's moving we might have a limited circle that's moving or other modes that we add so what we are gonna do is have a move range this is how many how much the distance of the move is how far back and forth if we set this to zero we'll have a non moving circle and then we're also going to have the move speed which is gonna be how fast it moves back and forth and then so now we need to set up that movement and we're gonna do that with a function down here at the bottom I'm going to call this the set between and we're going to call this to start the movement but when the tween completes we want it to repeat again so we're going to call this again every time the tween finishes its cycle and that means that when we call it with the tweens completed signal it's gonna pass in two values which we don't actually need but we have to account for them and if move range is zero we're gonna return we're not going to move so the first time we call this we won't start the tween and now move range we're going to want to reverse every time we call this so that moves back and forth and then the move tween we're going to set up its movement we're gonna interpolate the property on cell of position X : X when you write it in this reference and then we're gonna go from whatever our current position dot X is to position dot X plus move range the duration is move speed and we're going to use between trans quad and tween and out for the easing and then we're just going to say move between dots start now we want to connect the tweens between completed signal and we want to connect it to that same function so that every time it finishes it's going to come back and call this again and then in our in it we can set that for the first time let's give that a shot and see what happens there we go the circles are moving back and forth I only see them that's exactly what we want right that'll do it for this time I hope you enjoyed it and I'll see you in the next video you

Original Description

We're making a mobile game in Godot! In this part, adding a score and HUD. Download the code for this part: https://github.com/kidscancode/circle_jump/releases/tag/part07 Text version: http://kidscancode.org/godot_recipes/games/circle_jump/ Support me on Patreon: http://patreon.com/kidscancode
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

📰
Oracle Just Fired 30,000 People to Pay One Customer’s AI Bill
Oracle's massive layoffs may be linked to a single customer's large AI bill, highlighting the economic risks of AI adoption
Medium · AI
📰
Anthropic's Landmark $1.5B Copyright Settlement Approved
Anthropic's $1.5B copyright settlement highlights the need for clearer guidelines in AI research, impacting builders and developers
Dev.to AI
📰
India’s IT Sector Sees AI Hiring Surge Amid Broader Recruitment Slowdown
India's IT sector sees a surge in AI hiring despite a broader recruitment slowdown, indicating a shift in operational priorities
Dev.to AI
📰
Anthropic’s landmark $1.5B copyright settlement is approved
Anthropic's $1.5B copyright settlement sets a precedent, but the issue of using copyrighted works for AI training remains unresolved
TechCrunch AI
Up next
AI Videos Monetize Nahi Hote? 😱 Real Truth Interview | YouTube Monetization Explained @Techisrar
Invisible Gyan EXTRA
Watch →