Reader Level:
Article

Creating Games With the AllegNet Game Library

By francois skorzec on Nov 29, 2005
In this article I will show you the way of creating simple games with the AllegNet game library for .NET.

This article shows you the way of creating simple games with the AllegNet library.

AllegNet is a .net library for creating game using the power of the Allegro 4.2.0 library.

If you want to use the library, you must have the framework 2.0 installed.

Setp 1 : Installing the library

Download the needed library if you don't have it :

http://skorzec.com/allegnet/dl/needed.zip

You have to copy the files inside %windir%\system32 directory. If you already have the msvcr80.dll don't replace it.

Download the lastest version of the library :

http://www.skorzec.com/allegnet/dl/allegnet_0400_binary.zip

Unzip the files.

Setp 2 : Create a new project in visual studio 2005 express or other IDE of your choice.

Open VS 2005 and create a new c# console application.

Add reference to the file AllegNet.dll.

Step3 :Write the code

The following code is commented !!

/*Here you have all necessary using*/
using
System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using AllegNet;
using System.Drawing;

namespace AllagroManaged.Exemples
{
class AllegNet_pal:API //The main class must herit of AllegNet.API class
{
static int Main()
{

//AllegNet has some functions and object to deal with images, blit sound, joystick
//You can use object like PALETTE to play with 256 color image
PALETTE palette =
new PALETTE();

//An RGB structure. a palette is an array of 256 RGB structure
RGB temp;

int c;

//You can use Allegro_init function to initialize the library
if (Allegro_init() != 0)

return 1;

//You can use it to install Keyborad functionality
Install_keyboard();

//You can choose your screen resolution with Set_gfx_mode function and GFX_MODES enumerator
if (Set_gfx_mode(GFX_MODES.GFX_DIRECTX_WIN, 320, 240) != 0)
{
if (Set_gfx_mode(GFX_MODES.GFX_DIRECTX_WIN, 640, 480) != 0)
{

Console.WriteLine("Error setting graphics mode");

return 1;

}

}

/* first set the palette to black to hide what we are doing */

Set_palette(Black_Palette);

/* draw some circles onto the screen */
Acquire_screen();

for (c = 255; c > 0; c--)
Circlefill(Screen, Screen.w / 2, Screen.h / 2, c, c);

//Release the screen

Release_screen();

//You can install the mouse in order to play with the mouse
Install_mouse();

//You can use show_mouse function to show the mouse on the screen
Show_mouse(Screen);

// fill our palette with a gradually altering sequence of colors

for (c = 0; c < 64; c++)
{
RGB tmp =
new RGB();
tmp.r = (
byte)c;
tmp.g = (
byte)0;
tmp.b = (
byte)0;
palette.SetRGB(c,tmp);
}

for (c = 64; c < 128; c++)
{
RGB tmp =
new RGB();
tmp.r = (
byte)(127 - c);
tmp.g = (
byte)(c - 64);
tmp.b = (
byte)0;
palette.SetRGB(c, tmp);
}

for (c = 128; c < 192; c++)
{
RGB tmp =
new RGB();
tmp.r = (
byte)0;
tmp.g = (
byte)(191 - c);
tmp.b = (
byte)(c - 128);
palette.SetRGB(c, tmp);
}

for (c = 192; c < 256; c++)
{
RGB tmp =
new RGB();
tmp.r = (
byte)0;
tmp.g = (
byte)0;
tmp.b = (
byte)(255 - c);
palette.SetRGB(c, tmp);
}

//animate the image by rotating the palette
//Keypressed function return 1 when a key is pressed

while (Keypressed()==0)
{
temp = palette[255];
for (c = 255; c > 0; c--)
palette[c] = palette[c - 1];

palette[0] = temp;
Set_palette(palette);
}

return 0;
}
}
}

Step 4 : Running the project

You may have the following result :

capture-8.jpg

capture-9.jpg

Step 5 : Find more information about the library

Go to http://www.skorzec.com for more information about it.

Enjoy

COMMENT USING