- GameMaker Cookbook
- Brandon Gardiner
- 349字
- 2021-07-30 09:52:48
Creating win/lose scenarios
The term "game" has many different definitions, to the point where experts can't always agree what makes a game. Most definitions, though, determine that games are only such if they involve both win and lose scenarios. I mean, who wants to play a game you can't win or lose?
Getting ready
This recipe, again, does not necessitate new sprites or even objects. We'll be relying on existing objects but we'll be adding some new variables. Start by opening the Object Properties for obj_player
.
How to do it...
- In the Step event you should already have the actions that check the value of health. Beneath all of that, drag and drop Test Variable and have it check whether
lives
equals0
. - Below that, from the Main2 tab, drag Restart Game to the Actions tab.
- Close
obj_player
and openobj_score
. - Create a Step event and drag Test Variable to the Actions box and have it check whether
score
is equal to100
. - Below that, drag Restart Game from the Main2 tab.
How it works...
As you may have guessed by the names of the actions, you are simply asking GameMaker to check the values of score
and lives
, and restarting the game when they reach a certain point. In previous recipes you set the score to increase by 10 whenever you shot an enemy. If you shoot 10 enemies, the game will restart. You set the lives variable to 3
but had it decrease by 1 every time your health reached 0
. Once you have no lives left, the game restarts.
There's more...
Using Game Restart in this scenario is arbitrary; it is simply there to demonstrate that you can tell GameMaker to change the game's state based on your score, health, or number of lives. Under the Main1 tab in Object Properties you can find actions that take you to other rooms you may have created. This can be used to go from one level to another.
See also
The advanced GUI and Chapter 7, Saving the Day – Saving Game Data, covers save systems and leaderboards.
- Embedded Linux Projects Using Yocto Project Cookbook
- Java范例大全
- Node.js Design Patterns
- Java編程指南:基礎知識、類庫應用及案例設計
- Django Design Patterns and Best Practices
- Learning Laravel 4 Application Development
- Learning Neo4j 3.x(Second Edition)
- Python機器學習經典實例
- Python數據可視化之Matplotlib與Pyecharts實戰
- Learning Python by Building Games
- Java Web程序設計任務教程
- Mastering Concurrency Programming with Java 9(Second Edition)
- Drupal 8 Development Cookbook(Second Edition)
- 游戲設計的底層邏輯
- Mastering ArcGIS Server Development with JavaScript