|
An Allegro Game in 20 lines of code - Possible? |
Michael Jensen
Member #2,870
October 2002
|
what system is that from? it looks similar to the 800XL version but better gfx... can any one divide my gif into tiles? I do know that people have done pacman before without tiles, but i mean if you look at how the dots and the walls line (theres more than one pill in each tile space -- and i still cant divide my pic into tiles.....) http://www.geocities.com/michael_jensen419/level2.gif
|
spellcaster
Member #1,493
September 2001
|
It's from the arcade version. You know, the original -- |
Michael Jensen
Member #2,870
October 2002
|
Awesome work sc! you proved me wrong -- I'm still at a loss on how the pic I posted is tile based -- the source is avilable but you have to have flash to look at it -- the game is at http://www.neave.com/webgames/pacman/ and how do they get more than one pill on a tile??? (all the tile based pacmans that I could tell were tile based had the pills way to far apart...) another edit: -- I dont mean that it can't be made up of tiles b/c it can -- but I mean, can you impose like a grid on it (the pic I posted) of equal spacing to where it looks tilebased? (like 22x22 or 32 x 32 etc....)
|
spellcaster
Member #1,493
September 2001
|
There's just one pill in every tile. -- |
Michael Jensen
Member #2,870
October 2002
|
Wow sc -- it works pretty good on the interior of the pic that I posted.... except -- on the outside walls there is like 1 pixel outside of the tiles but that could be an easy hack -- very awesome, the reason why I always thought there was more than one pill for tile is because they're sooo close together -- I didnt think that the tiles would be smaller than the sprites that the game uses (in the pic I posted they are...) edit: To be more clear -- Until now I've thought that generally the tiles are the exact same height and width as the sprites that are being drawn on them, and in the pic that I was looking at they're not and it gives the effect (on my brain) that maybe its not tiled cause the pills look closer together cause the tiles are smaller...
|
Elias
Member #358
May 2000
|
I'm a bit late, but I just had to try this as well - here is my version of another classic game (not sure if it was done already): edit: now no warnings with -W -Wall #include <allegro.h> volatile int i,t=0,b=320,f=0,p[]={0,160,320},d[]={0,-1,1,0,0,0};void timer(void) {t++;}int main(void){if(!(allegro_init()||set_gfx_mode(GFX_AUTODETECT,640,480,0, 0)||install_timer()||install_int_ex(timer,BPS_TO_TIMER(100))||!install_mouse())) {clear(screen);for(i=0;i<480;i++)rectfill(screen,(i%40)*16,(i/40)*16,(i%40)*16+ 14,(i/40)*16+14,makecol(200,200,0));rest(4000);t=0;while(p[1]<400)if(f<t){for(i= 0;i<6;i+=2){if(i!=2)circlefill(screen,p[2],p[1],4,i?makecol(100,100,255):0);if(i <4)p[i+!i]+=d[i+!i];if(i<4&&getpixel(screen,p[2]+d<i>*5,p[1]+d[i+1]*5)){rectfill (screen,(p[2]+d<i>*5)&~15,(p[1]+d[i+1]*5)&~15,(p[2]+d<i>*5)|15,(p[1]+d[i+1]*5)| 15,0);d[i+!i]=-d[i+!i];p[i+!i]+=d[i+!i];}if(i)rectfill(screen,b-12,320,b+12,327 ,i==2?0:makecol(255,0,b/3));if(i==2)b=mouse_x;}f++;}}return 0;}END_OF_MAIN(); Guess which game it is first without running I have less than 20 ; - and it all fits into 11 lines not longer than 80 chars -- |
Michael Jensen
Member #2,870
October 2002
|
runs a little fast.... I wunder if compiling under djgpp and using moslo would help... -- it seems if i hit the ball once it slows down to a decent speed but its hitting it that first time when its going to speed of light that matters I suppose....
|
Elias
Member #358
May 2000
|
Yes, I put in rest(4000) because on my monitor it takes a few seconds to switch to fullscreen - and it messed up the timing code. It's fixed in the edited version. -- |
Thomas Fjellstrom
Member #476
June 2000
|
heh. looks good (yet another game I considered to do... Oh well.) -- |
Michael Jensen
Member #2,870
October 2002
|
I see, seems to work now -- was there paddle garbage in the old version too? You guys did way better than me on this as far as not cheating goes -- btw is what I did considered cheating?? edit: hehe -- so who can do a game in 10 lines!?;D
|
Thomas Fjellstrom
Member #476
June 2000
|
Mine is almost 10 I probably can get it to 10 If I really really try... But nah. -- |
Elias
Member #358
May 2000
|
Quote: I see, seems to work now -- was there paddle garbage in the old version too? You're right, I introduced garbage now - I edited it again to fix it. If I broke something else with that - I'm definitely not going to fix it in code formatted like that -- |
Michael Jensen
Member #2,870
October 2002
|
awesome
|
aileron42
Member #3,184
January 2003
|
First I want to say. These games everybody has written are sweet. Earlier I put my "car" racing game on this forum, but I've made a few changes. Added an opponent, and with a some shadow fx it is now a bumper car/hover craft racing game. Here it is if you care to take a look: 1/*1*/ #include <allegro.h> //include allegro
2/*2*/ int main() { //start of main
3/*3*/ int x[2]={0,0},y[2]={400,240+123},d[2]={0,0},ngx[4] = {456,456,182,182},ngy[4]={0,480,0,480},gc=0,t = -29,i=0, d1m = -1; //initialize
4/*4*/ if (!(!allegro_init()&&!install_keyboard()&&set_gfx_mode(GFX_AUTODETECT,640,480,0,0))) clear_to_color (screen,8); //install everything
5/*5*/ for (;!key[KEY_ESC] && (gc < 16) && (t<1025) ;t++, rest(50)) { //main loop
6/*6*/ for(i=0;i<2;i++) circlefill(screen,182 + i * 274 ,240,91,2); //draw big circles
7/*7*/ int a = (((x[0]-x[1])*(x[0]-x[1]) + (y[0]-y[1])*(y[0]-y[1]))< (18*18)) ? (((x[0]<x[1]) ? ((y[0]<y[1]) ? 128+fixtoi(fixatan(fixdiv(itofix(y[1]-y[0]),itofix(x[1]-x[0])))) : ((y[0]==y[1]) ? 128 : 128+fixtoi(fixatan(fixdiv(itofix(y[1]-y[0]),itofix(x[1]-x[0])))))): ((x[0]==x[1]) ?((y[0]<y[1]) ? 192 : ((y[0]==y[1]) ? -1 : 64 )) : ((y[0]<y[1]) ? 256+fixtoi(fixatan(fixdiv(itofix(y[1]-y[0]),itofix(x[1]-x[0])))) : ((y[0]==y[1]) ? 0 : fixtoi(fixatan(fixdiv(itofix(y[1]-y[0]),itofix(x[1]-x[0]))))))))%256) : -1; //determine the angle from th computer to the player
8/*8*/ for(i=0;i<2;i++) d<i> = (i==0) ? ((d[0]+256 +(key[KEY_LEFT] ? -4: 0)+(key[KEY_RIGHT] ? 4: 0)+((((x[0]-182)*(x[0]-182)+(y[0]-240)*(y[0]-240))>100*100) ? 0: 25 ) + ((((x[0]-(456))*(x[0]-(456))+(y[0]-240)*(y[0]-240))>95*95) ? 0: -25 ) + ((a==-1) ? 0 : (15-rand()%30)))%256) : (((t <5)&&(x[1] < 197)) ? 0 : (d[1] + (2 * d1m)+256)%256); //change directions
9/*9*/ if (d[1] == 192) d1m *= -1; //change direction of turn for computer
10/*10*/ for(i=0;i<4;i++) circlefill(screen,x[i%2] + ((i<2)? -2 : 0) ,y[i%2] + ((i<2)? 4 : 0),8,8); //clear hovercraft
11/*11*/ for (i=0;i<26;i++) rectfill(screen,172 + ((i>=13) ? 0 :8), 334+ (i%13) *8,180+ ((i>=13) ? 0:8),342+ (i%13) *8,(i%2)*15 ); // draw checkerboard start
12/*12*/ for(i=0;i<2;i++) x<i>=((x<i>+fixtoi(fixcos(itofix(d<i>))*6) < 640)&&(x<i> + fixtoi(fixcos(itofix(d<i>))*6) >= 0)) ? (x<i> + fixtoi(fixcos(itofix(d<i>))*6)+ (((a != -1)&&(i==0)) ? fixtoi(fixcos(itofix(a))*8) : 0)) : x<i> ; //change x pos
13/*13*/ for(i=0;i<2;i++) y<i>=((y<i>+fixtoi(fixsin(itofix(d<i>))*6) < 480)&&(y<i> + fixtoi(fixsin(itofix(d<i>))*6) >= 0)) ? (y<i> + fixtoi(fixsin(itofix(d<i>))*6)+(((a != -1)&&(i==0)) ? fixtoi(fixsin(itofix(a))*8) : 0)) : y<i> ; //change y pos
14/*14*/ for(i=0;i<4;i++) circlefill(screen,x[i%2] + ((i<2)? -2 : 0) ,y[i%2] + ((i<2)? 4 : 0) ,8,(i<2)? 0:(1+2*(i%2))); //draw hovercraft
15/*15*/ for (i=0;i<4;i++) line(screen,x[i%2]+ fixtoi(fixcos( itofix((d[i%2]+64 + (i/2)*128 )%256) )*4),y[i%2] + fixtoi(fixsin(itofix((d[i%2]+64+ (i/2)*128 )%256))*4),x[i%2] + fixtoi(fixcos(itofix((d[i%2]+64+ (i/2)*128)%256))*4)+ fixtoi(fixcos(itofix((d[i%2]+128)%256))*6),y[i%2] + fixtoi(fixsin(itofix((d[i%2]+64+ (i/2)*128 )%256))*4)+ fixtoi(fixsin(itofix((d[i%2]+128)%256))*6),9); //draw fins
16/*16*/ for(i=0;i<2;i++) triangle(screen ,x<i>+ fixtoi(fixcos(itofix((d<i>+64 )%256) )*3),y<i> + fixtoi(fixsin(itofix((d<i>+64 )%256))*3),x<i>+ fixtoi(fixcos(itofix((d<i>+192 )%256) )*3),y<i> + fixtoi(fixsin(itofix((d<i>+192 )%256))*3),x<i>+ fixtoi(fixcos(itofix(d<i>) )*3),y<i> + fixtoi(fixsin(itofix(d<i> ))*3),7); //draw windshields
17/*17*/ if (((x[0]-ngx[gc % 4])*(x[0]-ngx[gc % 4])<(4*4))&& ((y[0]-ngy[gc % 4])*(y[0]-ngy[gc % 4])<(170*170))) gc++; //check checkpoints
18/*18*/ textprintf(screen,font,0,0,15,"Time: %i Laps Left: %i Computer: %i ",(t < 0) ? 0 : t, 4-(gc/4), 4 - (t/256)); //draw lapcount
19/*19*/ } for(;!key[KEY_ESC];)textprintf_centre(screen,font,320,240,15,(gc==16) ? "You Win! Your time was: %i" : "You Lose! The time to beat is: %i" ,t-1); //game over
20/*20*/ }
only twenty lines long... a few are pretty long though... I hope you all enjoy;D;D;D --------------------------------------------- -------------------------- |
Michael Jensen
Member #2,870
October 2002
|
ohhh i didnt know you were supposed to do figure 8s!!!! I thot it was a bug that you had to run two laps last time to get it to go down once...
|
aileron42
Member #3,184
January 2003
|
Oh, sorry.. <><><><><><><><><><><><><><><><><><><><><><><><><> -------------------------- |
Evert
Member #794
November 2000
|
This thread is killing my browser! |
sech
Member #2,271
April 2002
|
141 posts... What's the record? "What are we going to do tonight, Bill?" |
Matthew Leverton
Supreme Loser
January 1999
|
Ok, everone send Evert your code if you have more to contribute. He will make a webpage or something with a download available. Thread closed. He'll create a new one when he's all ready. |
|
|