jAllegro - A lousy javascript port of a game programming library

Started by
1 comment, last by Sos_the_latter 8 years, 9 months ago

jAllegro

A lousy javascript port of a game programming library

About jAllegro
jAllegro is a minimal javascript port of a really popular game programming library called Allegro 4 from the first decade of our century. Allegro 4 is a simple game programming library that abstracts a set of functions in C programming language to the developer allowing for simple and rapid creation of video games, without the need to program entity systems, classes and so on. Allegro 5 is the current Allegro version, but it varies greatly in how the API works, thus alienating many hardcore Allegro users. This library aims to provide a simple wrapper for a subset of canvas operations making it look like good old Allegro.
jAllegro background
I wanted to create something that will be easy to use and different from everything that's already out there. Since Allegro and SDL, there haven't been many non-object-oriented game libraries around, especially with the rise of AS3 and Unity. jAllegro is something else, I would like to to be available to both hardcore Allegro freaks and total newcomers who have never made a game before! I don't think this is going to become the new industry standard, but I hope it will allow newcomers to try something simple, old Allegro folks to get a bit nostalgic and maybe move on to browser development, and for game jammers to have something bloat-free that can get the job done, fast and ugly, lean and mean.
Where to get jAllegro
jAllegro Hello World!
Here's a source code of jAllegro "Hello World!" example to give you an idea as to how it works.

function main()
{
    allegro_init();
    set_gfx_mode("canvas_id", 640, 480);
    clear_to_color(canvas,makecol(255,255,255));
    textout_centre(canvas,font,"Hello World!",SCREEN_W/2,SCREEN_H/2,24,makecol(0,0,0));
    return 0;
}
END_OF_MAIN(); 
Here's a output pixture of the above code!
exhello.jpg
jAllegro example game
Want something more sophisticated? Here's the jAllegro example game code. It's under 50 lines of code!

var man,apple,bg;
var munch;
var apple_x=200,apple_y=200;
var player_x=100,player_y=100;
var score = 0;
 
function draw()
{
    draw_sprite(canvas,bg,0,0);
    draw_sprite(canvas,man,player_x,player_y);
    draw_sprite(canvas,apple,apple_x,apple_y);
    textout(canvas,font,"Score: " + score,10,20,24,makecol(255,255,255));
}
 
function update()
{
    if (key[KEY_UP]) player_y-=4;
    if (key[KEY_DOWN]) player_y+=4;
    if (key[KEY_LEFT]) player_x-=4;
    if (key[KEY_RIGHT]) player_x+=4;
    if (distance(player_x,player_y,apple_x,apple_y)<20)
    {
        play_sample(munch);
        apple_x = rand()%(SCREEN_W-32);
        apple_y = rand()%(SCREEN_H-32);
        score++;
        log("Apple eaten!");
    }
}
 
function main()
{
    enable_debug('debug');
    allegro_init_all("canvas_id", 640, 480);
    man = load_bmp("data/man.png");
    apple = load_bmp("data/apple.png");
    bg = load_bmp("data/grass.jpg");
    munch = load_sample("data/munch.mp3");
 
    ready(function(){
        loop(function(){
            update();
            draw();
        },BPS_TO_TIMER(60));
    });
    return 0;
}
END_OF_MAIN();
And here's a screenshot of the game:
exgame.jpg
Use jAllegro
Planing to use jAllegro? Have any troubles? Found a bug? Wanna say hi?
Bonus!
Advertisement

Congratulations for your release and for the good quality of the documentation.

Can you expand on the advantages of "non-object-oriented game libraries"? What other libraries do you consider too object-oriented?

Omae Wa Mou Shindeiru

Thank you!

I don't thing either is advantageous, they are just different approaches. Each might be more suitable for given task. I think that non-OOP is slightly better for super-short-time-period game jams, such as 1 hour, two hour or 0h game jam, since the code overhead is lower (you have to write less stuff to make things happen on screen).

This topic is closed to new replies.

Advertisement