• 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 see your email account creation date
Tips

How to see your email account creation date

November 11, 2025
Microsoft’s ranking of the 10 best Windows versions
Tips

Microsoft’s ranking of the 10 best Windows versions

November 11, 2025
Recover deleted data on Windows 10 with Windows File Recovery
Tips

Recover deleted data on Windows 10 with Windows File Recovery

November 10, 2025
Tips

Why hasn’t your computer been updated to Windows 10 2004?

November 9, 2025
3 OCR Tools Extract Text from Images without Retyping
Tips

3 OCR Tools Extract Text from Images without Retyping

November 8, 2025
Ways hackers use to hack your Facebook and how to fix it
Tips

Ways hackers use to hack your Facebook and how to fix it

November 7, 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

How to create an order on Shopee to send items to relatives

How to create an order on Shopee to send items to relatives

November 12, 2025
How to install Anh Hai’s Pho Shop on MacBook is super easy

How to install Anh Hai’s Pho Shop on MacBook is super easy

November 11, 2025
How to turn off ads on Yoosee app in just 1 minute

How to turn off ads on Yoosee app in just 1 minute

November 11, 2025
Windows 11 and MS Office 2021 lifetime license, genuine from  during Keysoff’s 11.11 sale

Windows 11 and MS Office 2021 lifetime license, genuine from $14 during Keysoff’s 11.11 sale

November 11, 2025
How to create an order on Shopee to send items to relatives

How to create an order on Shopee to send items to relatives

November 12, 2025
How to install Anh Hai’s Pho Shop on MacBook is super easy

How to install Anh Hai’s Pho Shop on MacBook is super easy

November 11, 2025
How to turn off ads on Yoosee app in just 1 minute

How to turn off ads on Yoosee app in just 1 minute

November 11, 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

How to create an order on Shopee to send items to relatives

How to create an order on Shopee to send items to relatives

November 12, 2025
How to install Anh Hai’s Pho Shop on MacBook is super easy

How to install Anh Hai’s Pho Shop on MacBook is super easy

November 11, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

new88 trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

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

new88 trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

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