• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

[Tạo 2D Platformer Game với Godot] Part 27: Unlocking Levels

AnonyViet by AnonyViet
January 26, 2023
in Tips
0

In this section, I will show you how to unlock the next level after completing the previous level.

Join the channel Telegram of the AnonyViet 👉 Link 👈

It’s not that you like to click on any level to play that level.

Unlock levels

Algorithm

For this part, I will have the following algorithm:

+ I will add a variable in PlayerData to store the data of which map has been unlocked, with the structure as below:

var Unlocked_map = {
    "Map1": false,
    "Map2":false,
    "Map3":false,
}

+ Then in KhuVucDiChuyen after the Player has gone there ie won the game, then I will set the Map I am playing in the Unlocked_map variable to true

func _on_KhuVucDiChuyen_body_entered(body):
        PlayerData.Unlocked_map[get_parent().name] = true

+ Then, in the Level scene, I will check if I click on that Level and that Level if it is Map1, it will play Map1 because this is the first map I need to play.

+ Then, if it’s not Map1, that means you’ve clicked on Level 2 or higher and then I check if the previous Map that you clicked on has been completed, I will switch to playing that Map.

For example: If I haven’t played Map1, then Unlocked_map[“Map1”] is = false, I click on Level 2 and then Level2 checks if Unlocked_map[“Map1”] is = false then you have not completed it and can not play level2 and vice versa.

PlayerData

extends Node


var diemso = {
    "Map1": 0,
    "Map2":0,
    "Map3": 0,
}
var Unlocked_map = {
    "Map1": false,
    "Map2":false,
    "Map3":false,
}



I added a dictionary containing the data of unlocked maps.

AreaVucDiTrans

extends Area2D


export (String,FILE) var LevelKeTiep
onready var endlevelmenu = get_parent().get_node("EndLevelMenu")

func _on_KhuVucDiChuyen_body_entered(body):
    if body.name == "Player":
        endlevelmenu.get_node("EndLevelMenu").show()	
        get_tree().paused = true
        PlayerData.Unlocked_map[get_parent().name] = true

Moving area, I put 1 more line at the end.

And if you notice in the previous section, I have a few lines of code to add scores, but to add scores to PlayerData, it has to press 1 of 2 buttons. So, what if the player just went in and the menu won the game out? Definitely have to start over again.

+ So I will put a small exercise here is to transfer the line of code to add scores to PlayerData in EndLevelMap through KhuVucDiChuyen.

Level Scene

At the Scene level, I just added the code to the Hinhtron_pressed() function:

func _on_HinhTron_pressed():
    var level_truocdo = int(Level) - 1
    if MapName != "Map1":
        if PlayerData.Unlocked_map["Map"+ str(level_truocdo)] == true :
            get_tree().change_scene(Scene)
    else: 
        get_tree().change_scene(Scene)

I create one more variable level_truocdo and I add int() at Level because the Level variable is being declared as String if you don’t add int, it will be String – Integer and cause an error.

Result

[Tạo 2D Platformer Game với Godot]  Part 27: Unlocking Levels

Now if you run the game and click on the level you will see that it doesn’t go to the level 2 scene anymore, but has to complete the level 1.

Because of this, I don’t know what kind of picture I should get for you to see, so please read it @@.

Summary

In this section, I have shown you how to be able to add the level unlock feature. In the next part, the sound will be added.

The article achieved: 5/5 – (100 votes)

Tags: GameGodotLevelsPartPlatformertạoUnlockingvới
Previous Post

Lesson 104: How to use the COUNTIF function in Excel

Next Post

How to Jailbreak Untether with Fugu14 via Altstore

AnonyViet

AnonyViet

Related Posts

Top 5 game programming languages ​​to learn now
Tips

Top 5 game programming languages ​​to learn now

June 8, 2025
[Godot Shooter] #2: Creating characters & shooting bullets
Tips

[Godot Shooter] #2: Creating characters & shooting bullets

June 7, 2025
What do you need to learn game programming? Is it difficult? How long does it take?
Tips

What do you need to learn game programming? Is it difficult? How long does it take?

June 6, 2025
Instructions for registering chatgpt team at $ 1
Tips

Instructions for registering chatgpt team at $ 1

June 5, 2025
How to engrave the right mouse menu error on Windows
Tips

How to engrave the right mouse menu error on Windows

June 5, 2025
How to create online meme photos is very easy with a few steps
Tips

How to create online meme photos is very easy with a few steps

June 5, 2025
Next Post
How to Jailbreak Untether with Fugu14 via Altstore

How to Jailbreak Untether with Fugu14 via Altstore

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
Discover the glowing effect next to the iPhone ios 18 screen

Discover the glowing effect next to the iPhone ios 18 screen

June 8, 2025
[Godot Shooter] #2: Creating characters & shooting bullets

[Godot Shooter] #2: Creating characters & shooting bullets

June 7, 2025
Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
Discover the glowing effect next to the iPhone ios 18 screen

Discover the glowing effect next to the iPhone ios 18 screen

June 8, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET https://kubet88.yoga/ bj88

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET https://kubet88.yoga/ bj88

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply