This article is the first in a series I am planning that dives deep into the design and development of a simple game known as Pipes. While building the application, I will detail a number of key concepts or techniques that I have used. If you have programmed (before but not necessarily on a Pokitto) these concepts will seem obvious, if you are just starting out then hopefully they will be illuminating.
Most of you will be familiar with the game and would have seen it on mobile phones and even in printed form. Game play is very simple – connect each node with its partner by laying pipe between them. When laying a new pipe, it cannot cross any existing pipes. Once all of the nodes are connected, play moves on to a harder level.
I chose the Pipes game as it is complex enough to enable me to demonstrate the various techniques required to build a Pokitto game without being too complex. I hope you enjoy the articles and feel free to provide feedback via the community (https://talk.pokitto.com/)
Before we get started, I am going to assume that you have read the FemtoIDE tutorial which is in the [Pokitto Magazine Volume 2](https://talk.pokitto.com/t/magazine-pokitto-magazine-issue-2-released/2439) and have some basic programming experience in C++ or some other language. Even for a newbie, this tutorial is not extremely hard but it is focused on building a game on the Pokitto.
It doesn’t delve into classes and uses basic data types –
integers. Most of the code could be easily improved using more advanced functions but that is not the intent of this, introductory tutorial.
With each article in this series, I will start by prompting you to download the code from my repository. I encourage you to review the structure of the code just as much as the detail of the code itself. For this article, you can download the code from https://github.com/filmote/Pipes_Article1_Pokitto.
After opening the code in FemtoIDE, review the project. An image of the FemtoIDE is shown below. On the left-hand side is a navigation pane of the programs that make up the program and on the right the file currently being edited.
A number of files are worth mentioning at this point. Again I encourage you to review them so that you become familiar with their content.
My_settings.his a global configuration file used by the Pokitto library. It typically stores information such as what screen mode to use – low resolution, high resolution, 16 colours, etc. It can also be used to store custom settings for your particular program.
.elffiles are produced as part of the compilation process. The
.bincan be loaded onto a Pokitto and played.
main.cppis the default or first executable file that a Pokitto program runs. The contents of this file is visible in the right hand side of the screen and you can see that it is typically quite simple. In the shown example, it performs a number of steps to initialise the Pokitto then calls a second class (in this example
Game) which houses all of the game logic.
You can see that after the game initialisation, the process goes into a continuous loop. For those of you familiar with the Arduino platform, this is synonymous with the setup() and loop() constructs.
project.jsonis a file that is unique to the FemtoIDE and stores many project and compilation specific details. Typically, you will not need to edit this file so little knowledge of its structure is required.
The remainder of the files are specific to our game. These consist of a class header (
Game.h ), a number of class files (ending in
.cpp) and various support files.