PS2 Linux Programming

 

Simple Game

 

Introduction

 

This tutorial illustrates the integration of what has been covered so far in this series into a very simple computer game. In fact, to be honest, this application doesn’t really have any game-play at all but the reader can easily adapt and extend the code into a simple working game. As supplied , the code draws only 4 coloured sprites on screen, one of which can be moved around the screen with the controller pad.

 

There are many computer games that are built around coloured boxes: Tetris, Pong and Breakout to name but a few. The graphics are simple but the fun and immersion can be great. Writing such games illustrates many of the important features that are found in more modern and complex game products and the reader is encouraged to try writing one of these simple games if they have not already done so. Writing such a game will help enhance your knowledge of the PlayStation 2.

 

 

Program Code

 

There is nothing particularly new in this code other than the integration of the features already learned. Once again, the structure of the program at this stage is kept as simple as possible so as to help illustrate the techniques that are being used. The key points of the program are outlined below.

 

1.    A simple structure type Ps2BOX_t has been defined to hold the parameters of the boxes to be drawn such as the position, colour, depth and size.

 

2.    The code to read the controller pads has been integrated into the project.

 

3.     A simple render or game loop has been constructed to progress the game. Typical functions that are found in the game loop are: a function to update the pad data structures, a functions to perform some game logic such as moving the boxes around the screen, a function to clear the screen before commencing drawing, a function to render or draw to the off screen buffer and finally a function to swap the display buffers. This game loop is executed once per frame, producing one frame of animation for the game.

 

 

Program Operation

 

Four coloured boxes are on screen. Use the D-Pads on controller 1 to move the red box around. Press the Cross and the D-Pads together to make it move faster. Press the select and start together to end the program.

 

 

Conclusions

 

All the information that is needed to make a simple computer game is now available and the reader is encouraged to put this knowledge to good use and become a “PS2 Games Programmer”.

 

 

Dr Henry S Fortuna

University of Abertay Dundee

h.s.fortuna@abertay.ac.uk