Ring/Lessons/Graphics and 2D Games programming using RingAllegro

Graphics and 2D Games programming using RingAllegro
In this chapter we will learn how to use the allegro game programming library in our Ring applications.

We have the file gamelib.ring that load the DLL library that contains wrappers for the Allegro functions

The file gamelib.ring uses the Load instruction to execute the file allegro.rh which is a ring source code file contains constants to be used in our programs. Then using the function LoadLib we can load the DLL library "ring_allegro.dll".

To write portable code we can change the gamelib.ring to check the platform before loading the DLL/So file.

Drawing, Animation and Input
The next example uses the Allegro library for drawing, moving objects on the screen and getting input from the keyboard and the mouse.

.. note:: In the previous example we used the function callgc which is a Ring function to force calling the Garbage collector inside the While/End loop.

Program Output:

At first the program display a messagebox



Then we see two rectangles are moving on the screen



Then we see an image displayed on the screen



Finally we have one rectangle, and we see it moving all of the time on the screen but we can control it using the Mouse and/or the Keyborad



Using TrueType Fonts
In this example we will see how to use TrueType Fonts *.ttf in our Games using Allegro

Screen Shot:



Playing Sound Files
The next example play a sound file

Scaling and Rotating Images
The next example display and rotate an image

Screen Shot:



Display Transparent Image
The next example display image with white background on another image

Screen Shot:



Using Threads
In this example we will learn how to users threads from the Allegro library

Output: