Beispiel #1
0
void CGpApp::CollisionPlayerMissilesAndEnemies()
{
	for (INT sourceIndex = 0; sourceIndex != MISSILEMAX; ++sourceIndex)
	{
		if (LC_TRUE == m_PlayerMissiles[sourceIndex].nAlive)
		{
			for (INT targetIndex = 0; targetIndex != ENEMIESMAX; ++targetIndex)
			{
				if (LC_TRUE == m_Enemies[targetIndex].nAlive)
				{
					if (LC_OK <= LCXCollisionRect2RectLTWH(
						m_PlayerMissiles[sourceIndex].m_pos.x, m_PlayerMissiles[sourceIndex].m_pos.y,
						(FLOAT)MISSILE_WIDTH, (FLOAT)MISSILE_HEIGHT,
						m_Enemies[targetIndex].m_pos.x, m_Enemies[targetIndex].m_pos.y,
						(FLOAT)ENEMY_WIDTH, (FLOAT)ENEMY_HEIGHT))
					{
						m_PlayerMissiles[sourceIndex].nAlive = LC_FALSE;
						m_Enemies[targetIndex].nAlive = LC_FALSE;

						m_Score += 100;

						UpdateHighScore();

						DrawScore();

						m_pSnd[2]->Play();

						break;
					}
				}
			}
		}
	}
}
void DrawPlayScreen (void)
{
	int	i,j,p,m;
	unsigned	temp;

	VW_FadeOut ();

	temp = bufferofs;

	CA_CacheGrChunk (STATUSBARPIC);

	for (i=0;i<3;i++)
	{
		bufferofs = screenloc[i];
		DrawPlayBorder ();
		VWB_DrawPic (0,200-STATUSLINES,STATUSBARPIC);
	}

	bufferofs = temp;

	UNCACHEGRCHUNK (STATUSBARPIC);

	DrawFace ();
	DrawHealth ();
	DrawLives ();
	DrawLevel ();
	DrawAmmo ();
	DrawKeys ();
	DrawWeapon ();
	DrawScore ();
}
int QuiesceChecks(POS *p, int ply, int alpha, int beta, int *pv)
{
  int stand_pat, best, score, move, new_pv[MAX_PLY];
  int is_pv = (beta > alpha + 1);
  MOVES m[1];
  UNDO u[1];

  if (InCheck(p)) return QuiesceFlee(p, ply, alpha, beta, pv);

  nodes++;
  CheckTimeout();
  if (abort_search) return 0;
  *pv = 0;
  
  if (IsDraw(p)) return DrawScore(p);

  if (ply >= MAX_PLY - 1)
    return Eval.Return(p, 1);

  best = stand_pat = Eval.Return(p, 1);

  if (best >= beta) return best;
  if (best > alpha) alpha = best;

  if (TransRetrieve(p->hash_key, &move, &score, alpha, beta, 0, ply))
     return score;

  InitCaptures(p, m);
  while ((move = NextCaptureOrCheck(m))) {

    p->DoMove(move, u);
    if (Illegal(p)) { p->UndoMove(move, u); continue; }

    score = -Quiesce(p, ply + 1, -beta, -alpha, new_pv);

    p->UndoMove(move, u);
    if (abort_search) return 0;

    if (score >= beta) {
      TransStore(p->hash_key, move, score, LOWER, 0, ply);
        return score;
    }

    if (score > best) {
      best = score;
      if (score > alpha) {
        alpha = score;
        BuildPv(pv, new_pv, move);
      }
    }
  }

  if (*pv) TransStore(p->hash_key, *pv, best, EXACT, 0, ply);
  else     TransStore(p->hash_key, 0, best, UPPER, 0, ply);

  return best;
}
//ボール発射待機中の画面を描画	
void Standby_Draw(Gamedata& gameData){
	PictureMap& g = gameData.graphicData;
	DrawBlocks(gameData);
	if(gameData.intervalVisibleObjs["ready_logo"].Visible()){
		if(DrawGraph(READY_X, READY_Y, g["ready"], TRUE) == -1){
			pd("ready_logo");
		}
	}
	DrawBars(gameData);
	DrawScore(gameData);
}
Beispiel #5
0
static void AddScore(struct state *st, int xlim, int ylim, long dif)
{
  int i, sumlive = 0;
  for (i=0;i<kNumCities;i++)
	 sumlive += st->city[i].alive;
  if (sumlive == 0)
	 return;   /* no cities, not possible to score */

  st->score += dif;
  if (st->score > st->highscore)
	 st->highscore = st->score;
  DrawScore(st, xlim, ylim);
}
Beispiel #6
0
/***********************
* Draw: Draws all the entities that make up the level
* @author: Callan Moore
* @author: JC Fowles
* @return: void
********************/
void CLevel::Draw()
{
	m_pProjectile->Draw();
	m_pPlayerShip->Draw();
	

	for( unsigned int i = 0; i < m_pAlienColumns->size(); i++)
	{
		((*m_pAlienColumns)[i])->Draw();
	}

	DrawScore();
	//draw all things 
}
Beispiel #7
0
 void World::Draw()
 {
     if(m_state == IDLE)
     {
         if(m_texBanner != nullptr && m_texBanner->GetTexId() != 0)
         {
             DrawBanner();
         }
     }
     else if(m_state == PLAYING)
     {
         DrawPlayField();
         DrawScore();
         DrawBall();
         DrawPlayer1();
         DrawPlayer2();
     } 
     else if(m_state == GAMEOVER) 
     {
         glClear(GL_COLOR_BUFFER_BIT);
         DrawPlayField();
         DrawScore();
     }
 }
