Archive

Posts Tagged ‘Programming’

Tetris: Adding polish with music, sound effects, backgrounds, game options, an intro sequence and other tweaks

March 15, 2013 2 comments

Our previous version of SimpleTetris is working quite well as a single-player game, but lacks the professional touch. In this article, we’ll look at:

  • how to make pausing and unpausing the game also pause and unpause all of its subsystems
  • how to add music and sound effects and tie them into game events with SimpleFMOD (a library developed in another series on this web site which uses the well-known FMOD SoundSystem to produce audio – see the first part of the FMOD series for more information on how to use FMOD)
  • how to make an event-triggered throw-away animation using Simple2D
  • how to use bitmap images (sprites) as animated backgrounds
  • how to add game options which can be loaded and saved
  • how to add an intro sequence and a credits page

Most of these changes can be slotted in without any changes to the game logic, but there are a few gotchas and some little tweaks we can apply to make things better. I’ll note these below.

Download (SimpleTetris 1.41): Source code | Executable

For comparison, also have on hand the executable for the previous version of the game (SimpleTetris 1.31).

I strongly recommend that you run both versions and do a side-by-side comparison of the behaviour while working through the sections below, then hopefully the changes described will make sense more easily. Read more…

Advertisements

Tetris Revisited: Adding 2D Animations and Other Graphical Tweaks

October 12, 2012 1 comment

It’s game coding time with SimpleTetris again and this time we’re going to look at how to add a variety of different animations and useful graphical tweaks which can equally be applied to any game or demo.

We will create a simple animation class in C++ which takes care of tracking the position and timing of basic animations, and learn how to apply this to make changes in an object’s position, colour and alpha (transparency). We will examine how to use this class to animate several objects at different points in the path of a single animation, how to affect two paremeters of an object (eg. position and transparency) with a single animation function, and how to partly randomize the intermediate steps (interpolation) of an animation.

Although we are again using Simple2D here (and as such this article serves a tutorial on how to use it, and how SimpleTetris is evolving), the algorithms and principles can be mostly copy/pasted and are easily adaptable to other graphics libraries. The animation class works independently of Simple2D and does not depend on it.

Download: Source code (.cpp) | Source code (.h) | Executable

Read more…

Tutorial: Enabling Re-definable Controls in Windows games

September 29, 2012 Leave a comment

In this article we shall take a look at how to make the controls in your C++ game editable by the user. Once again we shall use SimpleTetris as the base example, and as with our implementation of the high score table, we will make use of Boost for serializing (saving) data into a file, and my Simple2D library for rendering the interface (although this part is optional).

Download: Source code (.cpp) | Source code (.h) | Executable

Read more…

Tutorial: A Modern Approach To Implementing High Score Tables in C++ using STL and Boost

September 22, 2012 4 comments

In this article I shall demonstrate a modern, object-oriented, re-usable technique to adding a local high score table to your C++ Windows games using STL and Boost. I shall use our SimpleTetris game of which this article is a follow-on.

Please note that this is by no means an efficient implementation, it is designed to just show the principle of the technique.

Download: Source code (.cpp) | Source code (.h) | Executable

Read more…

Coding Challenge Postmortem And Analysis: Asteroids in 10 Hours

June 18, 2012 3 comments

If you missed the live blog then check out Coding Challenge: Write Asteroids in 10 hours or less for the background. Let us now take a retrospective look at the results.

The latest version of the game and source code can be found here. Read more…

Coding Challenge: Write Asteroids in 10 hours or less

June 13, 2012 17 comments

Update 17-Jun-2012: Fixed some typos, the broken formatting in some of the code and the missing types after static_cast and dynamic_cast operators, and updated the code snippets to reflect two bug fixes.

Update 18-Jun-2012: Wrote the final section regarding the implementation of shields and waves.

The sun is shining brightly, it’s nice and warm outside and unbearably hot in the office, I didn’t manage to fall asleep til 7 this morning and people are asking me to go to the beach. This, of course, can only mean one thing: it’s time for another coding challenge!

Last time we managed to rattle through Tetris in a smooth 7 hours 59 minutes. Reader Jez Ward has upped the ante by issuing a challenge to write Asteroids in 10 hours or less. This is significantly more complex than Tetris for a few reasons:

  1. It’s a free-form game world and not a grid, which requires the use of per-pixel collision detection
  2. The ship has to accelerate and move in a way that roughly resembles basic physics
  3. The ship and asteroids do not have rectangular shapes but are irregular geometric constructions

…all of which basically means that significant portions of the game have to be engineered using different techniques to Tetris, which I thought made it a good 2nd-stage challenge for beginning game programmers to follow along with. Read more…

Tetris Revisited: Bells & Whistles 1

June 3, 2012 Leave a comment

This is a follow-up from the 8-hour Tetris prototype article.

Now we have a working game prototype, I shall walk you through how to make a series of basic improvements. The full source code is available below (see the original article for other dependencies you need to install to compile the code; the game is based on my Simple2D graphics library).

Download: Source code (.cpp) | Source code (.h) | Executable

Time spent: 2.5 hours. Read more…

%d bloggers like this: