示例#1
0
文件: nupac.cpp 项目: laulandne/src
bool update(void)
{
  bool GotEm, GotEm0, GotEm1, GotEm2, GotEm3;
  MoveGhost(&Ghost0); MoveGhost(&Ghost1); MoveGhost(&Ghost2);
  MoveGhost(&Ghost3); MovePac(&Pac);
  if(BlueCount) TheBlue();
  GotEm0=false; GotEm1=false; GotEm2=false; GotEm3=false;
  if((Pac.bx==Ghost0.bx)&&(Pac.by==Ghost0.by)) { GotEm=true; GotEm0=true; }
  if((Pac.bx==Ghost1.bx)&&(Pac.by==Ghost1.by)) { GotEm=true; GotEm1=true; }
  if((Pac.bx==Ghost2.bx)&&(Pac.by==Ghost2.by)) { GotEm=true; GotEm2=true; }
  if((Pac.bx==Ghost3.bx)&&(Pac.by==Ghost3.by)) { GotEm=true; GotEm3=true; }
  if(GotEm) {
    if(GotEm0) {
      if(Ghost0.lastint==G_SCARED) DoEyes(&Ghost0);
      if(Ghost0.lastint==G_SMART) DoDie();
    }
    if(GotEm1) {
      if(Ghost1.lastint==G_SCARED) DoEyes(&Ghost1);
      if(Ghost1.lastint==G_SMART) DoDie();
    }
    if(GotEm2) {
      if(Ghost2.lastint==G_SCARED) DoEyes(&Ghost2);
      if(Ghost2.lastint==G_SMART) DoDie();
    }
    if(GotEm3) {
      if(Ghost3.lastint==G_SCARED) DoEyes(&Ghost3);
      if(Ghost3.lastint==G_SMART) DoDie();
    }
  }
  if(NumDots==0) {
    WAITING=false; DIED=false;
  }
  //update_window(destw);
  return GotEm;
}
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;
}