• 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

[Lập Trình Game] Lesson 13: Collect items in Godot Engine

AnonyViet by AnonyViet
November 11, 2024
in Tips
0

If you can follow this part, it proves that you are a very hard-working person :D. This is the last part in the basic game programming series with godot Already. Regarding the Menu – Continue and Install, I will write it in the Tutorials article because it is outside the Series because this Series only guides you to program a basic game, not advanced.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

In this part, I will guide you to collect coins. You can use it in many ways such as after collecting it, the game ends, if you don't collect enough within the time, you lose, etc.

Groups:

This is a very useful feature of Godot that helps you identify a button through a Group

Here Group is the group and you can put each button into a different group and use it to identify the button.

You can identify the node using the command is_in_groups() or if you want to get the parent node equal to the child node, use it get_parent_in_group()

And to add nodes to the group you can do 2 ways.

1. It is added in the Node Panel next to the Inspector

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

2. It is added by Script with the command add_to_group() and this add_to_group() part you should leave in the _ready function because the ready function is the function that will run the code when it first enters the game so we will put it there so that when we first run the game it will run. will be added to the group immediately

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Setting Item:

You can download assets Coin Games to get resources

First we will create a new sense Area2D.

Here we will use area2d because it has a singal that identifies bodies or areas that collide with it, so we will use it so that when the player touches it, it will send a signal that the boides have collided and collect the item.

Note: Here, our asset coin is SpriteSheet because there is only 1 row, so Vframe will = 0 Hframe, then you can count it yourself. If it is blurry, reimport it again.

Then save it

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Next we will create an Animation for it with AnimationPlayer. Create a Node and then create a new Aniamtion

Then add the track

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Choose Frame

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then you also add a key to the track as usual

Next we will create a script for the area2d.

Here we need to check that if the body goes into the player, it will disappear, otherwise if the monster goes into the coin it will disappear, then woe :V and the player's coin count will be + 1.

So we will connect the signal body_entered

[Lập Trình Game]  Lesson 13: Collecting items in Godot Engine

And after the connection is complete, we will create an if statement to identify the bodies as players with Groups. Then the player's coin variable will + 1 and then self-destruct (queue_free()).

func _on_Coin_body_entered(body):
          if body.is_in_group("Player"):
                    body.coin += 1
                    queue_free()

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then in the jaw _ready Let's run the animation.

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Next we will create a coin variable in Player so that when the player enters, the coin will + 1

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then in the Player's func _ready() function, you add a command for it to go to Group

To be add_to_group("Player")

[Lập Trình Game]  Lesson 13: Collecting items in Godot Engine

Then you set the mask/layer to make sure it works :v

In Project Settings, I will add a new mask/layer called Coin

[Lập Trình Game]  Lesson 13: Collecting items in Godot Engine

Then you set a mask/layer for it

Mask:

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Layer:

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then in the Player's Mask, you also tick the Coin box

So if it's successful, you can use it to do anything, it all depends on your imagination.

Next, I will create a Label to display the Coin number

So that's the end of the basic game programming series with godot and later I will write 2D Tutorials and Visual Scripting with Godot.

You can Download Full Project Code Game Godot of 14 lessons here.

Previous Post

Experience YouTube Shopping easily in just 3 steps

Next Post

Basic operations on Scene2D – basic Godot Engine

AnonyViet

AnonyViet

Related Posts

4 ways to fix bluetooth connectivity on Windows 11
Tips

4 ways to fix bluetooth connectivity on Windows 11

August 8, 2025
How to know the computer is tracked and processed by Keylogger
Tips

How to know the computer is tracked and processed by Keylogger

August 7, 2025
Opal: Create applications who do not need to write code
Tips

Opal: Create applications who do not need to write code

August 3, 2025
How to activate a new Start menu on Windows 11
Tips

How to activate a new Start menu on Windows 11

July 29, 2025
Intellgpt: AI tool for osint and data science
Tips

Intellgpt: AI tool for osint and data science

July 28, 2025
How to create Google Ai Pro 12 months free with Indian student account
Tips

How to create Google Ai Pro 12 months free with Indian student account

July 27, 2025
Next Post
Basic operations on Scene2D – basic Godot Engine

Basic operations on Scene2D - basic Godot Engine

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 for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 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 for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 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í mm88 8XBET mm88 trang chủ new88

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í mm88 8XBET mm88 trang chủ new88

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