Beispiel #8
0
//-----------------------------------------------------------------------------
// Name : DrawObjects () (Private)
// Desc : Draws the game objects
//-----------------------------------------------------------------------------
void CGameApp::DrawObjects()
{
	m_pBBuffer->reset();

	HDC hdc = m_pBBuffer->getDC();

	m_imgBackground.Paint(hdc, 0, 0);

	if(GameOver == false && level.Winner == false && LevelChange == false)
	{
		DrawFunctor drawFn;
		std::for_each(m_vGameObjects.begin(), m_vGameObjects.end(), drawFn);
		std::for_each(m_vGameObjectsGift.begin(), m_vGameObjectsGift.end(), drawFn);
		std::for_each(m_vGameObjectsAnimate.begin(), m_vGameObjectsAnimate.end(), drawFn);
	}
	else
	{
		if(LevelChange == true)
			DrawGame(hdc,"level");
		if(level.Winner == true)
		{
			DrawGame(hdc,"winner");
			if(countGameOver == 0)
			{
				SaveScore();
				ScoreTable();
			}
			ShowScoreTable(hdc);
			countGameOver++;
		}
		if(GameOver == true)
		{
			DrawGame(hdc,"gameover");
			if(countGameOver == 0)
			{
				SaveScore();
				ScoreTable();
			}
			ShowScoreTable(hdc);
			countGameOver++;
		}
	}

	DrawScore(hdc);
	DrawLife(hdc);

	m_pBBuffer->present();
}
void SFApp::OnRender() {
  SDL_RenderClear(sf_window->getRenderer());
 
  SDL_RenderCopy(sf_window->getRenderer(), background, NULL, &back);
  SDL_RenderCopy(sf_window->getRenderer(), background, NULL, &back2);

  for(auto p: projectiles) {
    if(p->IsAlive()) {p->OnRender();}
  }

  for(auto w: walls) {
    if(w->IsAlive()) {w->OnRender();}
  }

  for(auto a: aliens) {
    if(a->IsAlive()) {a->OnRender();}
  }

  for(auto c: coins) {
    c->OnRender();
  }
  
  for(auto e: explosions){
    e->OnRender();
  }
  
  DrawScore(std::to_string(score));
  //  DrawScore("1723");
   // draw the player
  player->OnRender();
  
  SDL_RenderCopy(sf_window->getRenderer(), healthbar, NULL, &healthpos);
  SDL_RenderCopy(sf_window->getRenderer(), healthgreen, NULL, &healthgreenpos);
  
  if(gameover){
      SDL_RenderCopy(sf_window->getRenderer(), gameoverimage, NULL, &gameoverpos);
  }
  
  // Switch the off-screen buffer to be on-screen
  SDL_RenderPresent(sf_window->getRenderer());
}
Beispiel #10
0
void CStage::Draw(){

	/*for(int x=0;x<width;x++){
		for(int y=0;y<height;y++){

		}
	}*/
	if (quakeFlag && pauseFlag == false) {
		gStage->Draw(cos(DegToRad((double)GetRand(360)))*20, sin(DegToRad((double)GetRand(360))) * 20,num);
	}
	else {
		gStage->Draw(num);
	}
	quakeFlag = false;
	DrawJiki();
	enemy.Draw();
	barrageManager.Draw();
	enemy.enemyBarrage.Draw();
	jikiBarrage->Draw();
	gScore->Draw();
	DrawScore();
	DrawIcon();
}
Beispiel #11
0
/*
===================
=
= GameLoop
=
===================

This function controls the flow between states of the game.

It loads previous saved games, setup levels states, controls the
flow between levels, including when player loses or when completes the game,
and checks if the result of the current game is a highscore.

The "real" game loop (player actions in like moving, killing, etc.) is in the
PlayLoop function.
*/
void GameLoop (void)
{
	int i,xl,yl,xh,yh;
	char num[20];
	boolean	died;
#ifdef MYPROFILE
	/* clock_t type variables
	   may register times, 
		start and and times 
		could be used to measure 
		the speed of the graphics system.
		Speed is measured in fps- frames per second.
*/
	clock_t start,end;
#endif

restartgame:
	ClearMemory (); 
	SETFONTCOLOR(0,15);
	DrawPlayScreen ();
	died = false;
restart:
	do
	{
		if (!loadedgame)
		  gamestate.score = gamestate.oldscore;
		DrawScore();

		startgame = false;
		if (loadedgame)
			loadedgame = false;
		else
			SetupGameLevel ();

#ifdef SPEAR
		if (gamestate.mapon == 20)	// give them the key allways
		{
			gamestate.keys |= 1;
			DrawKeys ();
		}
#endif

		ingame = true;
		StartMusic ();
		PM_CheckMainMem ();
		if (!died)
			PreloadGraphics ();
		else
			died = false;

		fizzlein = true;
		DrawLevel ();

startplayloop:
		PlayLoop ();

#ifdef SPEAR
		if (spearflag)
		{
			SD_StopSound();
			SD_PlaySound(GETSPEARSND);
			if (DigiMode != sds_Off)
			{
				long lasttimecount = TimeCount;

				while(TimeCount < lasttimecount+150)
				//while(DigiPlaying!=false)
					SD_Poll();
			}
			else
				SD_WaitSoundDone();

			ClearMemory ();
			gamestate.oldscore = gamestate.score;
			gamestate.mapon = 20;
			SetupGameLevel ();
			StartMusic ();
			PM_CheckMainMem ();
			player->x = spearx;
			player->y = speary;
			player->angle = spearangle;
			spearflag = false;
			Thrust (0,0);
			goto startplayloop;
		}
#endif

		StopMusic ();
		ingame = false;

		if (demorecord && playstate != ex_warped)
			FinishDemoRecord ();

		if (startgame || loadedgame)
			goto restartgame;

		switch (playstate)
		{
		case ex_completed:
		case ex_secretlevel:
			gamestate.keys = 0;
			DrawKeys ();
			VW_FadeOut ();

			ClearMemory ();

			LevelCompleted ();		// do the intermission
#ifdef SPEARDEMO
			if (gamestate.mapon == 1)
			{
				died = true;			// don't "get psyched!"

				VW_FadeOut ();

				ClearMemory ();

				CheckHighScore (gamestate.score,gamestate.mapon+1);

				#pragma warn -sus
				#ifndef JAPAN
				_fstrcpy(MainMenu[viewscores].string,STR_VS);
				#endif
				MainMenu[viewscores].routine = CP_ViewScores;
				#pragma warn +sus

				return;
			}
#endif

#ifdef JAPDEMO
			if (gamestate.mapon == 3)
			{
				died = true;			// don't "get psyched!"

				VW_FadeOut ();

				ClearMemory ();

				CheckHighScore (gamestate.score,gamestate.mapon+1);

				#pragma warn -sus
				#ifndef JAPAN
				_fstrcpy(MainMenu[viewscores].string,STR_VS);
				#endif
				MainMenu[viewscores].routine = CP_ViewScores;
				#pragma warn +sus

				return;
			}
#endif

			gamestate.oldscore = gamestate.score;

#ifndef SPEAR
			//
			// COMING BACK FROM SECRET LEVEL
			//
			if (gamestate.mapon == 9)
				gamestate.mapon = ElevatorBackTo[gamestate.episode];	// back from secret
			else
			//
			// GOING TO SECRET LEVEL
			//
			if (playstate == ex_secretlevel)
				gamestate.mapon = 9;
#else

#define FROMSECRET1		3
#define FROMSECRET2		11

			//
			// GOING TO SECRET LEVEL
			//
			if (playstate == ex_secretlevel)
				switch(gamestate.mapon)
				{
				 case FROMSECRET1: gamestate.mapon = 18; break;
				 case FROMSECRET2: gamestate.mapon = 19; break;
				}
			else
			//
			// COMING BACK FROM SECRET LEVEL
			//
			if (gamestate.mapon == 18 || gamestate.mapon == 19)
				switch(gamestate.mapon)
				{
				 case 18: gamestate.mapon = FROMSECRET1+1; break;
				 case 19: gamestate.mapon = FROMSECRET2+1; break;
				}
#endif
			else
			//
			// GOING TO NEXT LEVEL
			//
				gamestate.mapon++;


			break;

		case ex_died:
			Died ();
			died = true;			// don't "get psyched!"

			if (gamestate.lives > -1)
				break;				// more lives left

			VW_FadeOut ();

			ClearMemory ();

			CheckHighScore (gamestate.score,gamestate.mapon+1);

			#pragma warn -sus
			#ifndef JAPAN
			_fstrcpy(MainMenu[viewscores].string,STR_VS);
			#endif
			MainMenu[viewscores].routine = CP_ViewScores;
			#pragma warn +sus

			return;

		case ex_victorious:

#ifndef SPEAR
			VW_FadeOut ();
#else
			VL_FadeOut (0,255,0,17,17,300);
#endif
			ClearMemory ();

			Victory ();

			ClearMemory ();

			CheckHighScore (gamestate.score,gamestate.mapon+1);

			#pragma warn -sus
			#ifndef JAPAN
			_fstrcpy(MainMenu[viewscores].string,STR_VS);
			#endif
			MainMenu[viewscores].routine = CP_ViewScores;
			#pragma warn +sus

			return;

		default:
			ClearMemory ();
			break;
		}

	} while (1);

}
Beispiel #12
0
void View::Draw(const Model &model) const {
  ofPushMatrix();
  SetupViewpoint();
  ofBackground(ofColor::white);
  //CHASERS-------------------
  for (int i = 0; i < model.nChasers; i++){
    model.topChaser[i]->draw();
    model.botChaser[i]->draw();
    model.rightChaser[i]->draw();
    model.leftChaser[i]->draw();
  }
  DrawGravity(model);
  DrawPlayers(model);
  
  ofColor ball_color = model.last_hit_player == 1 ? color_p1 :
      model.last_hit_player == 2 ? color_p2 : ofColor::white;
  DrawBallTrail(model, model.ball_trail, ball_color);
  DrawStrikeIndicator(model);
  DrawBall(model.ball, ball_color);
  
  for (float x=-10; x<GRID_W; x+=(1.0/6.0)) {
    for (float y=-5; y<GRID_H; y+=(1.0/6.0)) {
      if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)<0.3) {
        if (ball_color==color_p1){
          ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 100);
        }else if(ball_color==color_p2){
          ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 100);
        }else{
          ofSetColor(ofRandom(200,250),ofRandom(200,250),ofRandom(200,250), 200);
        }
        ofCircle(x, y, 0.1);
      }
      else if (ofDist(model.player1_top->GetPosition().x, model.player1_top->GetPosition().y, x, y)<0.4 ||
               ofDist(model.player1_bottom->GetPosition().x, model.player1_bottom->GetPosition().y, x, y)<0.4) {
        ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 155);
        ofCircle(x, y, 0.12);
      }
      else if (ofDist(model.player2_top->GetPosition().x, model.player2_top->GetPosition().y, x, y)<0.4 ||
               ofDist(model.player2_bottom->GetPosition().x, model.player2_bottom->GetPosition().y, x, y)<0.4) {
        ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 155);
        ofCircle(x, y, 0.12);
      }
      else if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)< model.p1glowMax){
        ofNoFill();
        ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 135);
        ofCircle(x, y, 0.12);
        ofFill();
      }
      else if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)< model.p2glowMax){
        ofNoFill();
        ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 135);
        ofCircle(x, y, 0.12);
        ofFill();
      }
      
      
      else {
        ofFill();
        ofSetColor(ofRandom(0,10),ofRandom(0,10),ofRandom(10,20), 20);
        ofTriangle(x, y+0.7, x-0.6, y-0.6, x+0.6, y-0.6);

      }

    }



    
  }
  DrawCourt(model);
  DrawScore(model);
  if (model.show_winning_state) {
    DrawTriangles(model);
  }
  ofPopMatrix();

  //DrawFramesPerSecond(model);
}
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;
}
Beispiel #14
0
void CheckKeys (void)
{
    ScanCode scan;


    if (screenfaded || demoplayback)    // don't do anything with a faded screen
        return;

    scan = LastScan;


#ifdef SPEAR
    //
    // SECRET CHEAT CODE: TAB-G-F10
    //
    if (Keyboard[sc_Tab] && Keyboard[sc_G] && Keyboard[sc_F10])
    {
        WindowH = 160;
        if (godmode)
        {
            Message ("God mode OFF");
            SD_PlaySound (NOBONUSSND);
        }
        else
        {
            Message ("God mode ON");
            SD_PlaySound (ENDBONUS2SND);
        }

        IN_Ack ();
        godmode ^= 1;
        DrawPlayBorderSides ();
        IN_ClearKeysDown ();
        return;
    }
#endif


    //
    // SECRET CHEAT CODE: 'MLI'
    //
    if (Keyboard[sc_M] && Keyboard[sc_L] && Keyboard[sc_I])
    {
        gamestate.health = 100;
        gamestate.ammo = 99;
        gamestate.keys = 3;
        gamestate.score = 0;
        gamestate.TimeCount += 42000L;
        GiveWeapon (wp_chaingun);
        DrawWeapon ();
        DrawHealth ();
        DrawKeys ();
        DrawAmmo ();
        DrawScore ();

        ClearMemory ();
        CA_CacheGrChunk (STARTFONT + 1);
        ClearSplitVWB ();

        Message (STR_CHEATER1 "\n"
                 STR_CHEATER2 "\n\n" STR_CHEATER3 "\n" STR_CHEATER4 "\n" STR_CHEATER5);

        UNCACHEGRCHUNK (STARTFONT + 1);
        IN_ClearKeysDown ();
        IN_Ack ();

        if (viewsize < 17)
            DrawPlayBorder ();
    }

    //
    // OPEN UP DEBUG KEYS
    //
#ifdef DEBUGKEYS
    if (Keyboard[sc_BackSpace] && Keyboard[sc_LShift] && Keyboard[sc_Alt] && param_debugmode)
    {
        ClearMemory ();
        CA_CacheGrChunk (STARTFONT + 1);
        ClearSplitVWB ();

        Message ("Debugging keys are\nnow available!");
        UNCACHEGRCHUNK (STARTFONT + 1);
        IN_ClearKeysDown ();
        IN_Ack ();

        DrawPlayBorderSides ();
        DebugOk = 1;
    }
#endif

    //
    // TRYING THE KEEN CHEAT CODE!
    //
    if (Keyboard[sc_B] && Keyboard[sc_A] && Keyboard[sc_T])
    {
        ClearMemory ();
        CA_CacheGrChunk (STARTFONT + 1);
        ClearSplitVWB ();

        Message ("Commander Keen is also\n"
                 "available from Apogee, but\n"
                 "then, you already know\n" "that - right, Cheatmeister?!");

        UNCACHEGRCHUNK (STARTFONT + 1);
        IN_ClearKeysDown ();
        IN_Ack ();

        if (viewsize < 18)
            DrawPlayBorder ();
    }

//
// pause key weirdness can't be checked as a scan code
//
    if(buttonstate[bt_pause]) Paused = true;
    if(Paused)
    {
        int lastoffs = StopMusic();
        LatchDrawPic (20 - 4, 80 - 2 * 8, PAUSEDPIC);
        VH_UpdateScreen();
        IN_Ack ();
        Paused = false;
        ContinueMusic(lastoffs);
        if (MousePresent && IN_IsInputGrabbed())
            IN_CenterMouse();     // Clear accumulated mouse movement
        lasttimecount = GetTimeCount();
        return;
    }

//
// F1-F7/ESC to enter control panel
//
    if (
#ifndef DEBCHECK
           scan == sc_F10 ||
#endif
           scan == sc_F9 || scan == sc_F7 || scan == sc_F8)     // pop up quit dialog
    {
        short oldmapon = gamestate.mapon;
        short oldepisode = gamestate.episode;
        ClearMemory ();
        ClearSplitVWB ();
        US_ControlPanel (scan);

        DrawPlayBorderSides ();

        SETFONTCOLOR (0, 15);
        IN_ClearKeysDown ();
        return;
    }

    if ((scan >= sc_F1 && scan <= sc_F9) || scan == sc_Escape || buttonstate[bt_esc])
    {
        int lastoffs = StopMusic ();
        ClearMemory ();
        VW_FadeOut ();

        US_ControlPanel (buttonstate[bt_esc] ? sc_Escape : scan);

        SETFONTCOLOR (0, 15);
        IN_ClearKeysDown ();
        VW_FadeOut();
        if(viewsize != 21)
            DrawPlayScreen ();
        if (!startgame && !loadedgame)
            ContinueMusic (lastoffs);
        if (loadedgame)
            playstate = ex_abort;
        lasttimecount = GetTimeCount();
        if (MousePresent && IN_IsInputGrabbed())
            IN_CenterMouse();     // Clear accumulated mouse movement
        return;
    }

//
// TAB-? debug keys
//
#ifdef DEBUGKEYS
    if (Keyboard[sc_Tab] && DebugOk)
    {
        CA_CacheGrChunk (STARTFONT);
        fontnumber = 0;
        SETFONTCOLOR (0, 15);
        if (DebugKeys () && viewsize < 20)
            DrawPlayBorder ();       // dont let the blue borders flash

        if (MousePresent && IN_IsInputGrabbed())
            IN_CenterMouse();     // Clear accumulated mouse movement

        lasttimecount = GetTimeCount();
        return;
    }
#endif
}
int QuiesceFlee(POS *p, int ply, int alpha, int beta, int *pv) {

  int best, score, move, new_pv[MAX_PLY];
  int fl_check, mv_type;
  int is_pv = (beta > alpha + 1);

  MOVES m[1];
  UNDO u[1];

  // Periodically check for timeout, ponderhit or stop command

  nodes++;
  CheckTimeout();

  // Quick exit on a timeout or on a statically detected draw

  if (abort_search) return 0;
  if (ply) *pv = 0;
  if (IsDraw(p) ) return DrawScore(p);

  // Retrieving data from transposition table. We hope for a cutoff
  // or at least for a move to improve move ordering.

  move = 0;
  if (TransRetrieve(p->hash_key, &move, &score, alpha, beta, 0, ply))
    return score;

  // Safeguard against exceeding ply limit

  if (ply >= MAX_PLY - 1)
    return Eval.Return(p, 1);

  // Are we in check? Knowing that is useful when it comes 
  // to pruning/reduction decisions

  fl_check = InCheck(p);

  // Init moves and variables before entering main loop

  best = -INF;
  InitMoves(p, m, move, -1, ply);

  // Main loop

  while ((move = NextMove(m, &mv_type))) {
    p->DoMove(move, u);
    if (Illegal(p)) { p->UndoMove(move, u); continue; }
    
    score = -Quiesce(p, ply, -beta, -alpha, new_pv);

    
    p->UndoMove(move, u);
    if (abort_search) return 0;

    // Beta cutoff

    if (score >= beta) {
      TransStore(p->hash_key, move, score, LOWER, 0, ply);
      return score;
    }

    // Updating score and alpha

    if (score > best) {
      best = score;
      if (score > alpha) {
        alpha = score;
        BuildPv(pv, new_pv, move);
      }
    }

  } // end of the main loop

  // Return correct checkmate/stalemate score

  if (best == -INF)
    return InCheck(p) ? -MATE + ply : DrawScore(p);

  // Save score in the transposition table

  if (*pv) TransStore(p->hash_key, *pv, best, EXACT, 0, ply);
  else     TransStore(p->hash_key, 0, best, UPPER, 0, ply);

  return best;
}
Beispiel #16
0
//-----------------------------------------------------------------------------
// Name : CollisionDetection () (Private)
// Desc : Detects and handles collision
//-----------------------------------------------------------------------------
void CGameApp::CollisionDetection()
{
	HDC hdc = m_pBBuffer->getDC();

	// collision detection with the main frame
	for(auto it = m_vGameObjects.begin(); it != m_vGameObjects.end(); ++it)
	{
		CGameObject * pGameObj = it->get();
		Vec2 pos = pGameObj->myPosition;

		if(pGameObj->GetObjectTypeSub() == GOT_BrickNormal || pGameObj->GetObjectTypeSub() == GOT_BrickDouble || pGameObj->GetObjectTypeSub() == GOT_BrickGift)
		{
			BricksExist = true;
		}

		pGameObj->myCollisionSide = CS_None;

		// check collision for ball and player with wall
		if(pGameObj->GetObjectType() == GOT_Ball || pGameObj->GetObjectType() == GOT_Player)
		{
			int dx = (int)pos.x - pGameObj->GetWidth() / 2;
			if( dx < 0 )
			{
				pGameObj->myCollisionSide |= CS_Left;

				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.x = -m_pBall.lock()->myVelocity.x;
				}

				if(pGameObj->GetObjectType() == GOT_Player)
				{
					pGameObj->myPosition.x = pGameObj->GetWidth()/2;
					if(FollowPlayer == true)
					{
						m_pBall.lock()->myPosition.x = ballPos.x + pGameObj->myPosition.x;
					}
				}
			}

			dx = (int)pos.x - (m_nViewWidth - pGameObj->GetWidth() / 2);
			if( dx > 0 )
			{
				pGameObj->myCollisionSide |= CS_Right;

				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.x = -m_pBall.lock()->myVelocity.x;
				}

				if(pGameObj->GetObjectType() == GOT_Player)
				{
					pGameObj->myPosition.x = m_nViewWidth - pGameObj->GetWidth() / 2;
					if(FollowPlayer == true)
					{
						m_pBall.lock()->myPosition.x = ballPos.x + pGameObj->myPosition.x;
					}
				}
			}

			int dy = (int)pos.y - pGameObj->GetHeight() / 2;
			if( dy < 0 )
			{
				pGameObj->myCollisionSide |= CS_Top;
				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.y = -m_pBall.lock()->myVelocity.y;
				}
			}

			dy = (int)pos.y - (m_nViewHeight - pGameObj->GetHeight() / 2);
			if( dy > 0 )
			{
				pGameObj->myCollisionSide |= CS_Bottom;
				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.y = -m_pBall.lock()->myVelocity.y;
				}
			}

		}

		// check ball collision with game objects
		if(pGameObj->GetObjectType() == GOT_Ball)
			for(auto it2 = m_vGameObjects.begin(); it2 != m_vGameObjects.end(); ++it2)
			{
				CGameObject * pGameObj2 = it2->get();
				Vec2 pos2 = pGameObj2->myPosition;


				if(pGameObj->GetObjectType() == pGameObj2->GetObjectType())
					continue;
				if(pGameObj2->GetObjectType() == GOT_Player || pGameObj2->GetObjectType() == GOT_Brick)
				{

					if(pGameObj2->GetObjectType() == GOT_Player)
					{
						if(pGameObj->myPosition.y > m_nViewHeight - m_pBall.lock()->GetHeight() - m_pPlayer.lock()->GetHeight() + ONE)
						{
							if(!(abs(pos.y - pos2.y) < pGameObj->GetHeight() / 2 + pGameObj2->GetHeight() / 2 && abs(pos.x - pos2.x) < pGameObj->GetWidth() / 2 + pGameObj2->GetWidth() / 2))
							{
								Decrease_Life();
								UnstoppableBall = false;
								StickyBar = false;
								ballPos.x = 0;
								ShrinkBar = false;
								MoveBall = false;
								m_pPlayer.lock()->Normal_Bar();
								SystemParametersInfo(SPI_SETMOUSESPEED, NULL, (void*)10, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
								if(countLife == NO_LIFE)
								{
									GameOver = true;
								}
							}
						}
					}

					if(abs(pos.y - pos2.y) < pGameObj->GetHeight() / 2 + pGameObj2->GetHeight() / 2 && abs(pos.x - pos2.x) < pGameObj->GetWidth() / 2 + pGameObj2->GetWidth() / 2)
					{		

						if(pGameObj2->GetObjectType() == GOT_Player)
						{
							if(StickyBar == true)
							{
								pGameObj->myVelocity.y = 0;
								pGameObj->myVelocity.x = 0;
								pGameObj->myPosition.y = (int)m_nViewHeight - m_pPlayer.lock()->GetHeight() - m_pBall.lock()->GetHeight() - ONE;
								ballPos.x = pGameObj->myPosition.x - pGameObj2->myPosition.x;
								FollowPlayer = true;
							}
							else
							{
								pGameObj->myVelocity.y = -pGameObj->myVelocity.y;
							}
						}
						else
						{
							if(UnstoppableBall != true)
								if(abs(pos.x - pos2.x) > pGameObj->GetHeight() / 2 + pGameObj2->GetHeight() / 2)
								{// left or right collosion
									pGameObj->myVelocity.x = -pGameObj->myVelocity.x;
								}
								else
								{// top or bottom collision
									pGameObj->myVelocity.y = -pGameObj->myVelocity.y;
								}
						}

						if(pGameObj2->GetObjectTypeSub() == GOT_BrickNormal || pGameObj2->GetObjectTypeSub() == GOT_BrickDouble || pGameObj2->GetObjectTypeSub() == GOT_BrickGift)
						{
							if(pGameObj2->GetObjectTypeSub() == GOT_BrickDouble)
							{						
								int CheckDouble=pGameObj2->DecreaseDouble();
								if(CheckDouble == 1)
								{
									Increase_Score(BRICK_SCORE);
									pGameObj2->ChangeSprite();
								}
								if(CheckDouble == 0)
								{
									Increase_Score(BRICK_SCORE);
									DrawScore(hdc);
									auto pAnimate = std::make_shared<Brick>('k');
									pAnimate->Init(Vec2(pos2.x,pos2.y));
									m_vGameObjectsAnimate.push_back(pAnimate);
									m_vGameObjects.erase(it2);
									break;
								}
							}
							else
							{
								if(pGameObj2->GetObjectTypeSub() == GOT_BrickGift)
								{
									auto pGift = std::make_shared<Gift>(pGameObj2->GetBrickType());
									pGift->Init(Vec2(pos2.x,pos2.y));
									m_vGameObjectsGift.push_back(pGift);
								}
								Increase_Score(BRICK_SCORE);
								DrawScore(hdc);
								auto pAnimate = std::make_shared<Brick>('k');
								pAnimate->Init(Vec2(pos2.x,pos2.y));
								m_vGameObjectsAnimate.push_back(pAnimate);
								m_vGameObjects.erase(it2);
								break;
							}
						}
					}
				}

			}

			// check gift collision with player
			if(pGameObj->GetObjectType() == GOT_Player)
				for(auto it2 = m_vGameObjectsGift.begin(); it2 != m_vGameObjectsGift.end(); ++it2)
				{
					CGameObject * pGameObj2 = it2->get();
					Vec2 pos2 = pGameObj2->myPosition;

					if(abs(pos.y - pos2.y) < pGameObj->GetHeight() / 2 + pGameObj2->GetHeight() / 2 && abs(pos.x - pos2.x) < pGameObj->GetWidth() / 2 + pGameObj2->GetWidth() / 2)
					{
						if(pGameObj2->GetObjectTypeSub() == GOT_Gift100)
						{
							Increase_Score(BRICK_GIFT_SCORE_1);
							DrawScore(hdc);
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_Gift200)
						{
							Increase_Score(BRICK_GIFT_SCORE_2);
							DrawScore(hdc);
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftUpLife)
						{
							Increase_Life();
							DrawLife(hdc);
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftDownLife)
						{
							Decrease_Life2();
							DrawLife(hdc);
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftIncreaseSpeed)
						{
							m_pBall.lock()->Increase_Speed();
							DrawLife(hdc);
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftDecreaseSpeed)
						{
							m_pBall.lock()->Decrease_Speed();
							DrawLife(hdc);
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftUnstoppableBall)
						{
							UnstoppableBall = true;
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftStickyBar)
						{
							StickyBar = true;
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftShrinkBar)
						{
							if(ShrinkBar == false)
							{
								ShrinkBar = true;
								m_pPlayer.lock()->Shrink_Bar();
							}
							m_vGameObjectsGift.erase(it2);
							break;
						}
						if(pGameObj2->GetObjectTypeSub() == GOT_GiftSlowMouse)
						{
							SlowMouse = true;
							break;
						}
					}

					int dy = (int)pos2.y - (m_nViewHeight - pGameObj2->GetHeight() / 2);
					if( dy > 0 )
					{
						m_vGameObjectsGift.erase(it2);
						break;
					}
				}
	}
}
Beispiel #17
0
//add
void WorldDrawer2d::init(){
	cs1 = new CoordinateSystem2d();
	cs2 = new CoordinateSystem2d();
	cs_used.push_back(cs2);
	cs_used.push_back(cs1);
	DrawCircle(&o1,0.0f,0.0f,0.5f);
	o1->scaleRelativeToPoint(o1->points.at(0),0.5f,0.5f);
	DrawCircle(&b1,1.0f,1.0f,1.0f);
	DrawCircle(&b2,1.0f,1.0f,1.0f);
	DrawCircle(&b3,1.0f,1.0f,1.0f);
	DrawCircle(&b4,1.0f,1.0f,1.0f);
	DrawTribune(&spectatori);
	DrawFour(0.25f,18.0f,&o3,1.0f,1.0f,1.0f);
	DrawFour(0.25f,18.0f,&o4,1.0f,1.0f,1.0f);
	DrawFour(4.0f,0.25f,&o5,1.0f,1.0f,1.0f);
	DrawFour(4.0f,0.25f,&o6,1.0f,1.0f,1.0f);
	DrawFour(4.0f,0.25f,&o7,1.0f,1.0f,1.0f);
	DrawFour(4.0f,0.25f,&o8,1.0f,1.0f,1.0f);
	DrawFour(4.0f,0.25f,&o9,1.0f,1.0f,1.0f);
	DrawFour(4.0f,0.25f,&o10,1.0f,1.0f,1.0f);
	DrawFour(0.25f,1.0f,&o11,1.0f,1.0f,1.0f);
	DrawFour(0.25f,1.0f,&o12,1.0f,1.0f,1.0f);
	DrawFour(0.25f,1.0f,&o13,1.0f,1.0f,1.0f);
	DrawFour(0.25f,1.0f,&o14,1.0f,1.0f,1.0f);
	DrawFour(12.0f,0.1f,&o15,1.0f,1.0f,1.0f);
	DrawFour(6.0f,0.1f,&o16,1.0f,1.0f,1.0f);
	DrawFour(6.0f,0.1f,&o17,1.0f,1.0f,1.0f);
	DrawFour(0.1f,1.3f,&o18,1.0f,1.0f,1.0f);
	DrawFour(0.1f,1.3f,&o19,1.0f,1.0f,1.0f);
	DrawFour(0.1f,1.3f,&o20,1.0f,1.0f,1.0f);
	DrawFour(0.1f,1.3f,&o21,1.0f,1.0f,1.0f);

	DrawPlayers(&players1,1.0f,1.0f,0.0f);
	DrawPlayers(&players2,1.0f,0.1f,0.1f);
	DrawScore(1.0f,1.0f,0.0f,1.0f,0.1f,0.1f);
	DrawField(18,12);
	
	o3->translate(12.25f,0.0f);
	o4->translate(-12.25f,0.0f);
	o5->translate(-8.25f,18.0f);
	o6->translate(8.25f,18.0f);
	o7->translate(-8.25f,-18.0f);
	o8->translate(8.25f,-18.0f);
	o9->translate(0.0f,19.7f);
	o10->translate(0.0f,-19.7f);
	o11->translate(4.0f,18.75f);
	o12->translate(-4.0f,18.75f);
	o13->translate(-4.0f,-18.75f);
	o14->translate(4.0f,-18.75f);
	o16->translate(0.0f,15.5f);
	o17->translate(0.0f,-15.5f);
	o18->translate(6.0f,16.8f);
	o19->translate(-6.0f,16.8f);
	o20->translate(6.0f,-16.8f);
	o21->translate(-6.0f,-16.8f);
	players1.at(0)->translate(0.0f,17.7f);
	players1.at(1)->translate(-5.0f,10.0f);
	players1.at(2)->translate(5.0f,10.0f);
	players1.at(3)->translate(3.0f,-3.0f);
	players1.at(4)->translate(-6.0f,-3.0f);
	players1.at(5)->translate(0.0f,-9.0f);
	players2.at(0)->translate(0.0f,-17.7f);
	players2.at(1)->translate(5.0f,-10.0f);
	players2.at(2)->translate(-5.0f,-10.0f);
	players2.at(3)->translate(-3.0f,3.0f);
	players2.at(4)->translate(6.0f,3.0f);
	players2.at(5)->translate(0.0f,9.0f);

	putBall();
	b1->scaleRelativeToPoint(b1->points[0],0.75f,0.75f);
	b2->scaleRelativeToPoint(b2->points[0],0.75f,0.75f);
	b3->scaleRelativeToPoint(b3->points[0],0.75f,0.75f);
	b4->scaleRelativeToPoint(b4->points[0],0.75f,0.75f);

	b1->translate(-4.0f,18.0f);
	b2->translate(4.0f,18.0f);
	b3->translate(-4.0f,-18.0f);
	b4->translate(4.0f,-18.0f);

}
Beispiel #18
0
void CCockpit::Draw()
{
	//---------------------------------
	//描画処理
	//---------------------------------
	Sint32 bx=0,by=0;
	Sint32 wx,wy;

	if( m_sNowLoadingWait )
	{
		DrawNowLoading();
	}

	if( m_bSplash )
	{
		DrawSplash();
	}

	wx = 0;
	wy = m_sHeight;

	m_pRaderDamage->SetHitPoint( m_sDispHitPoint );

	if( m_bArrow )                     DrawArrow(WINDOW_W/2,WINDOW_H/2);
	
	if( m_bSwitch[enSwitchRader]    )  m_pRaderControl->Draw(0,WINDOW_H+wy);
	if( m_bSwitch[enSwitchRed]      )  m_pRaderDamage->DrawSekigaisen(470+24,5);

	//左上U.I
	if( m_bSwitch[enSwitchBullet]   ) DrawRelord(36,36-wy);	//HP表示
	if( m_bSwitch[enSwitchPosition] ) m_pRaderDamage->Draw(8,10+by-wy);

	if( m_bSwitch[enSwitchTime]     )  DrawTime(400-16,24-wy);
	if( m_bSwitch[enSwitchScore]    )  DrawScore(400-32,8-wy);
	if( m_bOutogRange )                DrawOutOfArea(320,240+wy);
	if( m_bSwitch[enSwitchMessage]   ) DrawShortMessage(64,44-wy);

	if( m_sBlackMask ) 				   DrawBlackmask();

	if( m_bSwitch[enSwitchDamage]   ) 
	{
		//DrawHitPoint();
	}
	else
	{
		m_sDispHitPoint = 0;
	}

	if( m_sWhiteFade )
	{
		DrawGameOver();
	}

//		enSwitchDamage,		//残りHP(ON/OFF)
//		enSwitchMessage,	//ショートメッセージ(ON/OFF)
//		enSwitchBullet,		//残弾数(ON/OFF)
//		enSwitchHigher,		//敵高度表示(ON/OFF)

	m_pMsgWindow->Draw(6,WINDOW_H-74-m_sBlackMask*28/100);

	if( m_pStageClear ) m_pStageClear->Draw();

}
Beispiel #19
0
void	MoveMouse()
{
static	int	locked = 0;
int dx=0;
int dy=0;
char zug=' ';

	if ( locked )
	{
		locked--;
		actcode=0xee;
		return;
	}

	switch( actcode )
	{
	case RC_RIGHT :		// Pinguin nach rechts
		if ( man_x+1 < MAZEW )
		{
		dx = 1;
		dy = 0;
		zug = 'r';
		locked=1;
		}
		break;

	case RC_LEFT :		// Pinguin nach links
		if ( man_x > 1 )
		{
		dx = -1;
		dy = 0;
		zug = 'l';
		locked=1;
		}
		break;

	case RC_DOWN :		// Pinguin nach unten
		if ( man_y+1 < MAZEH )
		{
		dx = 0;
		dy = 1;
		zug = 'd';
		locked=1;
		}
		break;

	case RC_UP :		// Pinguin nach oben
		if ( man_y > 1 )
		{
		dx = 0;
		dy = -1;
		zug = 'u';
		locked=1;
		}
		break;

	case RC_MINUS :		// letzte Züge rückgängig machen
		if (moves>0)
			{
			if (getField(man_x,man_y)=='@')
				{
				setField(man_x,man_y,' ');
				}
			else
				{
				setField(man_x,man_y,'.');
				}

			if (Zuege[moves]=='r' || Zuege[moves]=='R')
				{
				man_x--;
				dx=1;
				}
			else if (Zuege[moves]=='l' || Zuege[moves]=='L')
				{
				man_x++;
				dx=-1;
				}
			else if (Zuege[moves]=='u' || Zuege[moves]=='U')
				{
				man_y++;
				dy=-1;
				}
			else if (Zuege[moves]=='d' || Zuege[moves]=='D')
				{
				man_y--;
				dy=1;
				}

			if (getField(man_x,man_y)==' ')
				{
				setField(man_x,man_y,'@');
				}
			else
				{
				setField(man_x,man_y,'+');
				}

			if (isupper(Zuege[moves]))
				{
				if (getField(man_x+2*dx,man_y+2*dy)=='$')
					{
					setField(man_x+2*dx,man_y+2*dy,' ');
					}
				else
					{
					setField(man_x+2*dx,man_y+2*dy,'.');
					}

				if (getField(man_x+dx,man_y+dy)==' ')
					{
					setField(man_x+dx,man_y+dy,'$');
					}
				else
					{
					setField(man_x+dx,man_y+dy,'*');
					}
				pushes--;
				}
			moves--;
			dx=0;
			dy=0;
			DrawBoard();
			DrawScore();
		}
		locked=1;
		break;

	case RC_PLUS :		// Rückgängig rückgängig machen
		if (Zuege[moves+1]!=' ')
			{
			if (Zuege[moves+1]=='r' || Zuege[moves+1]=='R')
				{
				dx=1;
				}
			else if (Zuege[moves+1]=='l' || Zuege[moves+1]=='L')
				{
				dx=-1;
				}
			else if (Zuege[moves+1]=='u' || Zuege[moves+1]=='U')
				{
				dy=-1;
				}
			else if (Zuege[moves+1]=='d' || Zuege[moves+1]=='D')
				{
				dy=1;
				}
			}
		locked=1;
		break;

	case RC_RED :		// vorheriges Level - bei angefangenem Level nachfragen, ob wirklich sicher
		if (moves!=0)
			{
			FBFillRect( 160, 70, 400, 436, B );
			FBDrawString( 160,75, 30, "Das Level ist noch nicht beendet!", WHITE, 0 );
			FBDrawString( 160,110, 30, "ROT   abbruch", WHITE, 0 );
			FBDrawString( 160,140, 30, "OK    naechstes Level", WHITE, 0 );
#ifdef USEX
			FBFlushGrafic();
#endif

			actcode=0xee;
			while( actcode != RC_OK && actcode != RC_RED )
				{
					RcGetActCode();
				}
			}
		if (actcode == RC_OK || moves==0)
			{
			if (level > 0)
				{
				level--;
				BoardInitialize();
				}
			else
				{
				level = max_level-1;
				BoardInitialize();
				}
			}
		else
			{
			FBFillRect( 0, 0, 720, 576, BLACK );
			DrawBoard();
			DrawScore();
			}

		locked=1;
		break;

	case RC_GREEN :		// naechstes Level - bei angefangenem Level nachfragen, ob wirklich sicher
		if (moves!=0)
			{
			FBFillRect( 160, 70, 400, 436, B );
			FBDrawString( 160,75, 30, "Das Level ist noch nicht beendet!", WHITE, 0 );
			FBDrawString( 160,110, 30, "ROT   abbruch", WHITE, 0 );
			FBDrawString( 160,140, 30, "OK    vorheriges Level", WHITE, 0 );
#ifdef USEX
			FBFlushGrafic();
#endif

			actcode=0xee;
			while( actcode != RC_OK && actcode != RC_RED )
				{
					RcGetActCode();
				}
			}
		if (actcode == RC_OK || moves==0)
			{
			if (level+1 < max_level)
				{
				level++;
				BoardInitialize();
				}
			else
				{
				level = 0;
				BoardInitialize();
				}
			}
		else
			{
			FBFillRect( 0, 0, 720, 576, BLACK );
			DrawBoard();
			DrawScore();
			}

		locked=1;
		break;

	case RC_YELLOW :	// Randfelder ('a') aus-/einblenden
		if (Rand == 0)
			{
			Rand = 1;
			}
		else
			{
			Rand = 0;
			}
		locked=1;
		FBFillRect( 0, 0, 720, 576, BLACK );
		DrawBoard();
		DrawScore();
		FBDrawString( 300, 510, 30, levelname[level], WHITE, 0 );
		break;

	case RC_BLUE :		// Level von vorne beginnen - bei angefangenem Level nachfragen, ob wirklich sicher
		if (moves!=0)
			{
			FBFillRect( 160, 70, 400, 436, B );
			FBDrawString( 160,75, 30, "Das Level ist noch nicht beendet!", WHITE, 0 );
			FBDrawString( 160,110, 30, "ROT   abbruch", WHITE, 0 );
			FBDrawString( 160,140, 30, "OK    vorheriges Level", WHITE, 0 );
#ifdef USEX
			FBFlushGrafic();
#endif
			actcode=0xee;
			while( actcode != RC_OK && actcode != RC_RED )
				{
					RcGetActCode();
				}
			}
		if (actcode == RC_OK || moves==0)
			{
			BoardInitialize();
			}
		else
			{
			FBFillRect( 0, 0, 720, 576, BLACK );
			DrawBoard();
			DrawScore();
			}
		locked=1;
		break;

	case RC_HELP :		// Hilfe anzeigen
		locked=1;
		FBFillRect( 160, 70, 400, 436, B );
		FBDrawString( 160, 70, 30, "ROT   vorheriges Level", WHITE, 0 );
		FBDrawString( 160,100, 30, "GRUEN naechstes Level", WHITE, 0 );
		FBDrawString( 160,130, 30, "GELB  Rand ein/aus", WHITE, 0 );
		FBDrawString( 160,160, 30, "BLAU  Level neu starten", WHITE, 0 );
		FBDrawString( 160,190, 30, "MINUS Zug zurueck", WHITE, 0 );
		FBDrawString( 160,220, 30, "PLUS  Zug vor", WHITE, 0 );
		FBDrawString( 160,260, 30, "HOME  Spiel beenden", WHITE, 0 );
		FBDrawString( 160,290, 30, "STUMM Spiel aus-/einblenden", WHITE, 0 );
		FBDrawString( 160,330, 30, "HILFE diese Hilfe", WHITE, 0 );
		FBDrawString( 160,370, 30, "OK    weiter", WHITE, 0 );
#ifdef USEX
		FBFlushGrafic();
#endif

		actcode=0xee;
		while( actcode != RC_OK )
			{
				RcGetActCode( );
			}
		FBFillRect( 0, 0, 720, 576, BLACK );
		DrawBoard();
		DrawScore();
		FBDrawString( 300, 510, 30, levelname[level], WHITE, 0 );
		break;
	}

	if (dx != 0 || dy != 0)		// Soll Pinguin verschoben werden?
	{
	if (getField(man_x+dx, man_y+dy) == ' ')	// Zug auf leeres Feld - keine Kiste vorhanden
		{
		if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');}
			else {setField(man_x,man_y,'.');}
		DrawField(man_x, man_y);

		man_x += dx; dx = 0;
		man_y += dy; dy = 0;
		setField(man_x,man_y,'@');

		DrawField(man_x, man_y);

		moves++;
		DrawScore();
		}
	else if (getField(man_x+dx, man_y+dy) == '.')	// Zug auf Zielfeld - keine Kiste vorhanden
		{
		if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');}
			else {setField(man_x,man_y,'.');}
		DrawField(man_x, man_y);

		man_x += dx; dx = 0;
		man_y += dy; dy = 0;
		setField(man_x,man_y,'+');

		DrawField(man_x, man_y);

		moves++;
		DrawScore();
		}
	else if (getField(man_x+dx, man_y+dy) == '$' && getField(man_x+(2*dx), man_y+(2*dy)) == ' ')	// Zug auf Feld mit Kiste - Kiste auf leeres Feld
		{
		setField(man_x+(2*dx), man_y+(2*dy),'$');
		setField(man_x+dx, man_y+dy,' ');
		DrawField(man_x+(2*dx), man_y+(2*dy));

		if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');}
			else {setField(man_x,man_y,'.');}
		DrawField(man_x, man_y);

		man_x += dx; dx = 0;
		man_y += dy; dy = 0;
		setField(man_x,man_y,'@');

		DrawField(man_x, man_y);

		moves++;
		pushes++;
		zug = toupper (zug);
		DrawScore();
		}
	else if (getField(man_x+dx, man_y+dy) == '$' && getField(man_x+(2*dx), man_y+(2*dy)) == '.')	// Zug auf Feld mit Kiste - Kiste auf Zielfeld
		{
		setField(man_x+(2*dx), man_y+(2*dy),'*');
		setField(man_x+dx, man_y+dy,' ');
		DrawField(man_x+(2*dx), man_y+(2*dy));

		if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');}
			else {setField(man_x,man_y,'.');}
		DrawField(man_x, man_y);

		man_x += dx; dx = 0;
		man_y += dy; dy = 0;
		setField(man_x,man_y,'@');

		DrawField(man_x, man_y);

		moves++;
		pushes++;
		zug = toupper (zug);
		DrawScore();
		}
	else if (getField(man_x+dx, man_y+dy) == '*' && getField(man_x+(2*dx), man_y+(2*dy)) == ' ')	// Zug auf Zielfeld mit Kiste - Kiste auf leeres Feld
		{
		setField(man_x+(2*dx), man_y+(2*dy),'$');
		setField(man_x+dx, man_y+dy,'.');
		DrawField(man_x+(2*dx), man_y+(2*dy));

		if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');}
			else {setField(man_x,man_y,'.');}
		DrawField(man_x, man_y);

		man_x += dx; dx = 0;
		man_y += dy; dy = 0;
		setField(man_x,man_y,'+');

		DrawField(man_x, man_y);

		moves++;
		pushes++;
		zug = toupper (zug);
		DrawScore();
		}
	else if (getField(man_x+dx, man_y+dy) == '*' && getField(man_x+(2*dx), man_y+(2*dy)) == '.')	// Zug auf Zielfeld mit Kiste - Kiste auf Zielfeld
		{
		setField(man_x+(2*dx), man_y+(2*dy),'*');
		setField(man_x+dx, man_y+dy,'.');
		DrawField(man_x+(2*dx), man_y+(2*dy));

		if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');}
			else {setField(man_x,man_y,'.');}
		DrawField(man_x, man_y);

		man_x += dx; dx = 0;
		man_y += dy; dy = 0;
		setField(man_x,man_y,'+');

		DrawField(man_x, man_y);

		moves++;
		pushes++;
		zug = toupper (zug);
		DrawScore();
		}
	else
		{
		zug = ' ';
		}
	}

	if (zug !=' ')
		{
		Zuege[moves]=zug;
		}

	if (win() == 1)		// durch letzten Zug gewonnen?
		{
		if (level+1 < max_level)
			{
			level++;
			}
		else
			{
			level = 0;
			}

		doexit=1;
		}
#ifdef USEX
	FBFlushGrafic();
#endif
	return;
}
Beispiel #20
0
void	DrawGameOver()
{
	DrawScore();
	FBDrawString( 300, 210, 64, "Level geschaft!", RED, 0 );
}
Beispiel #21
0
void	BoardInitialize()
{
	char* verz = DATADIR "/sokoban/";
	char* verz2 = CONFIGDIR "/sokoban/";
	FILE *Datei=0;
	int x,y,z;
	int i;
	char* d;

	if (levelverz[level]==1)
		{
		d = malloc (strlen(verz)+strlen(levelname[level])+1);
		strcpy (d,verz);
		strcat (d,levelname[level]);
		}
	else
		{
		d = malloc (strlen(verz2)+strlen(levelname[level])+1);
		strcpy (d,verz2);
		strcat (d,levelname[level]);
		}

	FBFillRect( 0, 0, 720, 576, BLACK );

	Datei = fopen(d, "r");

	free(d);

	if ( !Datei )
	{	// installation error
		doexit=4;
		FBDrawString( 200, 510, 30, "Installation Error. Cant find Level", WHITE, 0 );
		return;
	}

	MAZEW = 0;
	MAZEH = 0;

	for (y=0; y<18; y++)
		{
		for (x=0; x<22; x++)
			{
			setField(x, y, 'a');
			}
		}

	x=0; y=0;
	while(!feof(Datei))
		{
		z = fgetc(Datei);

		if (z!='#' && z!='.' && z!='$' && z!='@' && z!='+' && z!='*' && z!=' ' && z!=0x0d && z!=0x0a)
			{
			MAZEH=y;
			break;
			}
		else if (z == 0x0d)
			{
			z=fgetc(Datei);
			for (i=x; board[i][y] != '#' && i > 3; i--) {x=i;}
			if (MAZEW < x) {MAZEW = x;}
			y++;
			x=0;
			MAZEH=y;
			}
		else if (z == 0x0a)
			{
			for (i=x; board[i][y] != '#' && i > 3; i--) {x=i;}
			if (MAZEW < x) {MAZEW = x;}
			y++;
			x=0;
			MAZEH=y;
			}
		else
			{
			if (y<18 && x<22)
				{
				setField(x, y, z);
				if ((z=='@') || (z=='+'))
					{
					man_x = x;
					man_y = y;
					}
				}
			x++;
			}
		}

	fclose(Datei);

	ox = (720 - (MAZEW*32))/2;
	oy = (576 - (MAZEH*28))/2;

	for (y=0; y<18; y++)
		{
		for (x=0; x<22; x++)
			{
			if (getField(x, y) != '#') {setField (x, y, 'a');}
				else break;
			}
		for (x=21; x>=0; x--)
			{
			if (getField(x, y) != '#') {setField (x, y, 'a');}
				else break;
			}
		}

	for (x=0; x<22; x++)
		{
		for (y=0; y<18; y++)
			{
			if (getField(x, y) != '#') {setField (x, y, 'a');}
				else break;
			}
		for (y=17; y>=0; y--)
			{
			if (getField(x, y) != '#') {setField (x, y, 'a');}
				else break;
			}
		}

	moves = 0;
	pushes = 0;

	DrawBoard();
	DrawScore();
	FBDrawString( 300, 510, 30, levelname[level], WHITE, 0 );
	
	for (i=0; i<=1500;i++)
		{
		Zuege[i]=' ';
		}
}
Beispiel #22
0
/*
********************************************************************************
*                                                                              *
*   Search() is the recursive routine used to implement the alpha/beta         *
*   negamax search (similar to minimax but simpler to code.)  Search() is      *
*   called whenever there is "depth" remaining so that all moves are subject   *
*   to searching, or when the side to move is in check, to make sure that this *
*   side isn't mated.  Search() recursively calls itself until depth is ex-    *
*   hausted, at which time it calls Quiesce() instead.                         *
*                                                                              *
********************************************************************************
*/
int Search(int alpha, int beta, int wtm, int depth, int ply, int do_null)
{
  register int first_move=1;
  register BITBOARD save_hash_key;
  register int initial_alpha, value;
  register int extensions;
/*
 ----------------------------------------------------------
|                                                          |
|   check to see if we have searched enough nodes that it  |
|   is time to peek at how much time has been used, or if  |
|   is time to check for operator keyboard input.  this is |
|   usually enough nodes to force a time/input check about |
|   once per second, except when the target time per move  |
|   is very small, in which case we try to check the time  |
|   at least 10 times during the search.                   |
|                                                          |
 ----------------------------------------------------------
*/
  if (ply >= MAXPLY-2) return(beta);
  nodes_searched++;
  if (--next_time_check <= 0) {
    next_time_check=nodes_between_time_checks;
    if (CheckInput()) Interrupt(ply);
    time_abort+=TimeCheck(0);
    if (time_abort) {
      abort_search=1;
      return(0);
    }
  }
/*
 ----------------------------------------------------------
|                                                          |
|   check for draw by repetition.                          |
|                                                          |
 ----------------------------------------------------------
*/
  if (RepetitionCheck(ply,wtm)) {
    value=(wtm==root_wtm) ? DrawScore() : -DrawScore();
    if (value < beta) SavePV(ply,value,0);
#if !defined(FAST)
    if(ply <= trace_level) printf("draw by repetition detected, ply=%d.\n",ply);
#endif
    return(value);
  }
/*
 ----------------------------------------------------------
|                                                          |
|   now call LookUp() to see if this position has been     |
|   searched before.  if so, we may get a real score,      |
|   produce a cutoff, or get nothing more than a good move |
|   to try first.  there are four cases to handle:         |
|                                                          |
|   1. LookUp() returned "EXACT_SCORE" if this score is    |
|   greater than beta, return beta.  otherwise, return the |
|   score.  In either case, no further searching is needed |
|   from this position.  note that lookup verified that    |
|   the table position has sufficient "draft" to meet the  |
|   requirements of the current search depth remaining.    |
|                                                          |
|   2.  LookUp() returned "LOWER_BOUND" which means that   |
|   when this position was searched previously, every move |
|   was "refuted" by one of its descendents.  as a result, |
|   when the search was completed, we returned alpha at    |
|   that point.  we simply return alpha here as well.      |
|                                                          |
|   3.  LookUp() returned "UPPER_BOUND" which means that   |
|   when we encountered this position before, we searched  |
|   one branch (probably) which promptly refuted the move  |
|   at the previous ply.                                   |
|                                                          |
|   4.  LookUp() returned "AVOID_NULL_MOVE" which means    |
|   the hashed score/bound was no good, but it indicated   |
|   that trying a null-move in this position will be a     |
|   waste of time.                                         |
|                                                          |
 ----------------------------------------------------------
*/
  switch (LookUp(ply,depth,wtm,&alpha,beta)) {
    case EXACT_SCORE:
      if(alpha >= beta) return(beta);
      else {
        SavePV(ply,alpha,1);
        return(alpha);
      }
    case LOWER_BOUND:
      return(alpha);
    case UPPER_BOUND:
      return(beta);
    case AVOID_NULL_MOVE:
      do_null=0;
  }
/*
 ----------------------------------------------------------
|                                                          |
|   now it's time to try a probe into the endgame table-   |
|   base files.  this is done if (a) the previous move was |
|   a capture or promotion, unless we are at very shallow  |
|   plies (<4) in the search; (b) there are less than 5    |
|   pieces left (currently all interesting 4 piece endings |
|   are available.)                                        |
|                                                          |
 ----------------------------------------------------------
*/
#if defined(TABLEBASES)
  if (TotalPieces < 5) do {
    register int wpawn, bpawn;
    int tb_value;
    if (TotalWhitePawns && TotalBlackPawns) {
      wpawn=FirstOne(WhitePawns);
      bpawn=FirstOne(BlackPawns);
      if (FileDistance(wpawn,bpawn) == 1) {
        if(((Rank(wpawn)==1) && (Rank(bpawn)>2)) ||
           ((Rank(bpawn)==6) && (Rank(wpawn)<5)) || 
           EnPassant(ply)) break;
      }
    }
    tb_probes++;
    if (EGTBScore(ply, wtm, &tb_value)) {
      tb_probes_successful++;
      alpha=tb_value;
      if (abs(alpha) > MATE-100) alpha+=(alpha > 0) ? -(ply-1) : +(ply-1);
      else if (alpha == 0) alpha=(wtm==root_wtm) ? DrawScore() : -DrawScore();
      if(alpha >= beta) return(beta);
      else {
        SavePV(ply,alpha,2);
        return(alpha);
      }
    }
  } while(0);
# endif
/*
 ----------------------------------------------------------
|                                                          |
|   initialize.                                            |
|                                                          |
 ----------------------------------------------------------
*/
  in_check[ply+1]=0;
  extended_reason[ply+1]=no_extension;
  initial_alpha=alpha;
  last[ply]=last[ply-1];
  killer_count1[ply+1]=0;
  killer_count2[ply+1]=0;
/*
 ----------------------------------------------------------
|                                                          |
|  first, we try a null move to see if we can get a quick  |
|  cutoff with only a little work.  this operates as       |
|  follows.  instead of making a legal move, the side on   |
|  move 'passes' and does nothing.  the resulting position |
|  is searched to a shallower depth than normal (usually   |
|  one ply less but settable by the operator) this should  |
|  result in a cutoff or at least should set the lower     |
|  bound better since anything should be better than not   |
|  doing anything.                                         |
|                                                          |
|  this is skipped for any of the following reasons:       |
|                                                          |
|  1.  the side on move is in check.  the null move        |
|      results in an illegal position.                     |
|  2.  no more than one null move can appear in succession |
|      or else the search will degenerate into nothing.    |
|  3.  the side on move has little material left making    |
|      zugzwang positions more likely.                     |
|                                                          |
 ----------------------------------------------------------
*/
# if defined(NULL_MOVE_DEPTH)
  if (do_null && !in_check[ply] && 
      ((wtm) ? TotalWhitePieces : TotalBlackPieces)>2) {
    current_move[ply]=0;
    current_phase[ply]=NULL_MOVE;
#if !defined(FAST)
    if (ply <= trace_level)
      SearchTrace(ply,depth,wtm,alpha,beta,"Search",0);
#endif
    position[ply+1]=position[ply];
    Rule50Moves(ply+1)++;
    save_hash_key=HashKey;
    if (EnPassant(ply)) {
      HashEP(EnPassant(ply+1),HashKey);
      EnPassant(ply+1)=0;
    }
    if ((depth-NULL_MOVE_DEPTH-INCREMENT_PLY) >= INCREMENT_PLY)
      value=-Search(-beta,-alpha,ChangeSide(wtm),depth-NULL_MOVE_DEPTH-INCREMENT_PLY,ply+1,NO_NULL);
    else 
      value=-Quiesce(-beta,-alpha,ChangeSide(wtm),ply+1);
    HashKey=save_hash_key;
    if (abort_search) return(0);
    if (value >= beta) {
      StoreRefutation(ply,depth,wtm,beta);
      return(beta);
    }
  }
# endif
/*
 ----------------------------------------------------------
|                                                          |
|   if there is no best move from the hash table, and this |
|   is a PV node, then we need a good move to search       |
|   first.  while killers and history moves are good, they |
|   are not "good enough".  the simplest action is to try  |
|   a shallow search (depth-2) to get a move.  note that   |
|   when we call Search() with depth-2, it, too, will      |
|   not have a hash move, and will therefore recursively   |
|   continue this process, hence the name "internal        |
|   iterative deepening."                                  |
|                                                          |
 ----------------------------------------------------------
*/
  next_status[ply].phase=FIRST_PHASE;
  if (hash_move[ply]==0 && (depth > 2*INCREMENT_PLY) &&
      (((ply & 1) && alpha == root_alpha && beta == root_beta) ||
      (!(ply & 1) && alpha == -root_beta && beta == -root_alpha))) {
    current_move[ply]=0;
    value=Search(alpha,beta,wtm,depth-2*INCREMENT_PLY,ply,DO_NULL);
    if (abort_search) return(0);
    if (value <= alpha) {
      value=Search(-MATE,beta,wtm,depth-2*INCREMENT_PLY,ply,DO_NULL);
      if (abort_search) return(0);
    }
    else if (value < beta) {
      if ((int) pv[ply-1].path_length >= ply) hash_move[ply]=pv[ply-1].path[ply];
    }
    else hash_move[ply]=current_move[ply];
    last[ply]=last[ply-1];
    next_status[ply].phase=FIRST_PHASE;
  }
/*
 ----------------------------------------------------------
|                                                          |
|   now iterate through the move list and search the       |
|   resulting positions.  note that Search() culls any     |
|   move that is not legal by using Check().  the special  |
|   case is that we must find one legal move to search to  |
|   confirm that it's not a mate or draw.                  |
|                                                          |
 ----------------------------------------------------------
*/
  while ((current_phase[ply]=(in_check[ply]) ? NextEvasion(ply,wtm) : 
                                               NextMove(depth,ply,wtm))) {
    extended_reason[ply]&=check_extension;
#if !defined(FAST)
    if (ply <= trace_level) SearchTrace(ply,depth,wtm,alpha,beta,"Search",current_phase[ply]);
#endif
/*
 ----------------------------------------------------------
|                                                          |
|   if two successive moves are capture / re-capture so    |
|   that the material score is restored, extend the search |
|   by one ply on the re-capture since it is pretty much   |
|   forced and easy to analyze.                            |
|                                                          |
 ----------------------------------------------------------
*/
    extensions=-INCREMENT_PLY;
    if (Captured(current_move[ply]) && Captured(current_move[ply-1]) &&
        To(current_move[ply-1]) == To(current_move[ply]) &&
        (p_values[Captured(current_move[ply-1])+7] == 
         p_values[Captured(current_move[ply])+7] ||
         Promote(current_move[ply-1])) &&
        !(extended_reason[ply-1]&recapture_extension)) {
      extended_reason[ply]|=recapture_extension;
      recapture_extensions_done++;
      extensions+=RECAPTURE;
    }
/*
 ----------------------------------------------------------
|                                                          |
|   if we push a passed pawn, we need to look deeper to    |
|   see if it is a legitimate threat.                      |
|                                                          |
 ----------------------------------------------------------
*/
    if (Piece(current_move[ply])==pawn && !FutileAhead(wtm) &&
         ((wtm && To(current_move[ply])>H5 && TotalBlackPieces<16 &&
          !And(mask_pawn_passed_w[To(current_move[ply])],BlackPawns)) ||
         (!wtm && To(current_move[ply])<A4 && TotalWhitePieces<16 &&
          !And(mask_pawn_passed_b[To(current_move[ply])],WhitePawns)) ||
         push_extensions[To(current_move[ply])]) &&
         Swap(From(current_move[ply]),To(current_move[ply]),wtm) >= 0) {
      extended_reason[ply]|=passed_pawn_extension;
      passed_pawn_extensions_done++;
      extensions+=PASSED_PAWN_PUSH;
    }
/*
 ----------------------------------------------------------
|                                                          |
|   now make the move and search the resulting position.   |
|   if we are in check, the current move must be legal     |
|   since NextEvasion ensures this, otherwise we have to   |
|   make sure the side-on-move is not in check after the   |
|   move to weed out illegal moves and save time.          |
|                                                          |
 ----------------------------------------------------------
*/
    MakeMove(ply,current_move[ply],wtm);
    if (in_check[ply] || !Check(wtm)) {
/*
 ----------------------------------------------------------
|                                                          |
|   if the move to be made checks the opponent, then we    |
|   need to remember that he's in check and also extend    |
|   the depth by one ply for him to get out.               |
|                                                          |
 ----------------------------------------------------------
*/
      if (Check(ChangeSide(wtm))) {
        in_check[ply+1]=1;
        extended_reason[ply+1]=check_extension;
        check_extensions_done++;
        extensions+=IN_CHECK;
      }
      else {
        in_check[ply+1]=0;
        extended_reason[ply+1]=no_extension;
      }
/*
 ----------------------------------------------------------
|                                                          |
|   now we toss in the "razoring" trick, which simply says |
|   if we are doing fairly badly, we can reduce the depth  |
|   an additional ply, if there was nothing at the current |
|   ply that caused an extension.                          |
|                                                          |
 ----------------------------------------------------------
*/
      if (depth < 3*INCREMENT_PLY && !in_check[ply] &&
          extensions == -INCREMENT_PLY) {
        register int val=(wtm) ? Material : -Material;
        if (val+1500 < alpha) extensions-=INCREMENT_PLY;
      }
/*
 ----------------------------------------------------------
|                                                          |
|   if there's only one legal move, extend the search one  |
|   additional ply since this node is very easy to search. |
|                                                          |
 ----------------------------------------------------------
*/
      if (first_move) {
        if (last[ply]-last[ply-1] == 1) {
          extended_reason[ply]|=one_reply_extension;
          one_reply_extensions_done++;
          extensions+=ONE_REPLY_TO_CHECK;
        }
        if (depth+MaxExtensions(extensions) >= INCREMENT_PLY)
          value=-Search(-beta,-alpha,ChangeSide(wtm),depth+MaxExtensions(extensions),ply+1,DO_NULL);
        else {
          value=-Quiesce(-beta,-alpha,ChangeSide(wtm),ply+1);
        }
        if (abort_search) {
          UnMakeMove(ply,current_move[ply],wtm);
          return(0);
        }
        first_move=0;
      }
      else {
        if (depth+MaxExtensions(extensions) >= INCREMENT_PLY)
          value=-Search(-alpha-1,-alpha,ChangeSide(wtm),depth+MaxExtensions(extensions),ply+1,DO_NULL);
        else {
          value=-Quiesce(-alpha-1,-alpha,ChangeSide(wtm),ply+1);
        }
        if (abort_search) {
          UnMakeMove(ply,current_move[ply],wtm);
          return(0);
        }
        if (value>alpha && value<beta) {
          if (depth+MaxExtensions(extensions) >= INCREMENT_PLY)
            value=-Search(-beta,-alpha,ChangeSide(wtm),depth+MaxExtensions(extensions),ply+1,DO_NULL);
          else 
            value=-Quiesce(-beta,-alpha,ChangeSide(wtm),ply+1);
          if (abort_search) {
            UnMakeMove(ply,current_move[ply],wtm);
            return(0);
          }
        }
      }
      if (value > alpha) {
        if(value >= beta) {
          HistoryRefutation(ply,depth,wtm);
          UnMakeMove(ply,current_move[ply],wtm);
          StoreRefutation(ply,depth,wtm,beta);
          return(beta);
        }
        alpha=value;
      }
    }
    UnMakeMove(ply,current_move[ply],wtm);
  }
/*
 ----------------------------------------------------------
|                                                          |
|   all moves have been searched.  if none were legal,     |
|   return either MATE or DRAW depending on whether the    |
|   side to move is in check or not.                       |
|                                                          |
 ----------------------------------------------------------
*/
  if (first_move == 1) {
    value=(Check(wtm)) ? -(MATE-ply) :
                         ((wtm==root_wtm) ? DrawScore() : -DrawScore());
    if(value > beta) value=beta;
    else if (value < alpha) value=alpha;
    if (value >=alpha && value <beta) {
      SavePV(ply,value,0);
#if !defined(FAST)
      if (ply <= trace_level) printf("Search() no moves!  ply=%d\n",ply);
#endif
    }
    return(value);
  }
  else {
    if (alpha != initial_alpha) {
      memcpy(&pv[ply-1].path[ply],&pv[ply].path[ply],(pv[ply].path_length-ply+1)*4);
      memcpy(&pv[ply-1].path_hashed,&pv[ply].path_hashed,3);
      pv[ply-1].path[ply-1]=current_move[ply-1];
      HistoryBest(ply,depth,wtm);
    }
    StoreBest(ply,depth,wtm,alpha,initial_alpha);
/*
 ----------------------------------------------------------
|                                                          |
|   if the 50-move rule is drawing close, then adjust the  |
|   score to reflect the impending draw.                   |
|                                                          |
 ----------------------------------------------------------
*/
    if (Rule50Moves(ply) > 99) {
      value=(wtm==root_wtm) ? DrawScore() : -DrawScore();
      if (value < beta) SavePV(ply,value,0);
#if !defined(FAST)
      if(ply <= trace_level) printf("draw by 50-move rule detected, ply=%d.\n",ply);
#endif
      return(value);
    }
    return(alpha);
  }
}
Beispiel #23
0
INT CGpApp::Init()
{
	TLC_ARGS args;
	INT hr = 0;

	LOGI("CGpApp::Init::Begin\n");

	
	////////////////////////////////////////////////////////////////////////////
	// Create Texture from File: Mipmap Level = 0, Color Key = 0x0

	UINT	colorKey= 0x0;
	UINT	use16	= 0x0;
	INT		mip		= 1;

	MAKE_ARG4(args, (char*)"data/atx_background.bmp", use16, colorKey, mip);
	if(LC_FAILED(LcDev_CreateTextureFromFile(NULL, &m_pTex[0], &args)))
		return LC_EFAIL;

	MAKE_ARG4(args, (char*)"data/atx_ship.png", use16, colorKey, mip);
	if(LC_FAILED(LcDev_CreateTextureFromFile(NULL, &m_pTex[1], &args)))
		return LC_EFAIL;

	MAKE_ARG4(args, (char*)"data/atx_photon.png", use16, colorKey, mip);
	if(LC_FAILED(LcDev_CreateTextureFromFile(NULL, &m_pTex[2], &args)))
		return LC_EFAIL;

	MAKE_ARG4(args, (char*)"data/atx_villain.png", use16, colorKey, mip);
	if(LC_FAILED(LcDev_CreateTextureFromFile(NULL, &m_pTex[3], &args)))
		return LC_EFAIL;

	MAKE_ARG4(args, (char*)"data/atx_shield.png", use16, colorKey, mip);
	if(LC_FAILED(LcDev_CreateTextureFromFile(NULL, &m_pTex[4], &args)))
		return LC_EFAIL;

	MAKE_ARG4(args, (char*)"data/atx_bar.png", use16, colorKey, mip);
	if(LC_FAILED(LcDev_CreateTextureFromFile(NULL, &m_pTex[5], &args)))
		return LC_EFAIL;


	////////////////////////////////////////////////////////////////////////////
	// Create Background, Effect Sound Instance.
	// (Default- 22050 Hz, 16 bit stereo)

	MAKE_ARG2(args, (UINT)LC_SRC_T_FILE, (char*)"data/asm_bgm.wav");
	if(LC_FAILED(LcxSmd_CreateSound(NULL, &m_pSnd[0], &args)))
		return LC_EFAIL;

	MAKE_ARG2(args, (UINT)LC_SRC_T_FILE, (char*)"data/asm_fire.wav");
	if(LC_FAILED(LcxSmd_CreateSound(NULL, &m_pSnd[1], &args)))
		return LC_EFAIL;

	MAKE_ARG2(args, (UINT)LC_SRC_T_FILE, (char*)"data/asm_explosion.wav");
	if(LC_FAILED(LcxSmd_CreateSound(NULL, &m_pSnd[2], &args)))
		return LC_EFAIL;


	////////////////////////////////////////////////////////////////////////////
	// Create Font Instance with Sprite

	TLC_FONT	tFont("data/mwg_b.otf", LC_FONT_AN_INTERNAL, 14);		// font name: 문화고딕, Height: 14
	MAKE_ARG2(args, (LC_HANDLE)&tFont, (LC_HANDLE)m_pSpt);
	if(LC_FAILED(LcDev_CreateFont(NULL, &m_pFontScore, &args)))
		return LC_EFAIL;


	m_pSnd[0]->SetRepeat();
	m_pSnd[0]->Play();


	LoadHighScore();
	ObjectInitialize();
	DrawScore();

	LOGI("CGpApp::Init::End\n");

	return LC_OK;
}
Beispiel #24
0
void PlayGame(coord history[],ship_p cell[][NUM_COLS],class_p clas,ship_p ship,int ship_num,string choice)
{
	int num,hit=0,total=0,sum,length,q,sink=0,sink_this_time;
	string message;
	coord location;
	ship_p boat;
	DrawScore(100,ship_num,0,1);
	for (num=0;num<=99;num++)
	{
		do
		{
			location=GetLocationChosenByUser();
			if ( IsInHistory(location,history) )
			{;}
			else 
			{
				history[num].col=location.col;
				history[num].row=location.row;
				break;
			}
		}
		while(TRUE);
		
		total++;
		sink_this_time=0;
		if ( cell[location.row][location.col]==NULL )
		{			
			MarkMiss(location);
			DrawPrintfMessage("Miss!");
			if ( StringEqual("y",choice) ) { PlayNamedSound("Missile"); }
		}
		else
		{
			hit++;
			boat=cell[location.row][location.col];
			cell[location.row][location.col]=NULL;
			sum=0;
			length=clas[boat->clas].length;
			if( StringEqual(choice,"y") ) { PlayNamedSound( clas[boat->clas].sound ); }
			for (q=0;q<=length-1;q++)
			{
				if (cell[ (boat->contain)[q].row ][ (boat->contain)[q].col ]==NULL)
				{
					sum++;
				}
			}
			if (sum==length)
			{
				sink_this_time=1;
				sink++;
				clas[boat->clas].num--;
				MarkLineAsSunk( boat->contain,length,"White" );
				MarkLineAsSunk( boat->contain,length,clas[boat->clas].color );
				message="You sank the ";
				message=Concat(message,clas[boat->clas].name);
				message=Concat(message," ");
				message=Concat(message,boat->name);
				message=Concat(message," ! ");
				message=Concat(message,"There are ");
				message=Concat( message , IntegerToString(clas[boat->clas].num) );
				message=Concat(message," ");
				message=Concat(message,clas[boat->clas].name);
				message=Concat(message,"s left.");
				DrawPrintfMessage(message);
				if( StringEqual(choice,"y") ) { PlayNamedSound("You Sank My Battleship"); }
			}
			if (sink_this_time==0)
			{
				MarkHit(location,clas[boat->clas].color,0.85);
				DrawPrintfMessage("Direct hit!");
			}
		}
		DrawScore(99-num,ship_num-sink,hit,total);
		if (sink==ship_num)
		{
			break;
		}
	}
	if (sink==ship_num ) { DrawPrintfMessage("You win!"); }
	else { DrawPrintfMessage("I win!"); }
	if( StringEqual(choice,"y") )
	{
		if (sink==ship_num ) { PlayNamedSound("Song of Joy"); }
		else { PlayNamedSound("That's Pathetic"); }
	}
}
Beispiel #25
0
void CheckKeys (void)
{
	int		i;
	byte	scan;
	unsigned	temp;


	if (screenfaded || demoplayback)	// don't do anything with a faded screen
		return;

	scan = LastScan;


	#ifdef SPEAR
	//
	// SECRET CHEAT CODE: TAB-G-F10
	//
	if (Keyboard[sc_Tab] &&
		Keyboard[sc_G] &&
		Keyboard[sc_F10])
	{
		WindowH = 160;
		if (godmode)
		{
			Message ("God mode OFF");
			SD_PlaySound (NOBONUSSND);
		}
		else
		{
			Message ("God mode ON");
			SD_PlaySound (ENDBONUS2SND);
		}

		IN_Ack();
		godmode ^= 1;
		DrawAllPlayBorderSides ();
		IN_ClearKeysDown();
		return;
	}
	#endif


	//
	// SECRET CHEAT CODE: 'MLI'
	//
	if (Keyboard[sc_M] &&
		Keyboard[sc_L] &&
		Keyboard[sc_I])
	{
		gamestate.health = 100;
		gamestate.ammo = 99;
		gamestate.keys = 3;
		gamestate.score = 0;
		gamestate.TimeCount += 42000L;
		GiveWeapon (wp_chaingun);

		DrawWeapon();
		DrawHealth();
		DrawKeys();
		DrawAmmo();
		DrawScore();

		ClearMemory ();
		CA_CacheGrChunk (STARTFONT+1);
		ClearSplitVWB ();
		VW_ScreenToScreen (displayofs,bufferofs,80,160);

		Message(STR_CHEATER1"\n"
				STR_CHEATER2"\n\n"
				STR_CHEATER3"\n"
				STR_CHEATER4"\n"
				STR_CHEATER5);

		UNCACHEGRCHUNK(STARTFONT+1);
		PM_CheckMainMem ();
		IN_ClearKeysDown();
		IN_Ack();

		DrawAllPlayBorder ();
	}

	//
	// OPEN UP DEBUG KEYS
	//
#ifndef SPEAR
	if (Keyboard[sc_BackSpace] &&
		Keyboard[sc_LShift] &&
		Keyboard[sc_Alt] &&
		MS_CheckParm("goobers"))
#else
	if (Keyboard[sc_BackSpace] &&
		Keyboard[sc_LShift] &&
		Keyboard[sc_Alt] &&
		MS_CheckParm("debugmode"))
#endif
	{
	 ClearMemory ();
	 CA_CacheGrChunk (STARTFONT+1);
	 ClearSplitVWB ();
	 VW_ScreenToScreen (displayofs,bufferofs,80,160);

	 Message("Debugging keys are\nnow available!");
	 UNCACHEGRCHUNK(STARTFONT+1);
	 PM_CheckMainMem ();
	 IN_ClearKeysDown();
	 IN_Ack();

	 DrawAllPlayBorderSides ();
	 DebugOk=1;
	}

	//
	// TRYING THE KEEN CHEAT CODE!
	//
	if (Keyboard[sc_B] &&
		Keyboard[sc_A] &&
		Keyboard[sc_T])
	{
	 ClearMemory ();
	 CA_CacheGrChunk (STARTFONT+1);
	 ClearSplitVWB ();
	 VW_ScreenToScreen (displayofs,bufferofs,80,160);

	 Message("Commander Keen is also\n"
			 "available from Apogee, but\n"
			 "then, you already know\n"
			 "that - right, Cheatmeister?!");

	 UNCACHEGRCHUNK(STARTFONT+1);
	 PM_CheckMainMem ();
	 IN_ClearKeysDown();
	 IN_Ack();

	 DrawAllPlayBorder ();
	}

//
// pause key weirdness can't be checked as a scan code
//
	if (Paused)
	{
		bufferofs = displayofs;
		LatchDrawPic (20-4,80-2*8,PAUSEDPIC);
		SD_MusicOff();
		IN_Ack();
		IN_ClearKeysDown ();
		SD_MusicOn();
		Paused = False;
		//if (MousePresent) // PORT
		//	Mouse(MDelta);	// Clear accumulated mouse movement
		return;
	}


//
// F1-F7/ESC to enter control panel
//
	if (
#ifndef DEBCHECK
		scan == sc_F10 ||
#endif
		scan == sc_F9 ||
		scan == sc_F7 ||
		scan == sc_F8)			// pop up quit dialog
	{
		ClearMemory ();
		ClearSplitVWB ();
		VW_ScreenToScreen (displayofs,bufferofs,80,160);
		US_ControlPanel(scan);

		 DrawAllPlayBorderSides ();

		if (scan == sc_F9)
		  StartMusic ();

		PM_CheckMainMem ();
		SETFONTCOLOR(0,15);
		IN_ClearKeysDown();
		return;
	}

	if ( (scan >= sc_F1 && scan <= sc_F9) || scan == sc_Escape)
	{
		StopMusic ();
		ClearMemory ();
		VW_FadeOut ();

		US_ControlPanel(scan);

		SETFONTCOLOR(0,15);
		IN_ClearKeysDown();
		DrawPlayScreen ();
		if (!startgame && !loadedgame)
		{
			VW_FadeIn ();
			StartMusic ();
		}
		if (loadedgame)
			playstate = ex_abort;
		lasttimecount = TimeCount;
		//if (MousePresent) // PORT
		//	Mouse(MDelta);	// Clear accumulated mouse movement
		PM_CheckMainMem ();
		return;
	}

//
// TAB-? debug keys
//
	if (Keyboard[sc_Tab] && DebugOk)
	{
		CA_CacheGrChunk (STARTFONT);
		fontnumber=0;
		SETFONTCOLOR(0,15);
		DebugKeys();
		//if (MousePresent) // PORT
		//	Mouse(MDelta);	// Clear accumulated mouse movement
		lasttimecount = TimeCount;
		return;
	}

}
int Quiesce(POS *p, int ply, int alpha, int beta, int *pv) {

  int best, score, move, new_pv[MAX_PLY];
  MOVES m[1];
  UNDO u[1];
  int op = Opp(p->side);

  // Statistics and attempt at quick exit

  if (InCheck(p)) return QuiesceFlee(p, ply, alpha, beta, pv);

  nodes++;
  CheckTimeout();
  if (abort_search) return 0;
  *pv = 0;
  if (IsDraw(p)) return DrawScore(p);
  if (ply >= MAX_PLY - 1) return Eval.Return(p, 1);

  // Get a stand-pat score and adjust bounds
  // (exiting if eval exceeds beta)

  best = Eval.Return(p, 1);
  if (best >= beta) return best;
  if (best > alpha) alpha = best;

#ifdef USE_QS_HASH
  // Transposition table read

  if (TransRetrieve(p->hash_key, &move, &score, alpha, beta, 0, ply))
    return score;
#endif

  InitCaptures(p, m);

  // Main loop

  while ((move = NextCapture(m))) {

    // Pruning in quiescence search 
	// (not applicable if we are capturing last enemy piece)

	if (p->cnt[op][N] + p->cnt[op][B] + p->cnt[op][R] + p->cnt[op][Q] > 1) {

      // 1. Delta pruning

      if (best + tp_value[TpOnSq(p, Tsq(move))] + 300 < alpha) continue;

      // 2. SEE-based pruning of bad captures

      if (BadCapture(p, move)) continue;
	}

    p->DoMove(move, u);
    if (Illegal(p)) { p->UndoMove(move, u); continue; }

    score = -Quiesce(p, ply + 1, -beta, -alpha, new_pv);

    p->UndoMove(move, u);
    if (abort_search) return 0;

  // Beta cutoff

  if (score >= beta) {
#ifdef USE_QS_HASH
    TransStore(p->hash_key, *pv, best, LOWER, 0, ply);
#endif
    return score;
  }

  // Adjust alpha and score

    if (score > best) {
      best = score;
      if (score > alpha) {
        alpha = score;
        BuildPv(pv, new_pv, move);
      }
    }
  }

#ifdef USE_QS_HASH
  if (*pv) TransStore(p->hash_key, *pv, best, EXACT, 0, ply);
  else     TransStore(p->hash_key,   0, best, UPPER, 0, ply);
#endif

  return best;
}
Beispiel #27
0
void WorldDrawer2d::onIdle(){	//per frame
	
	detectCB();
	detectC();
	srand(time(NULL));
	int gol = detectGol();
	if(gol == 1){
			scor.y++;
			okgol1 = true;
			giveBall(1);

	}else if(gol == 2){
			scor.x++;
			okgol2 = true;
			giveBall(2);
	}
	if(gol!=0){
		DrawScore(1.0f,1.0f,0.0f,1.0f,0.1f,0.1f);
	
	}
	
	srand(time(NULL));
	if(okgol1 || okgol2){

		if(iteration <= 50){
			
			if(okgol2){
				for(int i = 0 ; i < 3; i++){
					for(int j = 6; j < 12; j++){
						float r = (float) rand()/RAND_MAX;
						float g = (float) rand()/RAND_MAX;
						float b = (float) rand()/RAND_MAX;
						spectatori[i * 12 + j]->setcolor(r,g,b);
					}
				}
				
			}else{
				for(int i = 0 ; i < 3; i++){
					for(int j = 0; j < 6; j++){
						float r = (float) rand()/RAND_MAX;
						float g = (float) rand()/RAND_MAX;
						float b = (float) rand()/RAND_MAX;
						spectatori[i * 12 + j]->setcolor(r,g,b);
					}
				}
			}
			iteration ++;
		}else{
			if(okgol2){
				for(int i = 0 ; i < 3; i++){
					for(int j = 6; j < 12; j++){
						spectatori[i * 12 + j]->setcolor(1.0f,1.0f,0.0f);
					}
				}
				
			}else{
				for(int i = 0 ; i < 3; i++){
					for(int j = 0; j < 6; j++){
						spectatori[i * 12 + j]->setcolor(1.0f,0.0f,0.0f);
					}
				}
			}
			okgol1 = false;
			okgol2 = false;
			iteration = 1;

		}
	}

	if(scor.y == 3 || scor.x == 3){
		Sleep(3000);
		int i = rand();
		scor.x = 0;
		scor.y = 0;
		DrawScore(1.0f,1.0f,0.0f,1.0f,0.1f,0.1f);
		if(i % 2== 0){
			giveBall(1);
		}else{
			giveBall(2);
		}

	}



	detectCP();
	
	if(animation){
		
		o1->translate(movex,movey);
		

	}

}
/****************************************************************************
 * ClientWndProc                                                            *
 *  - Typical PM client window procedure.  (see below)                      *
 *  - Standard client window I/O                                            *
 ****************************************************************************/
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
	   RECTL  rcl;
	   SWP	  swp;
	   HPS	  hpsPaint;

    static HPS	  hps;                      /* Permanent HPS                */
    static INT    cx, cy;		    /* Client window dimensions     */
    static BOOL   bSlowUpdateNow = FALSE;   /* Update toggle for asteroids  *
                                             *   and enemy which are slow.  */
    static POINTL ptlCenter;		    /* Center of client window      */

    switch (msg) {
      /* Recieved from WinCreateStdWindow */
      case WM_CREATE:
	/* Get permanent PS for entire window */
	hps = WinGetPS(hwnd);

	/* Load private Asteroid fonts from ASTEROID.DLL */
	if (GpiLoadFonts(hab, "ASTEROID") != GPI_OK) {
            WinReleasePS(hps);
	    WinAlarm(HWND_DESKTOP, WA_WARNING);
	    WinMessageBox(HWND_DESKTOP,NULLHANDLE,
		"Please put ASTEROID.DLL in a directory in your LIBPATH.",
		"Error reading ASTEROID.DLL",
		0,MB_ICONHAND|MB_OK|MB_APPLMODAL);
	    WinPostMsg(hwnd,WM_QUIT,(MPARAM) 0L,(MPARAM) 0L);
	    return (MRESULT) TRUE;
	    }

        /* Register/create logical fonts for use */
	InitFonts(hps);

	/* Display About dialoge box */
	WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, NULLHANDLE,
		  IDD_ABOUT, NULL);

	return 0;

      /* Recieved during attract mode when user starts game */
      case WM_STARTGAME:
        /* Determine the number of players */
	cPlayers = (INT)LONGFROMMP(mp1);

        /* Initialize each player */
	for (Player=0;Player<cPlayers;Player++) {
	    Level[Player] = 1;
	    Ships[Player] = prfProfile.iSHIPS;
	    DeletePhotons();
	    InitAsteroids();
	    InitEnemy();
	    }

        /* Start with player 1 */
	Player = 0;
	iGameMode = GAME_MODE_NEXT;
	iGameModeCnt = GAME_PAUSE_TIME-1;

	/* Hide the pointer if mouse controls are enabled */
	ShowMouse(FALSE);
        
        /* Paint everything */
	WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID);

	return 0;

      /* Recieved at startup and at the completion of a game */
      case WM_INITGAME:
        /* Make mouse visible if we hid it before */
        ShowMouse(TRUE);
        
	/* Fix menu to reflect attract mode */
	EnableMenuItem(hwndMenu, IDM_START, TRUE);
	EnableMenuItem(hwndMenu, IDM_STOP, FALSE);

	/* Initialize player and enemy data structures */
	cPlayers = 0;
	Level[0] = 1;
	for (Player=0;Player<2;Player++) {
	    Score[Player] = 0L;
	    Ships[Player] = 0;
	    DeletePhotons();
	    }
	Player = 0;

	/* Initialize asteroids (and enemy) for attract mode */
	InitAsteroids();
	InitEnemy();

        /* Depending on whether ASTEROID was just started or a game just  *
         *   completed display the "High Score" or "Press 1 or 2" screen. */
	if (SHORT1FROMMP(mp1) == 0) {
	    iGameMode = GAME_MODE_INIT1;
	    iGameModeCnt = GAME_INIT_TIME;
	    }
	else {
	    iGameMode = GAME_MODE_INIT2;
	    iGameModeCnt = GAME_INIT_TIME;
	    }

        /* Paint everything */
	WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID);
	return 0;

      /* Usually recieved from the system, sometime forced by the program to *
       *   ensure the screen is not corrupt.                                 */
      case WM_PAINT:
	/* Clear entire window to insure no "droppings" */
	WinQueryWindowRect(hwnd,&rcl);
        WinFillRect(hps, &rcl, CLR_BLACK);
	WinInvalidateRect(hwnd, &rcl, FALSE);

	/* Get the update region and paint it black */
	hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rcl);
	WinFillRect(hpsPaint, &rcl, CLR_BLACK);
	WinEndPaint(hpsPaint);

        /* Only in normal play mode should we draw the ship */
	if ((iGameMode == GAME_MODE_PLAY) &&
	    (iShipMode[Player] != EXPLOSION) &&
	    (iShipMode[Player] != HYPERSPACE))
	    DrawShip(hps, cx, cy, DRAW_INIT);
	else if ((iGameMode == GAME_MODE_PLAY) &&
		 (iShipMode[Player] == EXPLOSION))
	    ExplodeShip(hps, cx, cy);

        /* Draw the enemy if it is on the screen */
	if (iEnemyMode[Player] != NONE)
	    if (iEnemyMode[Player] != EXPLOSION)
		DrawEnemy(hps, cx, cy,DRAW_INIT);
	    else
		ExplodeEnemy(hps, cx, cy);

        /* Draw photons and asteroids in all modes but the "Enter your *
         *   initials" mode, otherwise draw that screen.               */
	if (iGameMode != GAME_MODE_HIGH) {
	    DrawPhotons(hps, cx, cy, DRAW_INIT);
	    DrawAsteroids(hps, cx, cy, DRAW_INIT);
	    }
	else
	    DrawHighScore(hps, cx, cy, DRAW_INIT);

        /* Always draw the score */
	DrawScore(hps, cx, cy, DRAW_INIT);

	return 0;

      /* Left mouse button down.  This simulates the move/track function *
       *   in the system menu.                                           */
      case WM_BUTTON1DOWN:
        if (prfProfile.bMOUSECONTROL &&
            iGameMode != GAME_MODE_INIT1 &&
            iGameMode != GAME_MODE_INIT2 &&
            !TogglePause(CHECK)) {
	    UPDATE_FIRE(iShipMode[Player], TRUE);
            return (MRESULT)TRUE;
        }
	return WinSendMsg(hwndFrame, WM_TRACKFRAME,
			 (MPARAM) (SHORT1FROMMP(mp2) | TF_MOVE), MPVOID);

      case WM_BUTTON1UP:
        if (prfProfile.bMOUSECONTROL) {
	    UPDATE_FIRE(iShipMode[Player], FALSE);
            return (MRESULT)TRUE;
        }
        return 0;
        
      /* Left mouse button double clicked.  Toggle frame control display. */
      case WM_BUTTON1DBLCLK:
        if (!prfProfile.bMOUSECONTROL ||
            iGameMode == GAME_MODE_INIT1 ||
            iGameMode == GAME_MODE_INIT2 ||
            TogglePause(CHECK)) {
            if (prfProfile.bCONTROLS = !prfProfile.bCONTROLS)
	    	ShowFrameControls();
            else
	    	HideFrameControls();
        }
	return 0;

      case WM_BUTTON2DOWN:
        if (prfProfile.bMOUSECONTROL) {
	    UPDATE_SHIELD(iShipMode[Player], iShipShieldCnt[Player]);
            return (MRESULT)TRUE;
        }
        return 0;
        
      case WM_BUTTON2CLICK:
        if (prfProfile.bMOUSECONTROL) {
            UPDATE_HYPERSPACE(iShipMode[Player], iShipModeCnt[Player]);
            return (MRESULT)TRUE;
        }
        return 0;
        
      /* Right mouse button double clicked.  Display the about dialog box. */
      case WM_BUTTON2DBLCLK:
        if (!prfProfile.bMOUSECONTROL ||
            iGameMode == GAME_MODE_INIT1 ||
            iGameMode == GAME_MODE_INIT2 ||
            TogglePause(CHECK)) {
            WinDlgBox(HWND_DESKTOP, hwndClient, (PFNWP)AboutDlgProc,
            	      NULLHANDLE, IDD_ABOUT, NULL);
        }
	return 0;

      /* User typed a key.  Most of this is self explanatory. */
      case WM_CHAR:
	ProcessChar((CHAR) (CHARMSG(&msg)->vkey-1),
		    CHARMSG(&msg)->fs & KC_VIRTUALKEY,
		    (CHAR) (CHARMSG(&msg)->chr),
		    (BOOL) !(CHARMSG(&msg)->fs & KC_KEYUP));
	return 0;

      /* User entered a command via the menu bar. */
      case WM_COMMAND:
	DoCommand(hwnd, msg, mp1, mp2);
	return 0;

      /* Suspend/un-suspend game depending on focus */
      case WM_SETFOCUS:
	if ((BOOL) SHORT1FROMMP(mp2))
	    TogglePause(SUSPEND_OFF);
	else if (!prfProfile.bBACKGRND)
	    TogglePause(SUSPEND_ON);
	return 0;

      /* Keep track of the client window size.  Profile information is not *
       *   updated here because there are better places (i.e. at exit)     */
      case WM_SIZE:
	cx = (INT)SHORT1FROMMP(mp2);
	cy = (INT)SHORT2FROMMP(mp2);

      /* Keep track of client window position.  Also updates profile info. */
      case WM_MOVE:
	WinQueryWindowPos(hwndFrame,&swp);
	if (!(swp.fl & SWP_MAXIMIZE) && !(swp.fl & SWP_MINIMIZE)) {
	    prfProfile.x  = swp.x;prfProfile.y   = swp.y;
	    prfProfile.cx = swp.cx;prfProfile.cy = swp.cy;
	    }

	if (swp.fl & SWP_MINIMIZE)
	    if (!prfProfile.bBACKGRND) {
		/* Set icon */
		WinSendMsg(hwndFrame, WM_SETICON,
		    (MPARAM) WinLoadPointer(HWND_DESKTOP, NULLHANDLE,
					    ID_RESOURCE), MPVOID);

		TogglePause(SUSPEND_ON);
		}
	    else
		WinSendMsg(hwndFrame, WM_SETICON, MPVOID, MPVOID);
	else
	    TogglePause(SUSPEND_OFF);

	ptlCenter.x = swp.cx / 2;
        ptlCenter.y = swp.cy / 2;
        WinMapWindowPoints(hwndClient, HWND_DESKTOP, &ptlCenter, 1L);

	return 0;

      /* Recieved approximately 31 times a second.  This is the longest and *
       *   ugliest of the messages, partly because there are so many cases  *
       *   to keep track of, partly because it must be highly optimized.    */
      case WM_TIMER:
        if (prfProfile.bMOUSECONTROL &&
            iGameMode != GAME_MODE_INIT1 &&
            iGameMode != GAME_MODE_INIT2) {                   POINTL ptl;
            static BOOL   bUp, bLeft, bRight;

            WinQueryPointerPos(HWND_DESKTOP, &ptl);
            if (bUp || (ptl.y - ptlCenter.y > 0))
	       	UPDATE_THRUST(iShipMode[Player],
            		      bUp = (ptl.y - ptlCenter.y > 0));
            if (bLeft || (ptlCenter.x - ptl.x > 0))
                UPDATE_LEFT(iShipMode[Player],
                	    bLeft = (ptlCenter.x - ptl.x > 0));
            if (bRight || (ptlCenter.x - ptl.x < 0))
                UPDATE_RIGHT(iShipMode[Player],
                 	     bRight = (ptlCenter.x - ptl.x < 0));
            WinSetPointerPos(HWND_DESKTOP, ptlCenter.x, ptlCenter.y);
        }
        
        /* Determine the current game mode */
	switch (iGameMode) {

          /* Either initialization/attract mode screen. */
	  case GAME_MODE_INIT1: case GAME_MODE_INIT2:
            /* Switch screens when count expires */
	    if (--iGameModeCnt == 0) {
		if (iGameMode == GAME_MODE_INIT1)
		    iGameMode = GAME_MODE_INIT2;
		else
		    iGameMode = GAME_MODE_INIT1;
		iGameModeCnt = GAME_INIT_TIME;

                /* Score must be redrawn because the attract mode screens *
                 *   draw the score differently.                          */
		DrawScore(hps, cx, cy, DRAW_REINIT);
		}

            /* Update photons, asteroids, enemy, and score */
	    UpdatePhotons(hps, cx, cy);
	    if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		UpdateAsteroids(hps, cx, cy);
		UpdateEnemy(hps, cx, cy);
		DrawScore(hps, cx, cy, DRAW_REFRESH);
		}
	    break;

          /* Completion of one player's turn or new game */
	  case GAME_MODE_NEXT:
            /* Initially, erase and redraw everything for new player */
	    if (iGameModeCnt-- == GAME_PAUSE_TIME) {
		if ((cPlayers == MAXPLAYERS) &&
                    (Ships[(Player+1) % MAXPLAYERS])) {
		    DrawAsteroids(hps, cx, cy, DRAW_ERASE);
		    DrawPhotons(hps, cx, cy, DRAW_ERASE);
		    Player = (Player+1) % MAXPLAYERS;
		    }
		DrawScore(hps, cx, cy, DRAW_REINIT);
		DrawAsteroids(hps, cx, cy, DRAW_INIT);
		}
            /* During countdown update score and asteroids */
	    else if (iGameModeCnt > 0) {
		if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		    DrawScore(hps, cx, cy, DRAW_REFRESH);
		    UpdateAsteroids(hps, cx, cy);
		    }
		}
            /* At end of countdown start the player */
	    else {
		InitShip();
		InitEnemy();
		iGameMode = GAME_MODE_PLAY;
		DrawScore(hps, cx, cy, DRAW_REINIT);
		}
	    break;

          /* Normal play mode */
	  case GAME_MODE_PLAY:
            /* Update ship, photons, asteroids, enemy, and score */
	    UpdateShip(hps, cx, cy);
	    UpdatePhotons(hps, cx, cy);
	    if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		UpdateAsteroids(hps, cx, cy);
		UpdateEnemy(hps, cx, cy);
                /* Erase old and draw new scores if there is a change*/
		if (bChangeScore) {
		    bChangeScore = FALSE;
		    DrawScore(hps, cx, cy, DRAW_REINIT);
		    }
                /* Else just refresh the score */
		else
		    DrawScore(hps, cx, cy, DRAW_REFRESH);
		}
	    break;

          /* Game over mode.  This is the longest and ugliest case because  *
           *   conditions are highly dependent on the number of players,    *
           *   multiplayer game status, and the number and order of high    *
           *   scores.                                                      */
	  case GAME_MODE_OVER:
            /* Initially, just update the score and number of ships */
	    if (iGameModeCnt-- == GAME_PAUSE_TIME)
		DrawScore(hps, cx, cy, DRAW_REINIT);

            /* During countdown refresh the score and update the asteroids */
	    else if (iGameModeCnt > 0) {
		if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		    DrawScore(hps, cx, cy, DRAW_REFRESH);
		    UpdateAsteroids(hps, cx, cy);
		    }
		}

            /* At the end of the countdown, if there are any other players, *
             *   continue with them.                                        */
	    else {
                /* Countinue on with any remaining players. */
		if ((cPlayers == MAXPLAYERS) &&
                    (Ships[(Player+1) % MAXPLAYERS])) {
                    /* Erase all of the old asteroids. */
		    DrawAsteroids(hps, cx, cy, DRAW_ERASE);

                    /* Setup everything for the next player */
		    Player = (Player+1) % MAXPLAYERS;
		    InitShip();
		    InitEnemy();
		    iGameMode = GAME_MODE_PLAY;
		    DrawAsteroids(hps, cx, cy, DRAW_INIT);
		    DrawScore(hps, cx, cy, DRAW_REINIT);
		    }

                /* Check for new high scores and update table as necessary. */
		else {
                    /* Erase all of the old asteroids. */
		    DrawAsteroids(hps, cx, cy, DRAW_ERASE);


                /* The following if/else block is admittedly a kludge, it is *
                 *   simple and it does work, however.  Ideally it should    *
                 *   sort the high scores and update the high score table in *
                 *   descending order.                                       */

                    /* If player 1 scored higher than player 2 then check *
                     *   player 1 first for a high score.                 */
       		    if (Score[0] > Score[1])
			for (Player=0;Player<cPlayers;Player++)
                            /* If the player's score is > than the lowest, *
                             *   update the high score table.              */
			    if (Score[Player] > prfProfile.lSCORES[9]) {
				UpdateHighScores();
				iGameMode = GAME_MODE_HIGH;
				}
                            /* Otherwise, make sure he is not asked for his *
                             *   initials.                                  */
			    else
				Score[Player] = 0;

                    /* Otherwise, check player 2 first */
		    else
			for (Player=cPlayers;Player>=0;Player--)
                            /* If the player's score is > than the lowest, *
                             *   update the high score table.              */
			    if (Score[Player] > prfProfile.lSCORES[9]) {
				UpdateHighScores();
				iGameMode = GAME_MODE_HIGH;
				}
                            /* Otherwise, make sure he is not asked for his *
                             *   initials.                                  */
			    else
				Score[Player] = 0L;

                    /* If there was no high score, go into attract mode */
		    if (iGameMode != GAME_MODE_HIGH)
			WinSendMsg(hwnd,WM_INITGAME,MPFROMSHORT(1),(MPARAM) 0L);
                    /* Else, check for player 1's initials first then 2's   *
                     * This is not faithful, in the arcade game the player  *
                     *   with the higher score always goes first.           */
		    else {
			if (Score[0] > 0L)
			    Player = 0;
			else
			    Player = 1;
			DrawScore(hps, cx, cy, DRAW_REINIT);
			DrawHighScore(hps, cx, cy, DRAW_INIT);
			}
		    }
		}
	    break;

          /* Mode which prompts players to enter their initials */
	  case GAME_MODE_HIGH:
            /* If the player's position is > 0 then refresh the screen */
	    if (Score[Player] > 0L)
		DrawHighScore(hps, cx, cy, DRAW_REFRESH);
            /* Else, the current player is done go to the next */
	    else if ((cPlayers == MAXPLAYERS) && (Player == 0) &&
		     (Score[1] > 0L)) {
		Player++;
		DrawHighScore(hps, cx, cy, DRAW_REINIT);
		}
            /* If there are no more high scores then go into attract mode */
	    else
		WinSendMsg(hwnd, WM_INITGAME, MPFROMSHORT(1), MPVOID);
	    break;
	  }
	return 0;

      /* Used by help manager */
      case HM_QUERY_KEYS_HELP:
	 return((MRESULT)IDH_CLIENTKEYS);

      /* Recieved always from the system or in the case of an initialization*
       *   error.  Both messages will normally save the profile information.*
       * Ideally the profile section should be moved to a subroutine and the*
       *   the following should be broken into two distinct cases.	    */
      case WM_SAVEAPPLICATION:
      case WM_DESTROY:
	/* If the fonts were not found bApplicationOk will be false, in     *
	 *   that case the window profile information should not be updated.*/
	if (TRUE) {
	    /* Copy window position and size info into profile structure */
	    WinQueryWindowPos(hwndFrame, &swp);
	    if (swp.fl & SWP_MAXIMIZE)
		prfProfile.ulMINMAX = SWP_MAXIMIZE;
	    else if (swp.fl & SWP_MINIMIZE)
		prfProfile.ulMINMAX = SWP_MINIMIZE;
	    else {
		prfProfile.ulMINMAX = 0;
		prfProfile.x  = swp.x;prfProfile.y   = swp.y;
		prfProfile.cx = swp.cx;prfProfile.cy = swp.cy;
		}

	    /* Write profile information */
	    PrfWriteProfileData(HINI_USERPROFILE, szClientClass, "Data",
		&prfProfile, sizeof(PROFILEREC));
	    }

        /* If the application is terminating release the fonts and the hps. */
        if (msg == WM_DESTROY) {
	    /* Make sure mouse is visible if we hid it before */
            ShowMouse(TRUE);
            
	    /* Release font identifiers and DLL resource module */
	    GpiSetCharSet(hps, LCID_DEFAULT);
	    GpiDeleteSetId(hps, LCID_LARGE);
	    GpiDeleteSetId(hps, LCID_SMALL);
	    GpiUnloadFonts(hab, "ASTEROID");

	    /* Release the "permanent" presentation space */
	    WinReleasePS(hps);
            }
	return 0;

      }
    return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
