- Godot Engine Game Development Projects
- Chris Bradfield
- 217字
- 2021-06-18 18:51:32
Obstacles
Finally, the game can be made a bit more challenging by introducing an obstacle that the player must avoid. Touching the obstacle will end the game.
Create a new scene for the cactus and add the following nodes:
- Area2D (named Cactus)
- Sprite
- CollisionShape2D
Drag the cactus texture from the FileSystem dock to the Texture property of the Sprite. Add a RectangleShape2D to the collision shape and size it so that it covers the image. Remember when you added if area.is_in_group("obstacles") to the player script? Add the Cactus body to the obstacles group using the Node tab (next to Inspector).
Now, add a Cactus instance to the Main scene and move it to a location in the upper half of the screen (away from where the player spawns). Play the game and see what happens when you run into the cactus.
You may have spotted a problem: coins can spawn behind the cactus, making them impossible to pick up. When the coin is placed, it needs to move if it detects that it's overlapping the obstacle. Connect the coin's area_entered() signal and add the following:
func _on_Coin_area_entered( area ):
if area.is_in_group("obstacles"):
position = Vector2(rand_range(0, screensize.x), rand_range(0, screensize.y))
If you've added the preceding Powerup object, you'll need to do the same for its area_entered signal.
- 軟件架構(gòu)設(shè)計(jì)
- 輕松學(xué)C#
- Getting Started with Clickteam Fusion
- 計(jì)算機(jī)應(yīng)用復(fù)習(xí)與練習(xí)
- Expert AWS Development
- Hadoop Real-World Solutions Cookbook(Second Edition)
- 21天學(xué)通Visual Basic
- C語言開發(fā)技術(shù)詳解
- 面向?qū)ο蟪绦蛟O(shè)計(jì)綜合實(shí)踐
- 手機(jī)游戲程序開發(fā)
- 單片機(jī)技能與實(shí)訓(xùn)
- Linux系統(tǒng)下C程序開發(fā)詳解
- 手把手教你學(xué)Flash CS3
- 計(jì)算機(jī)組裝與維修實(shí)訓(xùn)
- 企業(yè)級Web開發(fā)實(shí)戰(zhàn)