Posts Tagged ‘Tetris’

Tetris: Adding gamepad support

August 30, 2013 7 comments

In this article, we will look at how to add gamepad support to a game using our Tetris clone as an example.

Simple2D 1.11 includes gamepad support using XInput – the new replacement for DirectInput in DirectX 11 – and makes it ridiculously easy to add support to existing games as we shall see here. If you would rather code everything yourself and want the nitty gritty, check out my 2-part mini-series XInput Tutorial: Adding gamepad support to your Windows game for the low-level details.

Download (SimpleTetris 1.5): Source code | Executable

Read more…


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…

Tetris Aside: Coding for T-Spins

October 13, 2012 3 comments

(the source code and EXE file for this update of SimpleTetris can be found at the end of the article)

One of my Tetris-playing colleagues pointed out to me recently that T-spins do not work in my implementation of SimpleTetris. Although I hadn’t checked it explicitly, I was quite surprised by this as I knew the code I had written should support them just fine.

A nice double t-spin opener.

The orange-coloured T-piece here will fall 2 more rows, at which point it can be rotated such that it will complete the bottom 2 rows. This ‘impossible’ rotation of T-pieces where in real life the piece would be locked into place is the premise of the T-spin.

For those not in the know, the Tetris Wikia T-spin page has some excellent explanations and diagrams of what T-spins are; namely, when you rotate a T-shaped Tetris piece in a way that would be impossible in real life (due to the corners being obstructed by other blocks) such that it fits snugly into a T or notch-shaped hole (see image).

Read more…

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…

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…

Coding Challenge Postmortem And Analysis: Tetris in 8 Hours

May 23, 2012 3 comments

You may have seen that yesterday I coded Tetris from scratch in 8 hours in C++ (source code and EXE links on that page). Today I shall reflect on the whys, the good and bad points and lessons learned. Read more…

%d bloggers like this: