Quantcast
Channel: Game From Scratch - GameDev News
Viewing all articles
Browse latest Browse all 1352

Allegro.js A New JavaScript Library Inspired by Allegro

$
0
0

 

I remember using Allegro wayyyyyy back in the day in the early 1990s.  It was one of few graphics libraries available for DOS based machines (even though it started life as an Atari library) and certainly one of the only free game libraries available.  Amazingly enough Allegro is still under active development.  Anyways enough reminiscing…  today Allegro.js was released, an HTML5 library inspired by Allegro.  For a brand new library there is already an impressive amount of documentation and reference material available.  One of the hallmarks of the Allegro library was it was brutally simple to use and Allegro.js seems to have carried on that tradition.  Here is an example Allegro app:

 

// bitmap oobjectsvar logo,ball;// sample objectvar bounce;// size and speed of the ballvar size=64,speed=5;// positon of the ballvar cx=100,cy=100;// velocity of the ballvar vx=speed,vy=speed;// drawing functionfunctiondraw(){// draw allegro logo backgroundstretch_blit(logo,canvas,0,0,logo.w,logo.h,0,0,SCREEN_W,SCREEN_H);// draws the ball resized to size*size, centered// stretch it a bit vertically according to velocitystretch_sprite(canvas,ball,cx-size/2,cy-size/2,size,size+abs(vy));}// update game logicfunctionupdate(){// did the ball bounce off the wall this turn?var bounced=false;// if the ball is going to collide with screen bounds// after applying velocity, if so, reverse velocity// and remember that it boncedif(cx+vx>SCREEN_W-size/2) {vx=-speed;bounced=true;}if(cy+vy>SCREEN_H-size/2) {vy=-speed*3;bounced=true;}if(cx+vx<size/2) {vx=speed;bounced=true;}if(cy+vy<size/2) {vy=speed;bounced=true;}// move the ball
   cx+=vx;
   cy+=vy;// if it bounced, play a soundif(bounced)play_sample(bounce);// add gravity
   vy+=.3;}// entry point of our examplefunctionmain(){// enable debugging to console elementenable_debug("debug");// init all subsystems, put allegro in canvas with id="canvas_id"// make the dimesnions 640x480allegro_init_all("canvas_id",640,480);// load ball image
   ball =load_bmp("data/planet.png");// load background image
   logo =load_bmp("data/allegro.png");// load the bounce sound
   bounce =load_sample("data/bounce.mp3");// make sure everything has loadedready(function(){// repeat this game looploop(function(){// clear screenclear_to_color(canvas,makecol(255,255,255));// update game logicupdate();// render everythingdraw();// all this happens 60 times per second},BPS_TO_TIMER(60));});// the endreturn0;}// make sure that main() gets called as soon as the wesbite has loadedEND_OF_MAIN();

 

If this looks interesting to you be sure to check out Allegro.js.  It looks like a cool library, based on another cool library, just waiting for a community to form around it.


Viewing all articles
Browse latest Browse all 1352

Trending Articles