Exemple #1
0
unsigned gameMode(Screen &/*screen*/, const void * /*data*/){

   GameState state;


   Surface blankBack(SUR_UNINIT, 1, 1, BLUE);
   MessageBox fpsDisplay(WHITE,
                         Screen::getScreenRes().x / 2 - 40, 2,
                         1,
                         blankBack,
                         FONT_DEBUG, 0,
                         false, DEBUG);

   //SDL_ShowCursor(SDL_DISABLE);

   //flush event queue before accepting game controls,
   //specifically the mouse up event from clicking "Play Game"
   SDL_Event event;
   while(SDL_PollEvent(&event))
      debug("Unhandled event: ", int(event.type));

   timer_t oldTicks = SDL_GetTicks();
   while (state.loop){

      //time stuff
      timer_t newTicks = SDL_GetTicks();
      timer_t delta = newTicks - oldTicks;
      oldTicks = newTicks;

      double deltaMod = 1.0 * delta / DELTA_MODIFIER;
      
      double fps = delta == 0 ? 0 : 1000 / delta;
      fpsDisplay(format3(fps), "fps  |  ", delta, "ms ");

      //force interface refresh
      pushMouseMove();

      //update state
      updateState(deltaMod, state, fpsDisplay);

      //render
      render(state, fpsDisplay);
   }

   //Clean up
   SDL_ShowCursor(SDL_ENABLE);

   GameOutcome outcome = state.outcome;
   return outcome; //return something more meaningful
}
Exemple #2
0
void MANAGIMENT :: freeMode(){
	int ModelHandle;
	//床読み込み
	ModelHandle = MV1LoadModel("model\\floor\\floor.mqo");
	MV1SetScale(ModelHandle, VGet(250.0f, 100.0f, 250.0f));
	MV1SetPosition(ModelHandle, VGet(0, 0, 0));

	BUILDING buil;

	//弾の配列の確保
	SHOT* mShot;
	mShot = new SHOT(GetColor(255, 255, 0), 15.0f, 85.0f);
	//モデルの読み込み
	PLAYER* p;
	p = new PLAYER(VGet(0, 0, 0), 0.0, mShot);
	//ターゲットの読み込み
	TARGET t;
	t.newTarget();

	while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
		// 画面をクリア
		ClearDrawScreen();
		//床の描画
		MV1DrawModel(ModelHandle);
		
		buil.display();
		//FPSの表示
		fpsDisplay();
		//モデルの操作,描画
		p->control();
		p->display();
		t.display();
		p->doNotMove(buil.collision(p->getPos(), p->getRotate()));
		p->doNotMove(t.collision(p->getPos(), p->getRotate()));
		mShot->collisionTarget(buil.getModelHandle());
		if(mShot->collisionTarget(t.getModelHandle()) > 0){
			t.delTarget();
			t.newTarget();
		}
		//裏画面の内容を表画面に反映
		ScreenFlip();
	}
	MV1DeleteModel(ModelHandle);
	delete mShot;
	delete p;
}
Exemple #3
0
void MANAGIMENT :: battleModeH(){
	int ModelHandle;
	//床読み込み
	ModelHandle = MV1LoadModel("model\\floor\\floor.mqo");
	MV1SetScale(ModelHandle, VGet(250.0f, 100.0f, 250.0f));
	MV1SetPosition(ModelHandle, VGet(0, 0, 0));

	BUILDING buil;

	//弾の配列の確保
	SHOT* mShot;
	SHOT* eShot;
	mShot = new SHOT(GetColor(255, 255, 0), 15.0f, 85.0f);
	eShot = new SHOT(GetColor(255, 0, 0), 15.0f, 85.0f);

	
	READ_INIT* read;
	read = new READ_INIT();
	char src_ip[32];
	int src_port;
	char sin_ip[32];
	int sin_port;
	VECTOR pPos;
	VECTOR ePos;
	float pR, eR;
	read->read(src_ip, &src_port, sin_ip, &sin_port, &pPos, &ePos, &pR, &eR);
	delete read;
	
	NET_TRANS* net;
	net = new NET_TRANS(src_ip, src_port, sin_ip, sin_port);
	net->setBind();
	

	hTh = (HANDLE)_beginthreadex(NULL, 0, &thread_recv, net, 0, &thID);

	while(1){
		DrawFormatString(20, 20, GetColor(0, 0, 0), "通信中");
		if(!nflag2)
			net->send("start");
		if(nflag1)
			net->send("ok");
		if(nflag1 && nflag2)
			break;
		if(ProcessMessage() != 0 || CheckHitKey(KEY_INPUT_ESCAPE) != 0){
			sflag1 = true;
			WaitForSingleObject(hTh, INFINITE);
			CloseHandle(hTh);
			delete net;
			delete mShot;
			delete eShot;
			MV1DeleteModel(ModelHandle);
			return;
		}
		ScreenFlip();
	}
	sflag1 = true;
	WaitForSingleObject(hTh, INFINITE);
	CloseHandle(hTh);
	
	//モデルの読み込み
	PLAYER* p;
	ENEMY_NET* e;
	p = new PLAYER(pPos, pR, mShot, net);
	e = new ENEMY_NET(ePos, eR, eShot, net);
	

	int pH;
	int eH;

	e->start(e);
	while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
		// 画面をクリア
		ClearDrawScreen();
		//床の描画
		MV1DrawModel(ModelHandle);
		buil.display();
		//FPSの表示
		fpsDisplay();
		//モデルの操作,描画
		//プレイヤー
		p->control();
		p->send();

		p->doNotMove(buil.collision(p->getPos(), p->getRotate()));
		mShot->collisionTarget(buil.getModelHandle());
		
		p->display();
		e->display();

		e->enterCritical();
		eShot->collisionTarget(buil.getModelHandle());
		pH = p->damageCheck(eShot);
		e->leaveCritical();

		p->doNotMove(p->collision(e->getPos(), e->getRotate()));
		if(e->getHp() <= 0 || pH <= 0){
			break;
		}
		eH = e->damageCheck(mShot);
		//裏画面の内容を表画面に反映
		ScreenFlip();
	}
	
	
	while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
		p->send();
		// 画面をクリア
		ClearDrawScreen();
		//床の描画
		MV1DrawModel(ModelHandle);
		buil.display();
		//FPSの表示
		SetFontSize(16);
		fpsDisplay();
		p->addCR(0.01f);
		p->display();
		e->display();

		SetFontSize(32);
		pH = p->getHp();
		eH = e->getHp();
		if(pH == eH)
			DrawFormatString(300, 350, GetColor(255, 255, 255), "Draw");
		else if(pH > eH) 
			DrawFormatString(310, 350, GetColor(255, 255, 255), "Win");
		else
			DrawFormatString(300, 350, GetColor(255, 255, 255), "Loss");
		//裏画面の内容を表画面に反映
		ScreenFlip();
	}
	e->stop();
	SetFontSize(16);
	
	
	delete net;

	MV1DeleteModel(ModelHandle);
	delete mShot;
	delete eShot;
	delete p;
	delete e;
}
Exemple #4
0
void MANAGIMENT :: battleModeC(){
	int ModelHandle;
	//床読み込み
	ModelHandle = MV1LoadModel("model\\floor\\floor.mqo");
	MV1SetScale(ModelHandle, VGet(250.0f, 100.0f, 250.0f));
	MV1SetPosition(ModelHandle, VGet(0, 0, 0));

	//弾の配列の確保
	SHOT* mShot;
	SHOT* eShot;
	mShot = new SHOT(GetColor(255, 255, 0), 15.0f, 85.0f);
	eShot = new SHOT(GetColor(255, 0, 0), 15.0f, 85.0f);
	//モデルの読み込み
	PLAYER* p;
	ENEMY* e;
	p = new PLAYER(VGet(0, 0, 3500.0), 0.0f, mShot);
	e = new ENEMY(VGet(0, 0, -3500), PI, eShot);
	BUILDING buil;

	int pH;
	int eH;
	while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
		// 画面をクリア
		ClearDrawScreen();

		//床の描画
		MV1DrawModel(ModelHandle);
		buil.display();
		//FPSの表示
		fpsDisplay();
		//モデルの操作,描画
		//プレイヤー
		p->control();
		p->display();
		//敵
		VECTOR rotateP = p->getRotate();
		e->control(rotateP.y, p->getVector());
		e->display();
		
		p->doNotMove(buil.collision(p->getPos(), p->getRotate()));
		e->doNotMove(buil.collision(e->getPos(), e->getRotate()));
		mShot->collisionTarget(buil.getModelHandle());
		eShot->collisionTarget(buil.getModelHandle());

		p->doNotMove(p->collision(e->getPos(), e->getRotate()));
		e->doNotMove(e->collision(p->getPos(), p->getRotate()));
		
		pH = p->damageCheck(eShot);
		eH = e->damageCheck(mShot);
		if(pH <=0 || eH <= 0)
			break;
		mShot->collisionModel(e->getModelHandle());
		eShot->collisionModel(p->getModelHandle());
		
		//裏画面の内容を表画面に反映
		ScreenFlip();
	}
	
	while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
		// 画面をクリア
		ClearDrawScreen();
		//床の描画
		MV1DrawModel(ModelHandle);
		buil.display();
		//FPSの表示
		SetFontSize(16);
		fpsDisplay();
		p->addCR(0.01f);
		p->display();
		e->display();
		SetFontSize(32);
		pH = p->getHp();
		eH = e->getHp();
		if(pH == eH)
			DrawFormatString(300, 350, GetColor(255, 255, 255), "Draw");
		else if(pH > eH) 
			DrawFormatString(310, 350, GetColor(255, 255, 255), "Win");
		else
			DrawFormatString(300, 350, GetColor(255, 255, 255), "Loss");
		//裏画面の内容を表画面に反映
		ScreenFlip();
	}
	SetFontSize(16);

	MV1DeleteModel(ModelHandle);
	delete mShot;
	delete eShot;
	delete p;
	delete e;
}
Exemple #5
0
unsigned gameMode(Screen &/*screen*/, const void * data){

   GameState state;


   Surface blankBack(SUR_UNINIT, 1, 1, BLUE);
   MessageBox fpsDisplay(WHITE,
                         Screen::getScreenRes().x / 2 - 40, 2,
                         1,
                         blankBack,
                         FONT_DEBUG, 0,
                         false, DEBUG);

   SDL_ShowCursor(SDL_DISABLE);

   //flush event queue before accepting game controls,
   //specifically the mouse up event from clicking "Play Game"
   SDL_Event event;
   while(SDL_PollEvent(&event))
      debug("Unhandled event: ", int(event.type));

   timer_t oldTicks = SDL_GetTicks();

   //data tells us which level we're in.
   int level = *(int*)data;
       
   //first: tutorial
    {
        Surface tutImage(IMAGE_PATH + "level" + format2(level) + ".png");
        screenBuf << tutImage;
        screenBuf.flip();

        //wait for key down or mouse down
        //while (true){
        //    SDL_PollEvent(&event);
        //    if (event.type == SDL_MOUSEBUTTONUP || event.type == SDL_KEYUP)
        //        break;
        //}
        while (true){
            SDL_PollEvent(&event);
            if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYDOWN)
                break;
        }
        while (true){
            SDL_PollEvent(&event);
            if (event.type == SDL_MOUSEBUTTONUP || event.type == SDL_KEYUP)
                break;
        }


    }

    state.setLevel(level);

   while (state.loop){

      //time stuff
      timer_t newTicks = SDL_GetTicks();
      timer_t delta = newTicks - oldTicks;
      oldTicks = newTicks;

      if (delta > 500)
          continue;

      double deltaMod = 1.0 * delta / DELTA_MODIFIER;
      
      double fps = delta == 0 ? 0 : 1000 / delta;
      fpsDisplay(format3(fps), "fps  |  ", delta, "ms ");

      //force interface refresh
      pushMouseMove();

      //update state
      updateState(deltaMod, state, fpsDisplay);

      //render
      render(state, fpsDisplay);
   }

   //Clean up
   SDL_ShowCursor(SDL_ENABLE);

   GameOutcome outcome = state.outcome;
   return outcome; //return something more meaningful
}