Beispiel #29
0
static unsigned long
penetrate_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  XWindowAttributes xgwa;

  if (st->draw_reset)
    {
      st->draw_reset = 0;
      DrawCities(st, st->draw_xlim, st->draw_ylim);
    }

  XGetWindowAttributes(st->dpy, st->window, &xgwa);
  st->draw_xlim = xgwa.width;
  st->draw_ylim = xgwa.height;

  /* see if just started */
  if (st->loop == 0) {
	 if (st->smart) {
		st->choosypersen = st->econpersen = st->carefulpersen = 100;
		st->lrate = kMinRate; st->aim = 1;
	 }
	 NewLevel(st, st->draw_xlim, st->draw_ylim);
	 DrawScore(st, st->draw_xlim, st->draw_ylim);
  }

  st->loop++;

  if (st->levMissiles == 0) {
	 /* see if anything's still on the screen, to know when to end level */
	 int i;
	 for (i=0;i<kMaxMissiles;i++)
		if (st->missile[i].alive)
		  goto END_CHECK;
	 for (i=0;i<kMaxBooms;i++)
		if (st->boom[i].alive)
		  goto END_CHECK;
	 for (i=0;i<kMaxLasers;i++)
		if (st->laser[i].alive)
		  goto END_CHECK;
	 /* okay, nothing's alive, start end of level countdown */
	 usleep(kLevelPause*1000000);
	 NewLevel(st, st->draw_xlim, st->draw_ylim);
         goto END;
  END_CHECK: ;
  }
  else if ((random() % st->levFreq) == 0) {
	 launch(st, st->draw_xlim, st->draw_ylim, -1);
	 st->levMissiles--;
  }

  if (st->loop - st->lastLaser >= st->lrate) {
	 if (fire(st, st->draw_xlim, st->draw_ylim))
		st->lastLaser = st->loop;
  }

  if ((st->loop & 7) == 0)
    st->draw_reset = 1;

  LoopMissiles(st, st->draw_xlim, st->draw_ylim);
  LoopLasers(st, st->draw_xlim, st->draw_ylim);
  LoopBooms(st, st->draw_xlim, st->draw_ylim);

 END:
  return kSleepTime;
}
Beispiel #30
0
int mines_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile )
{
	struct timeval	tv;
	int				x;

	if ( FBInitialize( 720, 576, 8, fdfb ) < 0 )
		return -1;

	setup_colors();

	if ( RcInitialize( fdrc ) < 0 )
		return -1;


	while( doexit != 3 )
	{
		BoardInitialize();
		DrawBoard( 0 );
		Fx2ShowPig( 470, 300, 176, 144 );

		doexit=0;
		while( !doexit )
		{
			tv.tv_sec = 0;
			tv.tv_usec = 10000;
			x = select( 0, 0, 0, 0, &tv );		/* 100ms pause */
	
			RcGetActCode( );
			MoveMouse();
#ifdef USEX
			FBFlushGrafic();
#endif
		}

		if ( doexit != 3 )
		{
			actcode=0xee;
			if ( doexit ==2 )
				DrawScore();
			else
				DrawGameOver();
#ifdef USEX
			FBFlushGrafic();
#endif
			doexit=0;
			while(( actcode != RC_OK ) && !doexit )
			{
				tv.tv_sec = 0;
				tv.tv_usec = 100000;
				x = select( 0, 0, 0, 0, &tv );		/* 100ms pause */
				RcGetActCode( );
			}
		}
	}

	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;
}