• 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

How to change the default font on Windows 10
Tips

How to change the default font on Windows 10

April 13, 2026
5 tips for using a Browser to replace an App (helps save RAM, time and money)
Tips

5 tips for using a Browser to replace an App (helps save RAM, time and money)

April 13, 2026
How to make funny MeMe photos without Photoshop within 10 seconds
Tips

How to make funny MeMe photos without Photoshop within 10 seconds

April 11, 2026
How to quickly design your own Logo without Photoshop
Tips

How to quickly design your own Logo without Photoshop

April 10, 2026
How to convert Website into App on Windows
Tips

How to convert Website into App on Windows

April 9, 2026
Instructions for getting 3 months of Adobe Express Pro for free
Tips

Instructions for getting 3 months of Adobe Express Pro for free

April 9, 2026
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

How to avoid Adblock detection on Youtube with 4 good tips

How to avoid Adblock detection on Youtube with 4 good tips

April 17, 2026
How to transfer ChatGPT data to Claude is extremely simple

How to transfer ChatGPT data to Claude is extremely simple

April 16, 2026
How to authenticate the owner’s SIM on VNeID from April 15

How to authenticate the owner’s SIM on VNeID from April 15

April 15, 2026
Speak Cells: Excel tool to read spreadsheets by voice very well

Speak Cells: Excel tool to read spreadsheets by voice very well

April 15, 2026
How to avoid Adblock detection on Youtube with 4 good tips

How to avoid Adblock detection on Youtube with 4 good tips

April 17, 2026
How to transfer ChatGPT data to Claude is extremely simple

How to transfer ChatGPT data to Claude is extremely simple

April 16, 2026
How to authenticate the owner’s SIM on VNeID from April 15

How to authenticate the owner’s SIM on VNeID from April 15

April 15, 2026
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

How to avoid Adblock detection on Youtube with 4 good tips

How to avoid Adblock detection on Youtube with 4 good tips

April 17, 2026
How to transfer ChatGPT data to Claude is extremely simple

How to transfer ChatGPT data to Claude is extremely simple

April 16, 2026
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

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