Home Blog Index
Joseph Petitti —

Making a simple text-based game in C++

For the WPI course IMGD 3000 - Technical Game Development 1, I worked over the course of seven weeks to make a fully-featured game engine in C++. It uses simple text-based ASCII graphics and handles events, input, sounds, sprites, collisions, and other basic features. As a final project, to show off the features of this engine, I worked with a partner to make a fun game using it. The game, called "XiQ", is a fast-paced arcade puzzle game based on the Taito classic Qix.

Technical details

The engine I made is based on Professor Mark Claypool's Dragonfly engine, described as "a text-based game engine, primarily designed to teach about game engine development." Over the course of the term I built up the various features of the engine in several increments, which can be seen on GitHub.

By the end of Project 2c my engine had the following features:

As well as various other minor features.

Game features

To showcase the engine and make a practical project with it, I worked with a partner to develop a simple game using it.

The game we created is called XiQ: Tactical Zone Control. XiQ is a simple game in which you try to claim as much territory as possible in sixty seconds while avoiding enemies. You control a green marker called a XiQ (pronounced "quiche") that can walk along lines called Xix (pronounced "kicks"). You can draw Xix into the center of the play area by holding X or Z to draw fast or slow, respectively. When you box in an area with Xix it gets filled in, and you get points for the amount of area you captured. If you fence in an area by only drawing slowly you get ten times as many points, and the area is colored in a different color.

However, there are enemies that will try to stop you from claiming territory. Xyvz (pronounced "chives") are red X-shaped enemies that walk along Xix, and if they touch you you’ll die. The Xiz (pronounced "Cheese") is a red line-shaped enemy that flies around the uncaptured area of the board. If it hits an incomplete Xix as you’re drawing it, you’ll die. Also, if you run into your own incomplete Xix you’ll die. Score as many points as possible within sixty seconds to win!

Screenshot of Xiq
The Xiz is the red flying enemy, and the Xyvz are the red X's on the wires

One of the most difficult technical features of XiQ is the flood-fill algorithm we use to fill fenced-in areas with 'o' characters. When the player finishes drawing a line of Xix, the game runs a flood-fill algorithm on each side of the newly drawn line, filling in an arbitrary number of enclosed spaces created by it. All but the biggest enclosed area are taken as the captured zone, and are filled in with 'o' characters.

How to try it out

If you want to try out XiQ for yourself you can download and compile it for your system. You can find the source code on GitHub under the project4 directory.

The README and Makefile in GitHub are designed for a GNU/Linux system, but can be easily modified to work on any system.

The engine depends on the Simple and Fast Multimedia Library. To install it on Fedora GNU/Linux, do:

# dnf install SFML-devel

Now just download the code and compile it:

$ git clone https://github.com/jojonium/IMGD-3000-Technical-Game-Development-I.git imgd-3000 $ cd imgd-3000/project4/game $ make

Just run the ./game executable to play.

Final thoughts

Because I haven't done a ton of previous programming in C++, making this engine could be frustrating at times. Tracking down segmentation faults is always annoying, and some of the Professor's examples were misleading or outright wrong.

Even so, I feel liks a learned a lot from this class, and seriously sharpened my C++ skills. I ended up with a cool project that is actually pretty fun to play, and a simple game engine that I could re-use for something else in the future.