In part 1 we learned how to set up and communicate with the PiTrex and started with some design thoughts about “Vexxon - The Game”.
In this part 2 we start with programming the PiTrex and build the base for Vexxon.
(Game-) Programming for the PiTrex
As in every programming project, there are plenty of possibilities for how to solve it. In this series, I showcase how I personally prefer to create games (or any applications) for the PiTrex.
The Programming Environment
Working Cross-platform
Of course, it has its own charm to work directly on the PiTrex (in the end it’s a fully Linux-capable computer) but I prefer programming on a full-fledged Laptop with additional Monitors, a fast CPU, and a good graphics card. You will spend a lot of time with edit, compiling, linking, and testing a game, and the time you can save (and spend on more important things like new levels) it’s huge.
But on the other hand to that without the need for big changes after the PiTrex, it’s important to create an environment that’s as close as possible to the target platform (the PiTrex) as possible.
As I have highlighted in part 1, the architecture of my game(s) takes care of that. The Sandbox (or Playground) provides an environment that allows you to run the game and engine on Windows and implement the entire game and engine. It doesn’t use the PiTrex Library at all, but as you see in the block diagram, the game engine takes care of it and the game even has no “idea” if it runs on the PiTrex or Windows (macOS or Linux is also possible).
You can try out the Playground App for Windows with some example data, to see how it looks here.
Build for Windows
While it’s interesting to see the final app running, the more interesting part is how to build all this by yourself. For this, we must first install some tools and libraries.
Install Tools
In this tutorial series, we use Visual Studio as our IDE and CMake as a build tool
Download Visual Studio 2022 and install it on your Windows 10 machine. A good short intro on VS 2022 you find here
Download CMake and install it. If you like to know more about how to use those tools in detail, there is plenty of good information on YouTube
Download Git and install it. We use Git Bash and just the basic features for this tutorial. If you never worked with Git, find here a good one here
Install Libraries
To create a playground application that works on Windows, macOS, and Linux I use SDL (Simple Direct Media Layer) which provides me the graphic access but also the input handling I need.
Download SDL2
Copy the folder SDL2-2.26.2 to a folder (ex.
C:\Dev
)Set an environment variable
SDL2DIR
that points to that folderSET SDL2DIR={PATH_TO_FOLDER}
Download SDL2_image
Copy the
SDL2_image-2.6.2
a folder (ex.C:\Dev
)Set an environment variable
SDL2IMAGEDIRDIR
that points to that folderSET SDL2IMAGEDIR={PATH_TO_FOLDER}
Clone the playground repo with
git clone https://github.com/rogerboesch/playground
Open the Windows Command Prompt and go to that folder (ex.
cd C:\playground
)Create the Visual Studio project with
cmake -B build -G"Visual Studio 17 2022"
(I use Visual Studio 2022 here)
(You have full access to the source no matter if you have a free or paid subscription)
The result should look similar to this. Especially the last line that says that Build files have been written to {folder} confirms that you have all done right.
CMake has done a lot in the background and has created a build folder that contains all the files we need to work in Visual Studio
Now you’re ready to go and open Playground.sln
by double-clicking on it.
That’s all we need to work on “Vexxon - The Game” on Windows. We have a modern code editor, a comfortable debugger, and all the tools we need to work in the most efficient way on our game. If you click on the Play Icon Visual Studio builds the project and starts the application.
You will get this error message when you start the first time. This is because we have only installed SDL2 for development but the application doesn’t know where to find the runtime library (SDL2.dll
). The most simple solution is to copy SDL2.dll
which you also find in the root folder of the repo to the
same folder as the executable (ex. {folder_of_repo}/build/Debug
). If you don’t like to do that for every project, then simply copy SDL2.dll
into C:\Windows\System32
Now you should see an empty playground window with some text information, a horizon, and some ground lines. When you press the arrow keys you can already move here. Also, you see a rotating cube.
In the next newsletters, we go from here and implement a full level for Vexxon that will look like this.
That’s enough for now in Windows. Let’s jump to the PiTrex and let’s build Vexxon there. In the end that’s why we are doing all this :)
Info: It’s of course also possible to build it on macOS and Linux. All the code and info you find in the paid subscribers repository.
Build on PiTrex
One advantage of using Git is that we can also easily share code between the PiTrex and the host computer. Of course, you could even build remotely or copy using SCP, FTP, etc. but the approach of using Git has many advantages. I don’t change some code normally on the PiTrex but sometimes some minor tweaks must be done and then it’s the easiest to have version control (Git) in place.
Install the tools
Since the PiTrex is a Linux machine is quite easy and can be done with the following commands:
$ sudo apt update
$ sudo apt install git
And to verify if the installation was successful, type in
$ git --version
Because the PiTrex team uses make to build all I will also show that approach to build all on the PiTrex. To install all essential tools for development type in
$ sudo apt update
$ sudo apt install -y build-essential
After that, we can build and install Vexxon on the PiTrex with
$ git clone https://github.com/rogerboesch/playground
$ cd playground
$ cd src
$ mkdir build
$ make all
And to try out Vexxon simply call
$ ./playground
The Game Engine
At that point, we have most of the base work done to create games for the PiTrex while doing most of the development on Windows, macOS, or Linux. The game engine takes care of the differences between those platforms.
Also, it provides functionality to describe the entire game in a level file which can be extended and changed without coding. Even entire new levels can be created like this. I will provide an entire post just about the level files and how you can use them.
Besides the level support, it takes also care of the different input methods on the platform and I add later on even a feature where you can use your smartphone as a joystick :) But all step by step…
What’s Next?
In the next newsletters, I focus on the PiTrex only since we now have a working base to start on the actual game.
As you see, the level objects are not yet visible. This is mainly because there are too many objects to draw at once. So it needs some optimization for the PiTrex. The other change needed is the scaling and orientation of the coordinates since Vectrex has a slightly different system. Also, we learn more about the engine at first.
Stay tuned for “Vexxon The Game” - Part 3!
Info: The main articles will be available bi-weekly as written in the introduction letter. But to provide also some info between, I will add some sidenotes, background articles, or just progress videos so you don’t have to wait too long :)
Just to be sure,
when you are in the directory where the Makefile ist (playground/src) and type $ ls ../../pitrex/pitrex/pitrex/pitrex you get a valid path and see what?
Hi David,
no ,not the Makefile ofg the Pitrex library. You should not touch them at all and it's also not needed for our project. I refer to the Makefile in our project src/Makefile.
Best,
Roger