|
An Allegro Game in 20 lines of code - Possible? |
Matthew Leverton
Supreme Loser
January 1999
|
You can count headers and I'm still under 20. But that 80 character count per line is bogus. |
Thomas Fjellstrom
Member #476
June 2000
|
uuugghhh... Stupid computer. Stupid cat... Just finished writing the previous version of this message when XP decides to blue screen. SOme crappy error about IRQL_NOT_LESS_OR_EQUAL_TO or something. Soo, as with last time I seen that I opened up my case to see whats up... And I tell ya, a half hout later, I was finaly finished putting it all back to gether after ripping everything out to clean. IT was not a pretty sight. I swear there was enough cat fur in there to create another cat. Quote: *cough* maybe we should stop discussing DSP in this thread Oh, that 'Linear interpolation' is for resamplign right? hmm, Alsa-lib seems to do that for me if my card doesn't support the exact htz. Ohhh.. I need to add a cd input plugin maybe a ac3 or a52 plugin as well just to test to see if my code can easily handle more than 2 channels. (It should be easy. ) -- |
Plucky
Member #1,346
May 2001
|
Well somebody was interested in more 3D stuff, so I stuffed a crude voxel terrain engine into ~16 lines of code (actually ~15 if you get rid of the constant string definition on line 2 or perhaps 14 if you also get rid of lmap_c[][] and just use the map bitmap). Not really a game, but perhaps of some interest; you still have ~5 lines left to make a game out of it.;) Same usual stuff: Only one semicolon or bracket {} per line, discounting the semicolons inside a for() expression. No commas except for variable definition and lists of parameter arguments in functions. The engine is set for 32 bit color, which you can change to 15/16/24 bit. Arrow keys to move around. You can also try changing the voxel resolution setting from 3 to 0 to 7. And no optimizations (mostly due to trying to stuff the code), so it may be a bit slow.
You need to create a 512x512 grayscale bitmap (.bmp). Or you can copy the one below, and resave it as a bmp. http://www.geocities.com/sichoy/map.jpg [edit] I forgot to get rid of another line, so it's now 14 or 15 lines, depending on whether you keep the mapfile string. |
Evert
Member #794
November 2000
|
There you go: fox&geese with bugfixes. Should run fine now.;D Man, I spend too much time on these things, but it is fun. If we do want a competition (even if we don't, I think someone should collect all the little gems posted here and upload them somewhere), the most sensible requirement IMHO would be to limit the size of the sourcefile to, say, 2kb, not counting whitespace and comments. #include <allegro.h> #define DRAWTILE(c) rectfill(screen, c/8*(SCREEN_W/8), c%8*(SCREEN_H/8), c/8*(SCREEN_W/8)+(SCREEN_W/8), c%8*(SCREEN_H/8)+(SCREEN_H/8), ((c%8)&1)^((c/8)&1)?0:15), circlefill(screen, goose[0]%8*(SCREEN_W/8)+SCREEN_W/16, goose[0]/8*(SCREEN_H/8)+SCREEN_H/16, SCREEN_W/32, 4), circlefill(screen, goose[1]%8*(SCREEN_W/8)+SCREEN_W/16, goose[1]/8*(SCREEN_H/8)+SCREEN_H/16, SCREEN_W/32, 4), circlefill(screen, goose[2]%8*(SCREEN_W/8)+SCREEN_W/16, goose[2]/8*(SCREEN_H/8)+SCREEN_H/16, SCREEN_W/32, 4), circlefill(screen, goose[3]%8*(SCREEN_W/8)+SCREEN_W/16, goose[3]/8*(SCREEN_H/8)+SCREEN_H/16, SCREEN_W/32, 4), circlefill(screen, fox%8*(SCREEN_W/8)+SCREEN_W/16, fox/8*(SCREEN_H/8)+SCREEN_H/16, SCREEN_W/32, 1), rect(screen, goose[sgoose]%8*(SCREEN_W/8), goose[sgoose]/8*(SCREEN_H/8), goose[sgoose]%8*(SCREEN_W/8)+(SCREEN_W/8)-1, goose[sgoose]/8*(SCREEN_H/8)+(SCREEN_H/8)-1, 14) int main(void) { int goose[4] = {63,61,59,57}, sgoose = 0, fox = 4, turn = 0, done = 0, drawme = 1, c; allegro_init(), install_keyboard(), install_timer, install_mouse(),set_gfx_mode(GFX_AUTODETECT, 256,256,0,0), clear_to_color(screen, 15), text_mode(-1), show_mouse(screen); while (!key[KEY_ESC] && !done) { turn ? ( (fox%8!=7) ? fox-=((goose[0]==fox+9||goose[1]==fox+9||goose[2]==fox+9||goose[3]==fox+9)?0:(9*(key[KEY_S]?turn=0,drawme=1,-1:0))):0,(fox%8!=0) ? fox-=((goose[0]==fox+7||goose[1]==fox+7||goose[2]==fox+7||goose[3]==fox+7)?0:(7*(key[KEY_A]?turn=0,drawme=1,-1:0))):0,(fox%8!=0 && fox>8) ? (fox +=((goose[0]==fox-9||goose[1]==fox-9||goose[2]==fox-9||goose[3]==fox-9)?0:(9*(key[KEY_Q]?turn=0,drawme=1,-1:0)))):0, (fox%8!=7 && fox>8) ? (fox +=((goose[0]==fox-7||goose[1]==fox-7||goose[2]==fox-7||goose[3]==fox-7)?0:(7*(key[KEY_W]?turn=0,drawme=1,-1:0)))):0 ):( sgoose=( sgoose + (key[KEY_TAB]?(rest(100), drawme=1):0) )&3, (goose[sgoose]%8!=0 && goose[sgoose]>8) ? (goose[sgoose] += (goose[sgoose]-9==fox?0:9*(key[KEY_LEFT]?turn=1,drawme=1,-1:0))) :0, (goose[sgoose]%8!=7 && goose[sgoose]>8) ? (goose[sgoose] += (goose[sgoose]-7==fox?0:7*(key[KEY_RIGHT]?turn=1,drawme=1,-1:0))):0); if (drawme) for(c=0;c<64;c++){ scare_mouse(), DRAWTILE(c), unscare_mouse(), drawme = 0; } done = (fox>56 || (goose[0]<8 && goose[1]<8 && goose[2]<8 && goose[3]<8)) || ( (goose[0]+goose[1]+goose[2]+goose[3]==4*fox) && (abs(fox-goose[0])==7 || abs(fox-goose[0]==9)) ) ? 1:0; } while(keypressed()) readkey(); return done?textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2, 2, (fox>56)?"Fox wins!":"Geese win!"), readkey(), 0:0; } END_OF_MAIN()
|
white_door
Member #202
April 2000
|
This is a little piece of a rpg.. the battle between the forces of good rabbits and evil rabbits. Who will win? (designed to be like a final fantasy like battle) [edit added srand(NULL);] #include <allegro.h> #include <string.h> #include <stdlib.h> /*01*/BITMAP *draw_char(BITMAP *buffer,int x,int y,int half_w,int half_h,int facing) {int gen[32]={half_w,0,half_w/4,-half_h/4,half_w/8,-half_h/2,half_w/8,-half_h*3/4,half_w/4,-half_h*3/4,half_w/2,-half_h/4,half_w*3/4,-half_h/4,half_w*3/4,-half_h/2,half_w,-half_h/2,half_w,-half_h*3/4,half_w/4,half_h/4,half_w/2,half_h*3/4,half_w,half_h*3/4,half_w,half_h,half_w/4,half_h,0,half_h/2},side1[32]={x+gen[0],y+gen[1],x+gen[2],y+gen[3],x+gen[4],y+gen[5],x+gen[6],y+gen[7],x+gen[8],y+gen[9],x+gen[10],y+gen[11],x+gen[12],y+gen[13],x+gen[14],y+gen[15],x+gen[16],y+gen[17],x+gen[18],y+gen[19],x+gen[20],y+gen[21],x+gen[22],y+gen[23],x+gen[24],y+gen[25],x+gen[26],y+gen[27],x+gen[28],y+gen[29],x+gen[30],y+gen[31]},side2[32]={x-gen[0],y+gen[1],x-gen[2],y+gen[3],x-gen[4],y+gen[5],x-gen[6],y+gen[7],x-gen[8],y+gen[9],x-gen[10],y+gen[11],x-gen[12],y+gen[13],x-gen[14],y+gen[15],x-gen[16],y+gen[17],x-gen[18],y+gen[19],x-gen[20],y+gen[21],x-gen[22],y+gen[23],x-gen[24],y+gen[25],x-gen[26],y+gen[27],x-gen[28],y+gen[29],x-gen[30],y+gen[31]}; /*02*/(facing)?polygon(buffer,16,side1,makecol(255,0,0)):polygon(buffer,16,side2,makecol(0,0,255)); /*03*/return buffer; /*04*/} void main() {BITMAP game_state={/*int 7*/0,(allegro_init()||install_timer()||install_keyboard()||set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,200,0,0))?-1:50,text_mode(-1),40,100,80,100,/*pointers 4*/NULL,NULL,NULL,NULL,/*long int*/0,/*pointer*/NULL,/*int 3*/270,130,0},game_state2={/*int 7*/5,10,0,0,0,0,0,/*pointers 4*/NULL,NULL,NULL,NULL,/*long int*/0,/*pointer*/NULL,/*int 3*/0,0,0},*buffer=create_bitmap(320,200); /*05*/srand(time(NULL)); /*06*/while((game_state.cr>0||game_state.ct>0)&&memset(buffer->dat,0,320*200)&&game_state.h>0&&!key[KEY_DOWN]|(game_state.w=0)) while(game_state.w++<12)(game_state.w==1) ? textprintf(buffer,font,10,10,makecol(0,255,0),"Push [left] for magic"):(game_state.w==2) ? textprintf(buffer,font,10,20,makecol(0,255,0),"Push [up] for attack"):(game_state.w==3)?textprintf(buffer,font,10,30,makecol(0,255,0),"Push [Down] to Run"):(game_state.w==4)?((key[KEY_UP]&&game_state.seg==0&&game_state.ct>0)? game_state.seg=30*(game_state.id=1) : (key[KEY_LEFT]&&game_state.seg==0&&game_state.cr>0)? game_state.seg=15*(game_state.id=2) : (game_state.seg>0)? rest(game_state.seg--): (game_state.id==4)? game_state.id=(game_state.h-=(rand())%20) : (game_state.id==1)?(game_state.id=((game_state2.w-=(1+rand()%3))>0)?0*(game_state.seg=25)+4:(game_state.ct=-30)):(game_state.id==2)?(game_state.id=((game_state2.h-=(1+rand()%3))>0)?(game_state.seg=25)*0+4:(game_state.cr=-30)):rest(1)):(game_state.w==5)?((game_state.id==1)? line(buffer,game_state.ct+game_state.seg,game_state.cb+game_state.seg,game_state.ct+game_state.seg+20,game_state.cb+game_state.seg+20,makecol(255,200,200)): rest(1)):(game_state.w==6)?((game_state.id==2)?circle(buffer,game_state.cl,game_state.cr,game_state.seg,makecol(255,255,255)):rest(1)):(game_state.w==7)?(void)draw_char(draw_char(draw_char(buffer,game_state.ct,game_state.cb,20,20,TRUE),game_state.cl,game_state.cr,20,20,TRUE),game_state.x_ofs,game_state.y_ofs,20,20,FALSE):(game_state.w==8)?line(buffer,game_state.x_ofs-33,game_state.y_ofs+23,game_state.x_ofs-33+game_state.h,game_state.y_ofs+23,makecol(0,255,0)):(game_state.w==9)?line(buffer,game_state.ct+13,game_state.cb+23,game_state.ct+13+game_state2.w,game_state.cb+23,makecol(0,255,0)):(game_state.w==10)?line(buffer,game_state.cl+13,game_state.cr+23,game_state.cl+13+game_state2.h,game_state.cr+23,makecol(0,255,0)):(game_state.w==11)?(game_state.id==4)?line(buffer,game_state.x_ofs-20+game_state.seg,game_state.y_ofs+game_state.seg,game_state.x_ofs+game_state.seg,game_state.y_ofs+game_state.seg+20,makecol(255,200,200)):rest(1):blit(buffer,screen,0,0,0,0,320,200); /*07*/while(!key[KEY_ESC])(game_state.cr<0&&game_state.ct<0)? (textprintf_centre(screen,font,160,100,makecol(0,255,0),"You win! Push [Esc] to quit")):(textprintf_centre(screen,font,160,100,makecol(0,255,0),"You lose! Push [Esc] to quit")); } END_OF_MAIN()
|
Evert
Member #794
November 2000
|
Nice! But is it at all possible to win? I get trashed each time round... |
white_door
Member #202
April 2000
|
hehe well it depends on your compiler.. on my computer I win.. so.. hmm anyway its easy enough to add a srand(time(NULL)); with out pushing it past the limit. |
Oscar Giner
Member #2,207
April 2002
|
Here's my game. It's some kind of space shoter, but with circles. You're the yellow circle and enemies are the red ones. You move with the arrows and shot a blue circle with the rigth control. If an enemy collides with you... you lose! Compiles without any warning with -Wall
It was very funny to program, and I thing it's very funny to play Note: 100% original. I didn't look at any of your programs until I've finished this. -- |
miran
Member #2,407
June 2002
|
You do know what the word funny means, right? And that think is spelled with a k? Sorry 'bout that but I just had to... BTW, I thought that whole funny business was a German thing or something... -- |
Bruce Perry
Member #270
April 2000
|
Let's clarify... "Funny" can mean either "causing laughter" or "strange". Things that are funny can be fun, and vice versa, of course ... and you flame me for going on about "it's" ... -- |
Peter Wang
Member #23
April 2000
|
Just to complete the collection of 20 line interpretations of classic games, here's Pacman: 1#include <allegro.h>
2/*01*/int main(int dots, char**bmp){int x[]={6*20,5*20,6*20,7*20,6*20},y[]={14*20,7*20,7*20,7*20,6*20},dx[]={1,0,0,0,0},dy[]={0,0,0,0,0},dir,wantdir=0,ddx[]={1,0,-1,0},ddy[]={0,-1,0,1},map[16][13]={{1,1,1,1,1,1,1,1,1,1,1,1,1},{1,2,2,2,2,2,2,2,2,2,2,2,1},{1,2,1,1,2,2,1,2,2,1,1,2,1},{1,2,1,2,2,1,1,1,2,2,1,2,1},{1,2,1,2,2,2,1,2,2,2,1,2,1},{1,2,2,2,2,2,2,2,2,2,2,2,1},{1,1,1,2,1,2,2,2,1,2,1,1,1},{0,0,1,2,1,2,2,2,1,2,1,0,0},{1,1,1,2,1,1,1,1,1,2,1,1,1},{1,2,2,2,2,2,2,2,2,2,2,2,1},{1,2,2,1,1,1,2,1,1,1,2,2,1},{1,2,2,2,1,2,2,2,1,2,2,2,1},{1,2,1,2,2,2,1,2,2,2,1,2,1},{1,2,1,1,2,1,1,1,2,1,1,2,1},{1,2,2,2,2,2,0,2,2,2,2,2,1},{1,1,1,1,1,1,1,1,1,1,1,1,1}},*tmp,i,j,c[5],pdir=0,gobble=0;
3/*02*/for((void)((!allegro_init()&&!install_keyboard()&&!install_timer()&&!set_gfx_mode(GFX_AUTODETECT,640,480,0,0)&&(((int(*)())srand)(time(0))*0+1)&&(bmp=(char**)create_bitmap(13*20,16*20))&&(dots=101)&&(c[0]=makecol(255,255,0))&&(c[1]=makecol(255,0,255))&&(c[2]=makecol(255,200,200))&&(c[3]=makecol(0,255,255))&&(c[4]=makecol(255,0,0)))||((int(*)())exit)(0));!key[KEY_ESC]&&dots>0&&((!dx[0]&&!dy[0])||(gobble=gobble+4>40?-39:gobble+4)|1);blit((BITMAP*)bmp,screen,((int(*)())rest)(10)*0,0,190,80,13*20,16*20)){for(i=0;i<5;i++)if(map[(y<i>+dy<i>+((dy<i>>0)?19:0))/20][(x<i>+dx<i>+((dx<i>>0)?19:0))/20]==1)dx<i>=dy<i>=0;
4/*03*/for(wantdir=key[KEY_UP]?1:key[KEY_DOWN]?3:key[KEY_LEFT]?2:key[KEY_RIGHT]?0:wantdir,i=0;i<5;i++){if((tmp=&map[((y<i>+=dy<i>)+10)/20][((x<i>+=dx<i>)+10)/20])&&!i)*tmp=(dots-=*tmp==2)*0;
5/*04*/if(!(x<i>%20)&&!(y<i>%20)&&(dir=!i?wantdir:((rand()%10)-6))>=0&&map[(y<i>+ddy[dir]+((ddy[dir]>0)?19:0))/20][(x<i>+ddx[dir]+((ddx[dir]>0)?19:0))/20]!=1)pdir=!i?dir:pdir,dx<i>=ddx[dir],dy<i>=ddy[dir];}
6/*05*/for(i=1;i<5;i++)if(fixhypot(itofix(x<i>-x[0]),itofix(y<i>-y[0]))<itofix(16))dots=-1;
7/*06*/for(j=0;j<16;j++)for(i=0;i<13;i++){rectfill((BITMAP*)bmp,i*20,j*20,i*20+19,j*20+19,makecol(0,map[j]<i>==1?255:0,0));
8/*07*/if(map[j]<i>==2)circlefill((BITMAP*)bmp,i*20+10,j*20+10,2,makecol(255,255,200));}
9/*08*/arc((BITMAP*)bmp,x[0]+10,y[0]+10,itofix(pdir*64+ABS(gobble)),itofix(pdir*64+255-ABS(gobble)),8,c[0]);
10/*09*/line((BITMAP*)bmp,x[0]+10,y[0]+10,x[0]+10+fixtoi(fcos(itofix(pdir*64+ABS(gobble)))*8),y[0]+10-fixtoi(fsin(itofix(pdir*64+ABS(gobble)))*8),c[0]);
11/*10*/line((BITMAP*)bmp,x[0]+10,y[0]+10,x[0]+10+fixtoi(fcos(itofix(pdir*64+255-ABS(gobble)))*8),y[0]+10-fixtoi(fsin(itofix(pdir*64+255-ABS(gobble)))*8),c[0]);
12/*11*/floodfill((BITMAP*)bmp,x[0]+10+(!pdir?-5:5),y[0]+10,c[0]);
13/*12*/for(i=1;i<5;i++){circlefill((BITMAP*)bmp,x<i>+10,y<i>+10,8,c<i>);
14/*13*/circlefill((BITMAP*)bmp,x<i>+7,y<i>+7,3,makecol(255,255,255));
15/*14*/circlefill((BITMAP*)bmp,x<i>+13,y<i>+7,3,makecol(255,255,255));
16/*15*/circlefill((BITMAP*)bmp,x<i>+8,y<i>+7,0,0);
17/*16*/circlefill((BITMAP*)bmp,x<i>+12,y<i>+7,1,0);}}
18/*17*/if(dots<=0){textout_centre(screen,font,!dots?"You win!":"You lose!",320,220,makecol(255,255,255));
19/*18*/rest(2000);}
20/*19*/destroy_bitmap((BITMAP*)bmp);
21/*20*/return 0;}END_OF_MAIN()
I think I followed the "rules". If not, fsck it.
|
Thomas Fjellstrom
Member #476
June 2000
|
You suck. I thought about doing a pacman.. But oh well. Though, the rules say semi-colon delimited... But it brobably wouldn't be hard to fix... -- |
Bruce Perry
Member #270
April 2000
|
Ooh, casting function pointers to get around the void return values... not portable I almost used raise(SIGABRT), which returns int, in my game, but in the end I didn't need it. One or two bugs(?) in the game, namely that the whole background goes yellow whenever his mouth is closed, and the thingy doesn't stop moving when I let go of the keys (I wish he would). Otherwise works well -- |
Thomas Fjellstrom
Member #476
June 2000
|
he's not supposed to stop moving.. When was the last time you played pacman? -- |
aileron42
Member #3,184
January 2003
|
Well, I just joined {allegro.cc} tonight. I've been reading the forums for a while and decided it was time I gave my two cents, or in this case, my twenty lines. here goes...
It is a top view car racing game. No opponent, just a time trial though. Figur eights around the two circles. I hope you enjoy -------------------------- |
Peter Wang
Member #23
April 2000
|
Bruce: I can't reproduce the yellow background problem. Maybe floodfill() got changed at some stage, although I tested both stable and unstable Allegros.
|
Michael Jensen
Member #2,870
October 2002
|
I couldnt get pacman to compile at all... This is the first thread that I've read on allegro.cc in about a week or two and I decided to try to do the challenge, It's not an rpg but its tile based...... I did some things that may be considered cheap and cheating but I kept my code under 20 lines (19 I think) and no line has more than one semi colon on it.... the actual .cpp file is just under 5kb.... 1/*God is awesome*/ #include <allegro.h>
2#define set(a,b) {a=b;}
3#define im_a_cheater(x,y,s) {score+=s;set(grid[x][y],0)}
4#define cheat2(a,b,c,d,e,f,g) {textprintf(a,b,c,d,e,f,g);} // -- is this cheating? :-)
5int slowdown_variable=FALSE; //for fps
6void slowdown_function(void){set(slowdown_variable,TRUE)} END_OF_FUNCTION(slowdown_function) int main(void){LOCK_VARIABLE(slowdown_variable)LOCK_FUNCTION(slowdown_function) if ((allegro_init()==0) && (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0)==0) && (!install_keyboard()) && (!install_int(slowdown_function, 150))){srand((unsigned)time(NULL)); ///setup allegro randomize timer
7BITMAP * apage=create_bitmap(SCREEN_W, SCREEN_H); //backbuffer
8clear_to_color(apage,makecol(0,0,0)); //clear the backbuffer
9int grid[40][25]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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EY_4_PAD, KEY_5_PAD, KEY_6_PAD, KEY_1_PAD, KEY_2_PAD, KEY_3_PAD}, movin=FALSE; //setup game & variables
10while(alive && !key[KEY_ESC]){int x=rand()%40, y=rand()%24, t=(rand()%2)+1; //main while loop
11if (grid[px][py]==1){im_a_cheater(px,py,1)} else if (grid[px][py]==2){set(alive,FALSE)} if (x!=px || y!=py){set(grid[x][y],t)} if (grid[x][y]==1){cheat2(apage, font,x*8, (y+1)*8, makecol(0,255,0), "$", px)} else {rectfill(apage, x*8, (y+1)*8, ((x+1)*8)-1, ((y+2)*8)-1, makecol(192,192,192));} //check for death/score then place new item & draw money and bricks only one semicolon
12cheat2(apage, font, 0, 0, makecol(255,255,255), "SCORE: %d", score) /*im_a_cheater(0,24,1)*/ circlefill(apage, (px*8)+3, ((py+1)*8)+3, 2, makecol(255,255,0));
13blit(apage,screen, 0,0,0,0, SCREEN_W, SCREEN_H);
14rectfill(apage,px*8, (py+1)*8, ((px+1)*8)-1, ((py+2)*8)-1,makecol(0,0,0));
15set(movin,FALSE) while(!slowdown_variable || !movin){for (int j=0; j<9; j++){if ((!movin) && (key[controls[j]] || key[controls2[j]]) && (py+move[j/3]<24) && (py+move[j/3]>-1) && ((px+move[j%3])<40) && (px+move[j%3]>-1)){//stuff inside the for ()s doesn't count right?
16py+=move[j/3];
17px+=move[j%3]; if (!key[KEY_ESC]){while(key[controls[j]] || key[controls2[j]]){}} set(movin,TRUE)}}
18}set(slowdown_variable,FALSE)}cheat2(screen, font, 0, 0, makecol(255,0,0), "SCORE: %d (GAME OVER PRESS ENTER)", score) while (!key[KEY_ENTER]){} allegro_exit();} //shutting down & end of while, & then end of if
19return(0);}END_OF_MAIN()//exiting
if there is word wrap on here it might not be under 20 lines on here, but the .cpp file i have is under 20 with no more than 1 semicolon per line..... anyways its a remake of an old game that I made (first game I ever made) on my b&w trs-80 model 4 computer with basic.....(it was in textmode) Bricks & Money "fall", if you walk on the money -- you get a point and it disappears, if you walk on the bricks you die, esc quits, dont hold keys down -- tap them (sorry bout this, its hard to do good keyboard routines in a couple of lines -- for me anyways) It gets interesting once you're score is about 200 - 300, which is a while to wait...
|
Bruce Perry
Member #270
April 2000
|
Michael: compile Pacman as C, not C++. He uses some function pointers with "()" for the parameters; in C this means 'parameter number and types unknown', while in C++ it means 'no parameters'. -Wstrict-prototypes is a good warning... -- |
Michael Jensen
Member #2,870
October 2002
|
by the way I lied about my game -- the line with the for loop has two semicolons I think... Quote: the .cpp file i have is under 20 with no more than 1 semicolon per line.....
oh cool no warnings this time... thanks BP! -- but it's tilebased -- since when is pacman tilebased?
|
23yrold3yrold
Member #1,134
March 2001
|
Quote: since when is pacman tilebased? Since when isn't it? -- |
Michael Jensen
Member #2,870
October 2002
|
since forever! -- the walls are always thin and the pathways wide -- if you can call that tilebased, maybe it is, but I dont see how at this point....
|
spellcaster
Member #1,493
September 2001
|
Pacman is one of the traditional tile based examples.. -- |
23yrold3yrold
Member #1,134
March 2001
|
Pac-Man is soooo tile-based! Not terribly attractive tiles, but tiles all the same. BTW, this thread is a good example of why we need pages in the forums. How's that coming, Matthew? -- |
Michael Jensen
Member #2,870
October 2002
|
thats not the origonal pacman just cause you can do it with tiles doesn't make it right -- if you look at it in the offical games it becomes very hard for me to divide it into tiles... maybe it is tilebased -- but I doub't it -- I have it on 2600 and 800XL (those are ataris) edit: the walls arn't just tiles that have skinnier wall graphics, they're actually graphically offset as far as I can tell..... from what I've been looking at it would take more tiles than my atari had memory for if pacman is tile based them maybe some people are just better at hiding it than others cause it really doesnt seem like it is. edit2: IMO you'd have to have 4 different tile sizes (on the same map) and a lot of tile graphics to do it right.... edit3: I'm starting to think maybe pacman is tilebased -- but I know that people have done it non tile based, and I know that this isn't the origonal pacman but it's very hard for me to see tiles in it for example, maybe you could show me how you would divide it into equal tiles... http://www.geocities.com/michael_jensen419/level.gif
|
spellcaster
Member #1,493
September 2001
|
The original pacman: Edit: -- |
|
|