Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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 scoring mechanism

In the days of arcades, a high score was king. It wasn't enough to beat a game; you had to get in the top 10 highest scores in order to claim local fame. Once your score was high enough to knock someone out of the top ten, the victory could be finalized by putting your initials next to it. Or a dirty word. Not that I've ever done that….

Regardless, a lot of games today don't rely on a scoring system, but focus on the story, experience, or multiplayer rankings. Let's bring back a little piece of gaming history by creating a simple scoring mechanism.

Getting ready

This recipe does not involve any new sprites or other assets but does require a new object. Call the object obj_score and leave the sprite box blank.

How to do it...

  1. In the Object Properties for obj_score, add a Create event.
  2. Drag Set Score from the Score tab to the Actions box, and have it set the score to 0.
  3. Create a Draw GUI event and drag Draw Score to the Actions tab with the following values:
    x: 32
    y: 32
    caption: Score:
  4. Close the obj_score Object Properties window and open obj_enemy_patrol.
  5. Add a Collision event with obj_projectile and, from the Main1 tab, drag and drop Destroy Instance to the Actions box (Applies to: self).
  6. Drag Set Score to the Actions box and change the new score to 10 relative.
  7. Close the Object Properties window and open obj_projectile.
  8. Add a Collision event with obj_enemy_patrol and drag and drop Destroy instance at Position like you did previously.

How it works...

GameMaker is again doing a lot of the heavy lifting, here. You created obj_score to keep track of scoring. Not assigning a sprite to it will allow the object to be in a room, affecting the game, without being seen. The rest of the recipe is simply placing the score counter as a GUI element, checking for collisions between projectile and enemy, and adding points and destroying the two when they collide.

There's more...

In this recipe, obj_score acted as what's referred to as a controller object. These objects are often invisible and control specific aspects of the game. Since an object needs to be active in order for its actions and variables to be used, any aspect of the game that needs to be present without interruption should be assigned to a controller. I use controllers for music, HUD, global variables, and more.

See also

Most chapters going forward will deal with controllers and their various functions.

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