This is an old revision of the document!


Racing game

This racing game is a demonstration of using ARM-CAN UserInterface module to display 2D graphics on the LCD and use the joystick. The game itself is very simple – user has to drive the car on the track as fast as possible and there are no opponents nor obstacles on the track. Steering and driving is accomplished by moving the joystick. The program is made of several C source files which each take care of different tasks.

Data types

There are structure data types to hold information about 2D points, track sections and the car. All of them are declared in “types.h” file.

typedef struct
{
    short sX;
    short sY;
}
tPoint;
 
typedef struct
{
    tPoint pPosition;
    unsigned short usRadius;
}
tTrackSection;
 
typedef struct
{
    short sRadius;
    unsigned long ulAngle;
}
tPolarPoint;
 
typedef struct
{	
    long lVelocity;
    long lSteering;
    tPoint pPosition;
    unsigned long ulAngle;
    unsigned long ulColor;
    unsigned long ulLapTime;
    tBoolean bOnFinishLine;
}
tCar;

Trigonometric functions

Polygon drawing

Rendering track

Rendering car

Main program

The main function resides in “racing_game.c”.

Screenshot from game
int main(void);
void DoCarDriving(tCar *pCar);
void PrepareCar(void);
void GrPolyDraw(const tContext *pContext, const tPoint *pPoints, 
           unsigned long ulNumPoints, unsigned char ucClosedLoop);
void GrPolyFill(const tContext *pContext, const tPoint *pPoints, 
           unsigned long ulNumPoints);

Download

en/projects/racing_game.1276459239.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0