• 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

Instructions to unlock Facebook in the form of “your account locked” format “
Tips

Instructions to unlock Facebook in the form of “your account locked” format “

July 4, 2025
Top 5 white -hat hacker programming languages ​​should learn
Tips

Top 5 white -hat hacker programming languages ​​should learn

July 3, 2025
Latest information about Windows 10 21H1, 21H2
Tips

Latest information about Windows 10 21H1, 21H2

July 2, 2025
How to unlock the domain name was blocked by Facebook
Tips

How to unlock the domain name was blocked by Facebook

July 1, 2025
Graphic design students should be builted PC?
Tips

Graphic design students should be builted PC?

June 30, 2025
What is Facebook “account status” feature?
Tips

What is Facebook “account status” feature?

June 30, 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

Instructions to unlock Facebook in the form of “your account locked” format “

Instructions to unlock Facebook in the form of “your account locked” format “

July 4, 2025
How to register mysign digital signature on Vneid for free

How to register mysign digital signature on Vneid for free

July 4, 2025
Top 5 white -hat hacker programming languages ​​should learn

Top 5 white -hat hacker programming languages ​​should learn

July 3, 2025
Guide to see the new address on VNEID after the merger

Guide to see the new address on VNEID after the merger

July 3, 2025
Instructions to unlock Facebook in the form of “your account locked” format “

Instructions to unlock Facebook in the form of “your account locked” format “

July 4, 2025
How to register mysign digital signature on Vneid for free

How to register mysign digital signature on Vneid for free

July 4, 2025
Top 5 white -hat hacker programming languages ​​should learn

Top 5 white -hat hacker programming languages ​​should learn

July 3, 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

Instructions to unlock Facebook in the form of “your account locked” format “

Instructions to unlock Facebook in the form of “your account locked” format “

July 4, 2025
How to register mysign digital signature on Vneid for free

How to register mysign digital signature on Vneid for free

July 4, 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í 23win https://kubet88.yoga/ KUBET BK8 Bj88 https://u888b.site/ 8XBET

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í 23win https://kubet88.yoga/ KUBET BK8 Bj88 https://u888b.site/ 8XBET

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