In this tutorial I will be demonstrating a “quick and easy” way to make a 2D game using OpenGL and a programming language, no engines involved! To follow this tutorial you are expected to have at least a bit of experience using OpenGL and the language you want to use, even if you have only ever gotten as far as making a window and a triangle! I will be using C++ throughout the creation of the game and will be writing this whilst developing the software. I’ll be using Ubuntu 11.04 with the proprietary ATI driver as the platform but it shouldn’t make much difference, the window creation code might be the only difference if the platform being used does not have GLFW.
The whole development process will be split up into 4 stages, each should reach significant milestones leading up to the project’s completion. I’m not going to bother with a design stage, for now the game is going to consist of basic shapes with solid colour. This can be changed later on in development to actual graphics will little effort anyway.
The one thing which always kept me from using Debian was the horrific font rendering on LCD screens which has plagued it since it was born. I’ve always liked the way Ubuntu renders fonts, so now Debian has pretty much the same libcairo2 package by default, making the fonts render like Ubuntu’s is pretty easy.
First thing to do is grab Ubuntu’s fonconfig-config package from any of the mirrors here: http://packages.ubuntu.com/natty/all/fontconfig-config/download and save it somewhere. Now open the .deb file with Archive Manager (file-roller) as root and enter the /etc/fonts directory within the archive. Next, open nautilus as root (Alt + F2, gksudo nautilus) and brows to /etc/fonts on your Debian file system.
Next step is mega easy, just drag all the files and folders from the archive into the file browser, replacing all files which already exist.
Log out and back in, and change font preferences so they looks something like this:
Once this is done, fonts should be Ubuntu pretty!
NOTE: It works fantastically well with Ubuntu fonts!
This post will cover the very basics of how we will draw a tank, made up of 2 squares, one for the tank body and one for the tank turret. We will be drawing the tank the same way we drew the big white square, but by re-sizing and changing its colour!
Pretty simple.
There is only a small change to the original code. The addition of a new square for the turret and a change in colour for both squares along with a change in size so that they look like a tank and a turret.
This post will explain how to install Box2D on a Linux/Unix system and then add it to your game, ready to be used. Box2D is a physics engine specifically designed to be used in 2D graphics software to bring real world physics. You can find a list of features Box2D contains here: http://www.box2d.org/features.html
The next step in the development of the game is to add a player object. To keep the game simple, we wont be using any sort of inheritance and will be keeping all object types entirely separate. This section will be pretty small, adding 2 more files to our source tree, making a small modification to the Makefile and adding 3 lines of code to Main.cpp.
In yesterday’s post, creating simple BASIC programs, saving them into memory and running them was demonstrated. This post will be a small one demonstrating how to save your program from memory to a disk so it can be retrieved again after restarting the C64 or clearing the memory.
The emulated disk drives
VICE supports both C64 disc images and tape images by emulating the original devices. The use of an emulator means that we will have to use images of the storage media saved as files on the host operating system’s file system.
It is possible to create empty disk image files through VICE, ready to save data to them as if they were a real medium. To create one of these empty images, click File > Create and attach an empty disk > Unit #8… and then choose a name and location to create the image.
Make sure not to forget to include the .C64 file extension.
Once the file has been created, it will be attached to Unit #8. This is the identifier of the drive in which the disk has been loaded. It is necessary to remember the ID of the drive because to save and load from it, the number is used as a parameter.
If all went well, the C64 should still show READY and we can move on to writing the program to be saved.
Read more…
Every programmer has a secret (or not so secret) soft spot for the Commodore 64, I know I do so off to Google shopping search I go to try and find a cheap one. £100+ is a bit too ridiculous for me though so I managed to find an alternative.
Meet VICE.
Installing VICE
VICE C64 is a cross platform Commodore 64 emulator and best of all, it’s free software. (This doesn’t mean the Commodore 64 roms are!) Ubuntu users can install VICE via the Ubuntu Software Centre. Just search for “VICE” and install the emulator.
Once installed, you will need to download the ROM’s. You can find them HERE. Once downloaded, extract the contents of the “data” folder to ~/.vice and then run the emulator via the Applications>Other menu or typing “x64″ into a terminal.
Post boot
Once the emulator boots up, hopefully successfully, you should be greeted with the ever so famous “COMMODORE 64 BASIC V2” message. If you’re lucky enough to have reached this point, it’s time to write your first (unless you’ve done this before) BASIC program for the C64 and where better to start than the almighty Hello World application.
When I look at the lovely blue screen of the C64, I try to think of it as a BASIC interpreter quite similar to Python’s. This enables the user to enter BASIC commands without having to save them to memory, preserving valuable storage space in the 38911 byte block of memory.
Why?
It’s time to put all the beginner tutorials back onto my blog. I’ll start with a WriteProcessMemory tutorial (the basics of memory editing). WriteProcessMemory is useful when you don’t want to be loaded into the memory space of the target program.
First of all you are going to need to know the address of the memory you want to edit. Use Cheat Engine or some similar program (I recommend Cheat Engine, obviously) to find it.
In this example, I am going to write to a game called Star Sonata and enable a speed hack. You don’t have to get this game, you can use any game but make sure you change the addresses to the ones you find.
The Code
There’s not much to explain for this code so I’ve commented most lines in the source. Should make it easy to understand.
Source
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
int iChoice; // Store users choice.
DWORD dwProcId; // Store Star Sonata Process ID
HWND hStarSonata; //
HANDLE hProcess; // Handle to Star Sonata process
// Always do error checking, even if it takes a few seconds more to type!
if ((hStarSonata = FindWindow(NULL, "Star Sonata")) == NULL) { // Try to find the Star Sonata window.
printf("Cannot find Star Sonata window!"); // We couldn't find it
exit(1); // So let the user know and exit.
}
if (! GetWindowThreadProcessId(hStarSonata, &dwProcId)) { // Try to get the Process ID for use in OpenProcess
printf("Cannot retrieve process Id!"); // Let them know we cant get it
exit(1); // Exit...
}
// Now we are going to get a process handle to the game
if ((hProcess = OpenProcess(PROCESS_VM_WRITE, FALSE, dwProcId)) == NULL) { // Call OpenProcess to get VM Write access
printf("Cannot open process!"); // Failed to open process. Wrong priviliges?
exit(1);
}
printf("Star Sonata Speed Hack (Noz3001)\n\n(1)Enable Speed Hack\t(2)Disable Speed Hack\t(3)Quit\n\n"); // Show Options
while(iChoice != 3) { // Whilst option is not 3
printf("NOZ> _\b");
scanf("%i", &iChoice); // Get next option
switch(iChoice) {
case 1:
// Enable speed hack
if (! WriteProcessMemory(hProcess, (void*)0x00463de0, 0x75, 1, NULL)) { // Try to write 0x75 (jne) to 0x00463de0 (my address)
printf("Failed to write to memory!\n");
}
printf("Speed hack enabled.\n");
break;
case 2:
// Disable speed hack
if (! WriteProcessMemory(hProcess, (void*)0x00463de0, 0x74, 1, NULL)) { // 0x74 is (je). The original opcode.
printf("Failed to write to memory!\n");
}
printf("Speed hack disabled.\n");
break;
case 3:
printf("Leaving...\n");
continue;
default:
printf("No such option!\n");
break;
}
}
CloseHandle(hProcess);
exit(0);
}



