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
Beginning C++ Game Programming

You're reading from   Beginning C++ Game Programming Learn C++ from scratch and get started building your very own games

Arrow left icon
Product type Paperback
Published in Oct 2016
Publisher Packt
ISBN-13 9781786466198
Length 520 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
John Horton John Horton
Author Profile Icon John Horton
John Horton
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. C++, SFML, Visual Studio, and Starting the First Game FREE CHAPTER 2. Variables, Operators, and Decisions – Animating Sprites 3. C++ Strings, SFML Time, Player Input, and HUD 4. Loops, Arrays, Switch, Enumerations, and Functions – Implementing Game Mechanics 5. Collisions, Sound, and End Conditions – Making the Game Playable 6. Object-Oriented Programming, Classes, and SFML Views 7. C++ References, Sprite Sheets, and Vertex Arrays 8. Pointers, the Standard Template Library, and Texture Management 9. Collision Detection, Pickups, and Bullets 10. Layering Views and Implementing the HUD 11. Sound Effects, File I/O, and Finishing the Game 12. Abstraction and Code Management – Making Better Use of OOP 13. Advanced OOP – Inheritance and Polymorphism 14. Building Playable Levels and Collision Detection 15. Sound Spatialization and HUD 16. Extending SFML Classes, Particle Systems, and Shaders 17. Before you go...

Planning Timber!!!

Whenever you make a game it is always best to start with a pencil and paper. If you don't know exactly how your game is going to work on the screen, how can you possibly make it work in code?

Tip

At this point, if you haven't already, I suggest you go and watch a video of Timberman in action, so you can see what we are aiming for. If you feel your budget can stretch to it, then grab a copy and give it a play. It is often on sale for under a dollar on Steam. http://store.steampowered.com/app/398710/ .

The features and objects of a game, which define the gameplay, are known as the mechanics. The basic mechanics of the game are:

  • Time is always running out.
  • Get more time by chopping the tree.
  • Chopping the tree causes the branches to fall.
  • The player must avoid the falling branches.
  • Repeat until the time runs out or the player is squished.

Expecting you to plan the C++ code at this stage is obviously a bit silly. This is, of course, the first chapter of a C++ beginner's guide. We can, however, take a look at all the assets we will use and an overview of what we will need to make our C++ do what we want it to.

Take a look at a annotated screenshot of the game:

Planning Timber!!!

You can see that we have the following features:

  • Player's current score: Each time the player chops a log he will get one point. He can chop a log with either the left or the right arrow.
  • Player Character: Each time the player chops, he will move/stay on the same side of the tree. Therefore the player must be careful which side he chooses to chop on. When the player chops, a simple ax graphic will appear in the player character's hands.
  • Shrinking time-bar: Each time the player chops, a small amount of time will be added to the ever-shrinking time bar.
  • Lethal branches: The faster the player chops, the more time he will get, but also the faster the branches will move down the tree, and therefore the more likely he is to get squished. The branches spawn randomly at the top of the tree and move down with each chop.
  • When the player gets squished, which he will quite regularly, a gravestone graphic will appear.
  • Chopped log: When the player chops, a chopped log graphic will whiz off away from the player.
  • There are three floating clouds that will drift at random heights and speeds as well as a bee that does nothing but fly around.
  • All this takes place on a pretty background.

So, in nutshell the player must frantically chop to gain points and avoid running out of time. As a slightly perverse but fun consequence, the faster he chops, the more likely his squishy demise.

We now know what the game looks like, how it is played, and the motivation behind the game mechanics. We can go ahead and start to build it.

You have been reading a chapter from
Beginning C++ Game Programming
Published in: Oct 2016
Publisher: Packt
ISBN-13: 9781786466198
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