void MainLoop() { DrawWindow(); wrefresh(win); wrefresh(status); usleep(1000000); do { MovePacman(); DrawWindow(); CheckCollision(); MoveGhosts(); DrawWindow(); CheckCollision(); if(Points > FreeLife) { Lives++; FreeLife *= 2;} Delay(); } while (Food > 0); DrawWindow(); usleep(1000000); }
int pacman_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile ) { struct timeval tv; int x; int jumplevel=-1; if ( FBInitialize( 720, 576, 8, fdfb ) < 0 ) return -1; setup_colors(); if ( RcInitialize( fdrc ) < 0 ) return -1; InitLevel( 0 ); while( doexit != 3 ) { MazeInitialize(); DrawMaze( ); /* 0 = all */ DrawFill(); DrawGhosts( ); DrawPac( ); MazePig(); doexit=0; while( !doexit ) { tv.tv_sec = 0; #ifdef HAVE_DREAMBOX_HARDWARE tv.tv_usec = 8000; #else tv.tv_usec = 1000; #endif x = select( 0, 0, 0, 0, &tv ); /* 10ms pause */ MovePac( ); MoveGhosts( ); DrawGhosts( ); DrawPac( ); #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif RcGetActCode( ); CheckGhosts( ); } if ( doexit != 3 ) { actcode=0xee; if ( score ) DrawScore(); if ( !gametime ) DrawGameOver(); #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif doexit=0; jumplevel=-1; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); if ( actcode == RC_HELP ) { while( realcode != 0xee ) RcGetActCode( ); actcode=0xee; while(( actcode == 0xee ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } if ( actcode <= RC_9 ) { jumplevel=actcode; actcode=RC_OK; } } } if ( gametime ) NextLevel(); else InitLevel( jumplevel ); } } Fx2StopPig(); /* fx2 */ /* buffer leeren, damit neutrino nicht rumspinnt */ realcode = RC_0; while( realcode != 0xee ) { tv.tv_sec = 0; tv.tv_usec = 300000; x = select( 0, 0, 0, 0, &tv ); /* 300ms pause */ RcGetActCode( ); } RcClose(); FBClose(); return 0; }
PlayMaze() { PrintStatus(); /* Prints the score and everything else */ BlackOut(ALLBLACK); /* Hide the reconstruction of the viewPort */ WaitTOF(),WaitTOF(); /* Wait for the Blackout to finish */ InitializeStarting(); ScrollDisplay(SCROLLDEFINITELY); killallsound(); button=0; joyx=0; joyy=0; /* Initialize Joy Regs */ JoyRead(CTRLR_RESET); while(!(joyx || joyy)) { WaitTOF(); JoyRead(CTRLR_READ); } playsound(SND_BACKGRND,0),playsound(SND_BACKGRND,0); SetAPen(rastport,PATHCOLOR); /* We will be erasing dots */ for(i=0; i<numghosts; i++) energized[i]=0; while(dead>=0 && numdots) { tx=xposn[0]+XOFF; ty=yposn[0]+YOFF; if(tx>=minx-1 && tx<=maxx+1 && ty>=miny-1 && ty<=maxy+1) { lookhere=ReadPixel(rastport,tx+x_dir,ty+y_dir); if(lookhere==DOTCOLOR) { atedot++; WritePixel(rastport,tx+x_dir,ty+y_dir); INCSCORE(10); if(--numdots==advspeed[speedindex]) { speedindex++; if(killsound(SND_BACKGRND)) playsound(SND_BACKGRND,0),playsound(SND_BACKGRND,0); } playsound(SND_DOT,1); } else if(lookhere==ENERGCOLOR) { atedot=1; for(i=-1; i<2; i++) for(c=-1; c<2; c++) /* Erase energizer */ WritePixel(rastport,tx+(x_dir<<1)+c,ty+(y_dir<<1)+i); INCSCORE(50); if(--numdots==advspeed[speedindex]) { speedindex++; if(killsound(SND_BACKGRND)) playsound(SND_BACKGRND,0),playsound(SND_BACKGRND,0); } playsound(SND_DOT,1); Energize(); } } if((!joyx)^(!joyy)) joy_dir =(joyy)?(1+joyy):(2-joyx); if(x_dir || y_dir) dir_code=(y_dir)?(1+y_dir):(2-x_dir); dvx=xposn[0]+XOFF-pdest_v->x; dvy=yposn[0]+YOFF-pdest_v->y; old_dcode = dir_code; if((ABS(dvx)+ABS(dvy))<2 && joy_dir!=dir_code && pdest_v->next[joy_dir]) { dir_code = joy_dir; dvx=0; dvy=0; xposn[0]=pdest_v->x-XOFF; yposn[0]=pdest_v->y-YOFF; at_vertex = TRUE; } else at_vertex=((!dvx && !dvy) || (x_dir==y_dir)); if ((!joyx)^(!joyy)) /* if joy movement */ { if (at_vertex) { if(joyx && pdest_v->next[joy_dir] && !(pdest_v->code[joy_dir]&FORBID)) { pmv=pdest_v; pdest_v=pdest_v->next[joy_dir]; /* Destination vertex */ x_dir=joyx; /* Direction we are now headed */ y_dir=0; } else if(joyy && pdest_v->next[1+joyy] && !(pdest_v->code[1+joyy]&FORBID)) { pmv=pdest_v; pdest_v=pdest_v->next[1+joyy]; x_dir=0; y_dir=joyy; } else if ((!(pdest_v->next[joy_dir]) || (pdest_v->code[joy_dir]&FORBID)) && ((!(pdest_v->next[old_dcode]) || (pdest_v->code[old_dcode]&FORBID)))) /* If(at_vertex && no (allowable) next vertex) dead end;stop */ { x_dir=0; y_dir=0; } else if (x_dir||y_dir) /* Joy in invalid dir on vertex */ { pmv=pdest_v; /* There is a path in current dir - follow it */ pdest_v=pdest_v->next[old_dcode]; dir_code = old_dcode; } } /* End of block for if at a vertex */ else if (joyx && !(joyx+x_dir)) /* Reverses direction on edge */ { x_dir=-x_dir; /* Reverse current direction */ tv=pdest_v; /* Swap pdest_v with last vertex */ pdest_v=pmv; pmv=tv; } else if (joyy && !(joyy+y_dir)) /* Reverses dir along y */ { y_dir=-y_dir; /* Reverse current direction */ tv=pdest_v; /* Swap pdest_v with last vertex */ pdest_v=pmv; pmv=tv; } } /* End of block for if no button but movement on joystick */ else if (at_vertex && (y_dir || x_dir)) /* move but no joymove */ { if(x_dir && (!pdest_v->next[old_dcode] || (pdest_v->code[old_dcode]&FORBID))) x_dir=0;/* Stop @ Dead End */ else if(y_dir && (!pdest_v->next[old_dcode] || (pdest_v->code[old_dcode]&FORBID))) y_dir=0; else { pmv=pdest_v; /* Continue moving to next vertex */ pdest_v=pdest_v->next[old_dcode]; } } if (atedot<2) { xposn[0]+=x_dir; yposn[0]+=y_dir; } else atedot=0; WrapSprite(0,x_dir,y_dir); /* Wrap around routine */ spoff=((xposn[0]+yposn[0])>>1)&3; spoff=(spoff>2) ? (1+3*dir_code) : (spoff+3*dir_code); ChangeSprite(svp,&sprite[0],(short *)(pacmen+spoff)); if ((dead=MoveGhosts())<0) { dead=-1; --lives; /* Kill a PACMAN */ Die(); } else { ScrollDisplay(SCROLLMAYBE); PrintScore(); } if(dead>0) { killallsound(); playsound(SND_MONSTER,1); playsound(SND_MONSTER,1); DeEnergize(dead-1,0); /* Eat a ghost! */ playsound(SND_EYES,0); } JoyRead(CTRLR_READ); } /* End of main control loop */ return 0; } /* End of loop to decrement lives. */