Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GameMaker Cookbook

You're reading from   GameMaker Cookbook Over 50 hands-on recipes to help you build exhilarating games using the robust GameMaker system

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781784399849
Length 212 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Game Plan – Creating Basic Gameplay FREE CHAPTER 2. It's Under Control – Exploring Various Control Schemes 3. Let's Move It – Advanced Movement and Layout 4. Let's Get Physical – Using GameMaker's Physics System 5. Now Hear This! – Music and Sound Effects 6. It's All GUI! - Creating Graphical User Interface and Menus 7. Saving the Day – Saving Game Data 8. Light 'em up! – Enhancing Your Game with Lighting Techniques 9. Particle Man, Particle Man – Adding Polish to Your Game with Visual Effects and Particles 10. Hello, World – Creating New Dimensions of Play Through Networking Index

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...

  1. 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 equals 0.
  2. Below that, from the Main2 tab, drag Restart Game to the Actions tab.
  3. Close obj_player and open obj_score.
  4. Create a Step event and drag Test Variable to the Actions box and have it check whether score is equal to 100.
  5. 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 Chapter 6, It's All GUI! – Creating Graphical User Interface and Menus, deals with more advanced GUI and Chapter 7, Saving the Day – Saving Game Data, covers save systems and leaderboards.

You have been reading a chapter from
GameMaker Cookbook
Published in: Dec 2015
Publisher:
ISBN-13: 9781784399849
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime