Exemplo n.º 1
0
Arquivo: main.cpp Projeto: boredzo/CCX
void RetrieveResources( void )
{
	                            OpeningProgress( 0, 10 );
	InitSound( );				OpeningProgress( 1, 10 );

	InitBackdrop( );			OpeningProgress( 2, 10 );

	GetBlobGraphics( );			OpeningProgress( 3, 10 );
	
	InitNext( );				OpeningProgress( 4, 10 );
	
	InitScore( );				OpeningProgress( 5, 10 );

	InitGrayMonitors( );		OpeningProgress( 6, 10 );
	
	InitOpponent( );			OpeningProgress( 7, 10 );

	InitStage( );   // must run after backdrop window is open
	InitGameTickCount( );

	InitPlayers( ); // must run after backdrop window is open
	InitFont( ); 
	InitZapStyle( );// must run after fonts are inited
					            OpeningProgress( 8, 10 );
	
	InitBlitter( ); // must run after player windows are open
	InitPlayerWorlds( );  		OpeningProgress( 9, 10 );
	
	InitVictory( );	// must run after fonts are inited			
	InitTweak( );				OpeningProgress( 10, 10 );
}
Exemplo n.º 2
0
void GameScene::Initialize(HWND& hWnd)
{
	if(!Manage_Scene::Initialized())
	{
		Manage_Scene::Initialize(hWnd);
	}
	
	/*
	if (!SUCCEEDED(D3DXCreateTextureFromFileEx(gDevice->g_pd3dDevice, background, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, NULL, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
		D3DX_FILTER_NONE, D3DX_FILTER_NONE, NULL, NULL, NULL, &backGroundTexture)))
	{
		MessageBox(NULL,_T("Image Load error"),NULL,NULL);
	}
	*/
	ZeroMemory(&g_GoalLine, sizeof(g_GoalLine));
	D3DXCreateTextureFromFileEx(gDevice->g_pd3dDevice, _T(IMG_FIREBALLOON), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, NULL, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
		D3DX_FILTER_NONE, D3DX_FILTER_NONE, NULL, NULL, NULL, &balloonTexture);
	D3DXCreateTextureFromFileEx(gDevice->g_pd3dDevice, _T(IMG_BG), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, NULL, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
		D3DX_FILTER_NONE, D3DX_FILTER_NONE, NULL, NULL, NULL, &backGroundTexture); 
	D3DXCreateTextureFromFileEx(gDevice->g_pd3dDevice, _T(IMG_GOALLINE), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, NULL, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
		D3DX_FILTER_NONE, D3DX_FILTER_NONE, NULL, NULL, NULL, &g_GoalLine.Texture);
	D3DXCreateFont(gDevice->g_pd3dDevice, 30,15, 255, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("바탕체"), &scoreFont);
	D3DXCreateFont(gDevice->g_pd3dDevice, 30,15, 255, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("바탕체"), &lifeFont);
	D3DXCreateFont(gDevice->g_pd3dDevice, 30,15, 255, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("바탕체"), &stageFont);

	if (!SUCCEEDED(D3DXCreateSprite(gDevice->g_pd3dDevice, &spriter)))
	{
		MessageBox(NULL,_T("Error on generating spriter"),NULL,NULL);
	}
	
	InitStage(1);
}
Exemplo n.º 3
0
void nav_oval(uint8_t p1, uint8_t p2, float radius) {
  radius = - radius; /* Historical error ? */

  float alt = waypoints[p1].a;
  waypoints[p2].a = alt;

  float p2_p1_x = waypoints[p1].x - waypoints[p2].x;
  float p2_p1_y = waypoints[p1].y - waypoints[p2].y;
  float d = sqrtf(p2_p1_x*p2_p1_x+p2_p1_y*p2_p1_y);

  /* Unit vector from p1 to p2 */
  float u_x = p2_p1_x / d;
  float u_y = p2_p1_y / d;

  /* The half circle centers and the other leg */
  struct point p1_center = { waypoints[p1].x + radius * -u_y,
                             waypoints[p1].y + radius * u_x,
                             alt  };
  struct point p1_out = { waypoints[p1].x + 2*radius * -u_y,
                          waypoints[p1].y + 2*radius * u_x,
                          alt  };

  struct point p2_in = { waypoints[p2].x + 2*radius * -u_y,
                         waypoints[p2].y + 2*radius * u_x,
                         alt  };
  struct point p2_center = { waypoints[p2].x + radius * -u_y,
                             waypoints[p2].y + radius * u_x,
                             alt  };

  float qdr_out_2 = M_PI - atan2f(u_y, u_x);
  float qdr_out_1 = qdr_out_2 + M_PI;
  if (radius < 0) {
    qdr_out_2 += M_PI;
    qdr_out_1 += M_PI;
  }
  float qdr_anticipation = (radius > 0 ? -15 : 15);

  switch (oval_status) {
  case OC1 :
    nav_circle_XY(p1_center.x,p1_center.y, -radius);
    if (NavQdrCloseTo(DegOfRad(qdr_out_1)-qdr_anticipation)) {
      oval_status = OR12;
      InitStage();
      LINE_START_FUNCTION;
    }
    return;

  case OR12:
    nav_route_xy(p1_out.x, p1_out.y, p2_in.x, p2_in.y);
    if (nav_approaching_xy(p2_in.x, p2_in.y, p1_out.x, p1_out.y, CARROT)) {
      oval_status = OC2;
      nav_oval_count++;
      InitStage();
      LINE_STOP_FUNCTION;
    }
    return;

  case OC2 :
    nav_circle_XY(p2_center.x, p2_center.y, -radius);
    if (NavQdrCloseTo(DegOfRad(qdr_out_2)-qdr_anticipation)) {
      oval_status = OR21;
      InitStage();
      LINE_START_FUNCTION;
    }
    return;

  case OR21:
    nav_route_xy(waypoints[p2].x, waypoints[p2].y, waypoints[p1].x, waypoints[p1].y);
    if (nav_approaching_xy(waypoints[p1].x, waypoints[p1].y, waypoints[p2].x, waypoints[p2].y, CARROT)) {
      oval_status = OC1;
      InitStage();
      LINE_STOP_FUNCTION;
    }
    return;

  default: /* Should not occur !!! Doing nothing */
    return;
  }
}
Exemplo n.º 4
0
/** Navigation along a figure 8. The cross center is defined by the waypoint
    [target], the center of one of the circles is defined by [c1]. Altitude is
    given by [target].
    The navigation goes through 6 states: C1 (circle around [c1]), R1T, RT2
    (route from circle 1 to circle 2 over [target]), C2 and R2T, RT1.
    If necessary, the [c1] waypoint is moved in the direction of [target]
    to be not far than [2*radius].
*/
void nav_eight(uint8_t target, uint8_t c1, float radius) {
  float aradius = fabs(radius);
  float alt = waypoints[target].a;
  waypoints[c1].a = alt;

  float target_c1_x = waypoints[c1].x - waypoints[target].x;
  float target_c1_y = waypoints[c1].y - waypoints[target].y;
  float d = sqrtf(target_c1_x*target_c1_x+target_c1_y*target_c1_y);
  d = Max(d, 1.); /* To prevent a division by zero */

  /* Unit vector from target to c1 */
  float u_x = target_c1_x / d;
  float u_y = target_c1_y / d;

  /* Move [c1] closer if needed */
  if (d > 2 * aradius) {
    d = 2*aradius;
    waypoints[c1].x = waypoints[target].x + d*u_x;
    waypoints[c1].y = waypoints[target].y + d*u_y;
  }

  /* The other center */
  struct point c2 = {
    waypoints[target].x - d*u_x,
    waypoints[target].y - d*u_y,
    alt };

  struct point c1_in = {
    waypoints[c1].x + radius * -u_y,
    waypoints[c1].y + radius * u_x,
    alt };
  struct point c1_out = {
    waypoints[c1].x - radius * -u_y,
    waypoints[c1].y - radius * u_x,
    alt };

  struct point c2_in = {
    c2.x + radius * -u_y,
    c2.y + radius * u_x,
    alt };
  struct point c2_out = {
    c2.x - radius * -u_y,
    c2.y - radius * u_x,
    alt };

  float qdr_out = M_PI - atan2f(u_y, u_x);
  if (radius < 0)
    qdr_out += M_PI;

  switch (eight_status) {
  case C1 :
    NavCircleWaypoint(c1, radius);
    if (NavQdrCloseTo(DegOfRad(qdr_out)-10)) {
      eight_status = R1T;
      InitStage();
    }
    return;

  case R1T:
    nav_route_xy(c1_out.x, c1_out.y, c2_in.x, c2_in.y);
    if (nav_approaching_xy(waypoints[target].x, waypoints[target].y, c1_out.x, c1_out.y, 0)) {
      eight_status = RT2;
      InitStage();
    }
    return;

  case RT2:
    nav_route_xy(c1_out.x, c1_out.y, c2_in.x, c2_in.y);
    if (nav_approaching_xy(c2_in.x, c2_in.y, c1_out.x, c1_out.y, CARROT)) {
      eight_status = C2;
      InitStage();
    }
    return;

  case C2 :
    nav_circle_XY(c2.x, c2.y, -radius);
    if (NavQdrCloseTo(DegOfRad(qdr_out)+10)) {
      eight_status = R2T;
      InitStage();
    }
    return;

  case R2T:
    nav_route_xy(c2_out.x, c2_out.y, c1_in.x, c1_in.y);
    if (nav_approaching_xy(waypoints[target].x, waypoints[target].y, c2_out.x, c2_out.y, 0)) {
      eight_status = RT1;
      InitStage();
    }
    return;

  case RT1:
    nav_route_xy(c2_out.x, c2_out.y, c1_in.x, c1_in.y);
    if (nav_approaching_xy(c1_in.x, c1_in.y, c2_out.x, c2_out.y, CARROT)) {
      eight_status = C1;
      InitStage();
    }
    return;

  default:/* Should not occur !!! Doing nothing */
    return;
  } /* switch */
}
Exemplo n.º 5
0
uint
iAuction::MainStage(uint s){

  InitStage();

  int sink = -1; //here sink is a column
  int i_bar= -1;
  int j_bar= -1;

  SV.insert(s);
  UpdateLabeledRows(s);
  while(sink == -1){
    double delta = std::numeric_limits<double>::infinity();
    for(set<uint>::iterator itr=LU.begin(); itr!=LU.end(); itr++){
      uint cur_j = heaps[*itr].top().first;
      while(SV.find(cur_j)!=SV.end()){
	heaps[*itr].pop();
        cur_j = heaps[*itr].top().first;
      }
      if(SV.find(cur_j) == SV.end()){
        if((orig_matrix[*itr][GetAssignedCol(*itr)]-Deltas[GetAssignedCol(*itr)]) - (orig_matrix[*itr][cur_j] - Deltas[cur_j]) 
		< delta){
          delta = (orig_matrix[*itr][GetAssignedCol(*itr)]-Deltas[GetAssignedCol(*itr)]) - (orig_matrix[*itr][cur_j] - Deltas[cur_j]);
          j_bar = cur_j;
          i_bar = *itr;
        }
      }//if SV
    }//for
    
    assert(j_bar != -1 && i_bar != -1);
    //pred[i_bar] = j_bar;
    pred[i_bar].push_back(j_bar);
    assert(pred_j[j_bar] == -1);
    pred_j[j_bar] = i_bar;
    for(set<uint>::iterator itr=SV.begin(); itr!=SV.end(); itr++)
      Deltas[*itr] += delta;
    price_cnt ++;
    
    if(!GetNumAsgnRows(j_bar)){
      sink = j_bar;
    }
    else{
      //update LU SV
      SV.insert(j_bar);
      UpdateLabeledRows(j_bar);
    }
#if 0
    //display data
    _cout("\tset SV: ");
    DisplaySet(SV);
    _cout("\tset LU: ");
    DisplaySet(LU);
    //_cout("\tpred: ");
    //DisplayVec<int>(pred);
    _cout("\tdalta="<<delta<<"; j*="<<j_bar<<endl);
    _cout("\tDeltas: ");
    DisplayVec<double>(Deltas);
    _cout(endl);
#endif
  }//while sink

  assert(sink!=-1);

  //update the assignment and allocation
  allocated_cols.insert(sink);
  int j_asgn=-1;
  uint cnt = 0;
  uint true_pred = sink;

  while(j_asgn!=(int)s){ 
    if(cnt++ > col_size)
      throw EXCEPTION_BROKEN;
    j_asgn=assignment[i_bar];
    assignment[i_bar] = true_pred;
#if 0
    _cout("\ti_bar="<<i_bar<<" j_asgn="<<j_asgn<<" pred="<<true_pred<<endl);
#endif

   if(pred_j[j_asgn] != -1){
     i_bar=pred_j[j_asgn];
      for(uint j=0; j<pred[i_bar].size(); j++)
          if((int)pred[i_bar][j] == j_asgn){
            true_pred = pred[i_bar][j];
            break;
          }
   } 
   //assert(i<row_size || j_asgn==(int)s);
  }//while

  //update num_allocation, by re-scanning num of assigned rows in each column
  UpdateRecordAllocations();

#if 0
  _cout("Stats of this stage:"<<endl);
  _cout("\tstart col = "<<s<<"; sink col = "<<sink<<endl);
  _cout("\tassignment: ");
  DisplayVec<uint>(assignment);
  _cout("\tallocation: ");
  DisplayVec<uint>(allocation);
  _cout("\trecord_allocations: ");
  DisplayVec<uint>(record_allocations);
  _cout("transformed matrix with current assignment and Deltas: "<<endl);
  DisplayMatrix(orig_matrix, assignment, Deltas);
  _cout("-----------------------------------------------------"<<endl);
#endif

  return (uint)sink;
}
Exemplo n.º 6
0
void GameScene::Draw(float gameTime, User& user)
{
	RECT rcSrcRect;
	RECT bgRect;
	D3DXVECTOR3 vecCenter;

	static int offset =0;

	rcSrcRect.left = 0;
	rcSrcRect.top = 0;
	rcSrcRect.right = 59;
	rcSrcRect.bottom = 88;

	vecCenter.x = .0f;
	vecCenter.y = .0f;
	vecCenter.z = .0f;

	srand((unsigned int)time(NULL));
	
	if( currentEnemyNum < om->ManageMaxEnemy() )
	{
		if(GetTickCount()%60==0)
		{
			om->insertObj();
			currentEnemyNum++;
		}
	}
	
	if ((GetKeyState(VK_LEFT) & 0x80000000) && vecPosition.x > 0) 	
			vecPosition.x -= 7.0f;
	if ((GetKeyState(VK_RIGHT) & 0x80000000) && vecPosition.x+rcSrcRect.right < SCREEN_WIDTH) 
		vecPosition.x += 7.0f;
	if ((GetKeyState(VK_UP) & 0x80000000) && vecPosition.y > 0 ) 
		vecPosition.y -= 5.0f;
	if ((GetKeyState(VK_DOWN) & 0x80000000) && vecPosition.y+rcSrcRect.bottom < SCREEN_HEIGHT) 	
		vecPosition.y += 10.0f;

	// 충돌체크
	// 보이는 적중에 부딪히면 파괴
	if(currentEnemyNum>=0)
	{	
		for(int i=0; i<om->ManageMaxEnemy(); i++)
			if(om->getAlive(i))
			{
				if( !(om->getEnemy(i).manageMoving(gDevice->g_pd3dDevice, i*100+100)) ) 
				{
					//새의 위치가 위아래로 벗어나면 파괴
					om->deleteObj(i);
					currentEnemyNum--;
				} 
				else 
				{
					// 충돌체크 보이는 적중에 부딪히면 파괴		
					D3DXVECTOR3* pos = om->getEnemy(i).getPosition();
					if( vecPosition.x < pos->x + BIRD_RECT_RIGHT
						&&pos->x < vecPosition.x + rcSrcRect.right
						&&vecPosition.y < pos->y + BIRD_RECT_BOTTOM
						&&pos->y < vecPosition.y + rcSrcRect.bottom)
					{	
						currentScore -= 50;
						if(currentScore < 0)
							currentScore =0;							
						life -= 10;
						om->deleteObj(i);
						currentEnemyNum--;
					}	
				}
			}
	}

	if(life<=0)
	{
		MessageBox(NULL, _T("Oops! ,You are dead!"), NULL, MB_OK);
		exit(1);
	}
	
	gDevice->Clear(D3DCOLOR_XRGB(0,0,255));
	gDevice->Begin();

	if(spriter != NULL && balloonTexture != NULL && backGroundTexture!= NULL)
	{
		spriter->Begin(D3DXSPRITE_ALPHABLEND);

		bgRect.left = 0;
		bgRect.right = SCREEN_WIDTH;
		bgRect.top = 0;
		bgRect.bottom = SCREEN_HEIGHT;
		vecPosBG.y = -(float)offset;
		spriter->Draw(backGroundTexture, &bgRect, NULL, &vecPosBG, 0xFFFFFFFF);

		bgRect.top = 0;
		bgRect.bottom = offset;
		
		D3DXVECTOR3 vecPosBG2(0,(float)(SCREEN_HEIGHT-offset),0);
		spriter->Draw(backGroundTexture, &bgRect, NULL, &vecPosBG2, 0xFFFFFFFF);
		offset++;
		offset = offset%SCREEN_HEIGHT;

		//시작하고 10초뒤에 골라인 올라옴
		time_t crtTime;
		time(&crtTime);
		if(goalTime < crtTime)
		{
			g_GoalLine.Position.y -= 3.0f;
			spriter->Draw( g_GoalLine.Texture, &g_GoalLine.Source, &g_GoalLine.Center, &g_GoalLine.Position, 0xffffffff );
		}
		
		if(currentEnemyNum > 0)
		{
			for(int i=0; i<om->ManageMaxEnemy(); i++)
			{
				if(om->getAlive(i) == TRUE)
					spriter->Draw( om->getEnemy(i).getTexture(), om->getEnemy(i).getSource(), om->getEnemy(i).getCenter(), om->getEnemy(i).getPosition(), 0xffffffff );
			}
		}

		// 골라인과 플레이어가 만나면 
		if ( g_GoalLine.Position.y < vecPosition.y )
		{
			if(currentStage == 5)
			{
				// 스테이지 클리어
				user.SetScore(currentScore);
				user.SetStage(currentStage);
				user.SetUserState(user.GAME_CLEAR);
				SetGameOver(true);
				//MessageBox(NULL, _T("ALL STAGE CLEAR!, Congraturations!"), NULL, MB_OK);
				//exit(0);
			}
			currentStage++;
			delete om;
			InitStage(currentStage);
		}

		spriter->Draw(balloonTexture, &rcSrcRect, &vecCenter, &vecPosition, 0xffffffff);

		RECT scoreRect = {400,20,-1,-1};
		RECT lifeRect = {20,20,-1,-1};
		RECT stageRect = {220,20,-1,-1};
		
		if(prevTimer == NULL)
			prevTimer = crtTime;
		if(crtTime-prevTimer != 0)
		{
			currentScore+=5;
		}
		prevTimer = crtTime;

		std::string scoreStr = "SCORE ";
		scoreStr.append(std::to_string(currentScore));

		std::string lifeStr = "LIFE ";
		lifeStr.append(std::to_string(life));

		std::string stageStr = "STAGE ";

		stageStr.append(std::to_string(om->GetStageNumber()));

		std::wstring scoreWstr = std::wstring(scoreStr.begin(), scoreStr.end());
		std::wstring lifeWstr = std::wstring(lifeStr.begin(), lifeStr.end());
		std::wstring stageWstr = std::wstring(stageStr.begin(), stageStr.end());
		//LPCWSTR scoreResult = _T(scoreStr.c_str());
		if(scoreFont)
			scoreFont->DrawText(spriter, scoreWstr.c_str(), scoreWstr.length(), &scoreRect, DT_NOCLIP, D3DXCOLOR(0,0,0,1));

		if(lifeFont)
			lifeFont->DrawText(spriter, lifeWstr.c_str(), lifeWstr.length(), &lifeRect,DT_NOCLIP, D3DXCOLOR(0,0,0,1));
		if(stageFont)
			stageFont->DrawText(spriter, stageWstr.c_str(), stageWstr.length(), &stageRect, DT_NOCLIP, D3DXCOLOR(0,0,0,1));
	
		spriter->End();
	}
	//else
		//MessageBox(NULL, _T("Error"), NULL, NULL);
	gDevice->End();
	gDevice->Present();
}