Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
jAllegro is a minimal javascript port of a really popular game programming library called Allegro 4 from the first decade of our century. jAllegro is meant for everyone, from absolute beginners to old-school programming nerds, and it's fast to learn!
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! Check it out, and maybe make a game with it?
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.
Code: (js)
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!
jAllegro example game
Want something more sophisticated? Here's the jAllegro example game code. It's under 50 lines of code!
Code: (js)
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:
Use jAllegro
Planing to use jAllegro? Have any troubles? Found a bug? Wanna say hi?
Catch me on twitter at @Sosowski
Bonus!
Here's a picture of jAllegro unit test running consistently on all major browsers.
Read more about:
BlogsYou May Also Like