Пример #1
0
void set_60hz(){
	static int term;
	static int t;

	term = GetNowCount() - t;
	if(16-term > 0){
		Sleep(16-term);
	}

	t = GetNowCount();
}
Пример #2
0
void Fps::Move() {
	if (cnt == 0) {
		start = GetNowCount();
	}
	if (cnt == N) {
		int end = GetNowCount();
		fps = 1000.f / ((end - start) / (float)N);
		cnt = 0;
		start = end;
	}
	cnt++;
}
Пример #3
0
bool Update(){
	if (mCount == 0){ //1フレーム目なら時刻を記憶
		mStartTime = GetNowCount();
	}
	if (mCount == N){ //60フレーム目なら平均を計算する
		int t = GetNowCount();
		mFps = 1000 / ((t - mStartTime) / (float)N);
		mCount = 0;
		mStartTime = t;
	}
	mCount++;
	return true;
}
Пример #4
0
void client_main(){
  static Mode status = UNCONNECTED;
	ClientConnection client(PORT, SERVER_IP);
	Input input;
	decoder.initialize();

	while(!client.connect()){
	  ClearDrawScreen();
	  const static int titleGraph = LoadGraph( "../graphic/ShootingTitle.jpg");
	  DrawGraph( 0, 0, titleGraph, false);
	  DrawString( 300, 500, "Now connecting", WHITE);
		ScreenFlip();
		int lastTry = GetNowCount();
		while(GetNowCount() - lastTry < 1000){
			Sleep(20);

			// Windows 特有の面倒な処理をDXライブラリにやらせる
	    // -1 が返ってきたらループを抜ける
	    if( ProcessMessage() < 0 ) exit(0);
  
	    // もしESCキーが押されていたらループから抜ける
	    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) exit(0);
		}
	}
  status = CONNECTED;

  // 移動ルーチン
	int fpsTimer = GetNowCount();
  while( 1 ){
    input.getKeyInput();
	  client.send(input.encode());
	  vector<int> clientMessage;
	  if(client.receive(clientMessage) >= 0){
  		while(client.receive(clientMessage) >= 0);
		  decoder.draw(clientMessage);
	  }
	  int term;
	  term = GetNowCount()-fpsTimer;
	  if(8-term>0){
  		Sleep(8-term);
	  }
	  fpsTimer = GetNowCount();
  
    // Windows 特有の面倒な処理をDXライブラリにやらせる
    // -1 が返ってきたらループを抜ける
    if( ProcessMessage() < 0 ) break ;
  
    // もしESCキーが押されていたらループから抜ける
    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) break;
  }
}
Пример #5
0
void Fps::UpData(void){

	if( count == 0 ){ //1フレーム目なら時刻を記憶
		startTime = GetNowCount();
	}
	if( count == N ){ //60フレーム目なら平均を計算する
		int t = GetNowCount();
		fps = 1000.f/((t-startTime)/(float)N);
		count = 0;
		startTime = t;
	}
	count++;

}
Пример #6
0
void Wait(){
	int tookTime = GetNowCount() - mStartTime;	//かかった時間
	int waitTime = mCount * 1000 / FPS - tookTime;	//待つべき時間
	if (waitTime > 0){
		Sleep(waitTime);	//待機
	}
}
Пример #7
0
void load(){
	int t;
	SetCreateSoundDataType( DX_SOUNDDATATYPE_MEMPRESS ) ;

	t=GetNowCount();
	img_board[10] = LoadGraph("../dat/img/board/10.png");
	img_board[11] = LoadGraph("../dat/img/board/11.png");
	img_board[12] = LoadGraph("../dat/img/board/12.png");
	img_board[20] = LoadGraph("../dat/img/board/20.png");
	img_chetc[0]	= LoadGraph( "../dat/img/char/atari.png" );
	img_chetc[2]	= LoadGraph( "../dat/img/char/ball.png" );
	img_eff_bom[0] = LoadGraph( "../dat/img/effect/bom0.png" );
	img_eff_bom[1] = LoadGraph( "../dat/img/effect/bom1.png" );
	img_eff_bom[2] = LoadGraph( "../dat/img/char/body.png" );
	img_eff_bom[3] = LoadGraph( "../dat/img/bullet/bom_title0.png" );
	img_etc[1]	= LoadGraph( "../dat/img/enemy/hp.png" );
	img_etc[2]	= LoadGraph( "../dat/img/enemy/bossback.png" );
	img_etc[5]	= LoadGraph( "../dat/img/enemy/bossback3.png" );
	img_etc[6]	= LoadGraph( "../dat/img/enemy/bossback4.png" );
	img_etc[7]	= LoadGraph( "../dat/img/enemy/hp_boss.png" );//ボスのHP
	LoadDivGraph( "../dat/img/bullet/b0.png" , 5 , 5 , 1 , 76 , 76 , img_bullet[0] ) ;
	LoadDivGraph( "../dat/img/bullet/b1.png" , 6 , 6 , 1 , 22 , 22 , img_bullet[1] ) ;
	LoadDivGraph( "../dat/img/bullet/b2.png" , 10 , 10 , 1 , 5 , 120 , img_bullet[2] ) ;
	LoadDivGraph( "../dat/img/bullet/b3.png" , 5 , 5 , 1 , 19 , 34 , img_bullet[3] ) ;
	LoadDivGraph( "../dat/img/bullet/b4.png" , 10 , 10 , 1 , 38 , 38 , img_bullet[4]  ) ;
	LoadDivGraph( "../dat/img/bullet/b5.png" , 3 , 3 , 1 , 14 , 16 , img_bullet[5] ) ;
	LoadDivGraph( "../dat/img/bullet/b6.png" , 3 , 3 , 1 , 14 , 18 , img_bullet[6] ) ;
	LoadDivGraph( "../dat/img/bullet/b7.png" , 10 , 10 , 1 , 16 , 16 , img_bullet[7] ) ;
	LoadDivGraph( "../dat/img/bullet/b8.png" , 10 , 10 , 1 , 12 , 18 ,img_bullet[8] ) ;
	LoadDivGraph( "../dat/img/bullet/b9.png" , 3 , 3 , 1 , 13 , 19 , img_bullet[9] ) ;
	LoadDivGraph( "../dat/img/bullet/b10.png" , 8 , 8 , 1 , 8 , 8 , img_bullet[10] ) ;
	LoadDivGraph( "../dat/img/bullet/b11.png" , 8 , 8 , 1 , 35 , 32 , img_bullet[11] ) ;
	LoadDivGraph( "../dat/img/bullet/l0.png" , 2 , 2 , 1 , 30 , 460 , img_lazer[0] ) ;
	LoadDivGraph( "../dat/img/bullet/l0_moto.png" , 2 , 2 , 1 , 70 , 70 , img_lazer_moto[0] ) ;
	LoadDivGraph( "../dat/img/enemy/hit_effect.png" , 5 , 5 , 1 , 140 , 140 , img_del_effect ) ;
	LoadDivGraph( "../dat/img/char/riria.png" , 8 , 8 , 1 , 100 , 100 , img_dot_riria ) ;
	LoadDivGraph( "../dat/img/char/0.png" , 12 , 4 , 3 , 73 , 73 , img_ch[0] ) ;
	LoadDivGraph( "../dat/img/enemy/0.png" , 9 , 3 , 3 , 32 , 32 , img_enemy[0] ) ;
	img_cshot[0]=LoadGraph("../dat/img/char/bl_00.png");
	img_cshot[1]=LoadGraph("../dat/img/char/bl_01.png");
	img_back[0] = LoadGraph("../dat/img/back/0/back0.png");
	img_back[10] = LoadGraph("../dat/img/back/10/kotei0.png");
	img_back[11] = LoadGraph("../dat/img/back/10/scroll0.png");
	sound_se[0]=LoadSoundMem("../dat/se/enemy_shot.wav");
	sound_se[1]=LoadSoundMem("../dat/se/enemy_death.wav");
	sound_se[2]=LoadSoundMem("../dat/se/cshot.wav");
	sound_se[3]=LoadSoundMem("../dat/se/char_death.wav");
	sound_se[8]=LoadSoundMem("../dat/se/hit.wav");
	sound_se[11]=LoadSoundMem("../dat/se/boss_change.wav");
	sound_se[14]=LoadSoundMem("../dat/se/bom0.wav");
	sound_se[15]=LoadSoundMem("../dat/se/bom1.wav");
	sound_se[33]=LoadSoundMem("../dat/se/lazer.wav");
	//sound_se[99]=LoadSoundMem("../dat/music/youmu.wav");//反魂蝶のBGMを再生する場合はココに音楽ファイルを用意して下さい

	ChangeVolumeSoundMem( 50, sound_se[0] ) ;
	ChangeVolumeSoundMem(128, sound_se[1] ) ;
	ChangeVolumeSoundMem(128, sound_se[2] ) ;
	ChangeVolumeSoundMem( 80, sound_se[3] ) ;
	ChangeVolumeSoundMem( 80, sound_se[8] ) ;
}
Пример #8
0
void Woman::update()
{
	elapsedTime = GetNowCount() - beginTime;
	if (elapsedTime > 20000)
	{
		this->isVisible = false;
	}
	if (!isVisible)return;
	Vector2 target = Vector2(500,335);
	target -= this->getPosition();
	if (target.length() < 1)
	{
		gamemodes->sceneMode = 2;
	}
	target *= (1.0/target.length());
	Vector2 newPos = this->getPosition() - target;
	for (std::list<Botch>::iterator itr = this->botches->begin(); itr != this->botches->end(); itr++)
	{
		Botch b = *itr;
		if (!b.isVisible)continue;
		Vector2 dist =  b.getPosition()-newPos;
		if (dist.length() < 100)
		{
			Vector2 newDist = Vector2(-dist.y, dist.x);
			newPos = this->getPosition() - newDist;
		}
	}
	this->setPosition(newPos);
	
}
Пример #9
0
void Fps::Wait(void){
	int tookTime = GetNowCount() - startTime;	//かかった時間
	int waitTime = count*1000/FPS - tookTime;	//待つべき時間
	if( waitTime > 0 ){
		Sleep(waitTime);	//待機
	}
}
Пример #10
0
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){
	ChangeWindowMode(TRUE);
	gFPS.SetDefaultFPS(60);
	if( DxLib_Init() == -1 ){
		 return -1;	// エラーが起きたら直ちに終了
	}
	ChangeFontType(DX_FONTTYPE_ANTIALIASING_EDGE);
	SetMouseDispFlag(TRUE);
	gameManager.SetStage(gameManager.Load);
	for(;;){ //メインループ
		ClearDrawScreen();
		if(ProcessMessage()==-1 || GameMain()==1){break;} //ゲーム本体を実行
		//FPS描画
		int NowFPS = gFPS.Get();
		int Col = (int)(255 * NowFPS / gFPS.GetDefaultFPS());
		//DrawFormatString(500,450,GetColor(255,Col,Col),"FPS: %d",NowFPS);
		ScreenFlip();
		if((GetJoypadInputState( DX_INPUT_KEY_PAD1 ) & PAD_INPUT_10) !=0){
			GetDateTime( &Date );
			std::stringstream fname;
			fname <<"img" << Date.Year << Date.Mon << Date.Day <<Date.Hour <<Date.Min <<GetNowCount() << ".png";
			SaveDrawScreenToPNG( 0 , 0 , 480 , 480 ,fname.str().c_str()) ;
		}
		gFPS.Fix();
	}

	DxLib_End() ;		// DXライブラリ使用の終了処理

	return 0 ;		// ソフトの終了
}
Пример #11
0
void FPSer::Wait()
{
	int tookTime = GetNowCount() - time_a;	//かかった時間
	int waitTime = count * 1000 / setfps - tookTime;	//待つべき時間
	if (waitTime > 0) {
		Sleep(waitTime);	//待機
	}
}
Пример #12
0
void fps(){
    int i;
    static int t=0,ave=0,f[60];
 
    f[fpsc%60]=GetNowCount()-t;
    t=GetNowCount();
    if(fpsc%60==59){
        ave=0;
        for(i=0;i<60;i++)
            ave+=f[i];
        ave/=60;
    }
    if(ave!=0){
        DrawFormatString(0, 0,GetColor(255,255,255),"%.1fFPS",1000.0/(double)ave);
    }
    return;
}
Пример #13
0
Shooting::Shooting(){
  gameClock = 0;
  fpsTimer = GetNowCount();
  addHero();
  addHero();
  addHero();
  addHero();
}
Пример #14
0
void FallingObject::Init(int x, int y)
{
	this->x = x;
	this->y = y;
	this->starttime = GetNowCount();
	exist=true;
	once=false;
}
Пример #15
0
void gamewait() {

	int term = 0;

	term = GetNowCount();
	(1000 / 60 > term)? Sleep(1000 / 60 - term) : Sleep(0);

	start = clock();
}
Пример #16
0
//FPS表示関数
void MANAGIMENT :: fpsDisplay(){
	static int time1=0, time2=0;
	static int count=0;
	static double fps=0.0;
	
	if(count == 0)
		time1=GetNowCount();	//1周目の時間取得
	
	if(count == 49){
		time2=GetNowCount();	//50周目の時間取得
		fps = 1000.0f/((time2-time1)/50.0f);	//FPSを計算
		count=0;
	}else
		count++;	//現在何周目かカウント
	
	if(fps != 0)
		DrawFormatString(565,460,0xffffffff,"FPS %.1f",fps);	//FPSを表示
	return;
}
Пример #17
0
FallingObject::FallingObject(void)
{
	this->speed = SPEED;
	this->starttime = GetNowCount();
	this->sound_h = LoadSoundMem("music/bomb.mp3");
	this->hit_area = HIT_AREA;
	this->color = GetColor(0, 255, 0);
	SetMouseDispFlag( TRUE );
	exist=true;
	once=false;
}
Пример #18
0
/* ================================================ */
FpsManager* FpsManager::Create()
{
	if( s_pInstance == NULL ){
		s_pInstance = NEW FpsManager;

		s_instancCreateTime = GetNowCount();	// アプリ開始時の時間
		s_preUpdateTime = s_instancCreateTime;
	}

	return s_pInstance;
}
Пример #19
0
void FPSer::CountFPS()
{
	Wait();

	if (!count)
	{
		time_a = GetNowCount();
	}
	if (count == checknum - 1)
	{
		time_b = GetNowCount();
		FPS = 1000 / (((time_b - time_a) ? (time_b > time_a ? time_b - time_a : time_b + (INT_MAX - time_a)) : checknum) / (double)checknum);
		count = 0;
	}
	else
	{
		count++;
	}
	DrawFormatString(560, 0, Flag::color.white, "fps:%.2f", FPS);
}
Пример #20
0
bool CMain::Init(){
	srand((unsigned int)GetNowCount());
	//ChangeFont("MS Pゴシック") ;	$
	
	if (_mkdir("tenyu_data")==0){
		_rmdir("tenyu_data");
		ErrorDx("Error->NotFound dir\"tenyu_data\" (exit)");
		return false;
	}

	return true;
	//エラー時にはreturn false
}
Пример #21
0
void FallingObject::UpDate()
{
	if(exist){
		this->y+=speed;
		if(GetNowCount() - starttime > 3000){
			exist = false;
			once = false;
			score.SetCombo(0);
			/*Play* play = Play::getInstance();
			play->setCombo(0);*/
		}
	}
}
Пример #22
0
void ShowFPS(void)
{//FPS値表示
	static int Count = -1;
	static double Show_Count = 0;
	static int Second = 0;
	int Now_Second;

	if(Count < 0)
	{
		Second = GetNowCount();
		Count = 0;
	}

	Count++;

	Now_Second = GetNowCount();
	if(Second + 1000 <= Now_Second)
	{
		Show_Count = Count * 1000. / (Now_Second - Second);
		Second = Now_Second;
		Count = 0;
	}
	DrawFormatString(0,0,Black,"FPS : %f",Show_Count);	
}
Пример #23
0
Scene* SceneTitleInit::Update()
{
	int t;
	switch (state) {
	case 0:
		if (Bright::Instance()->ChangeBright(255, 30)) ++state;
		break;
	case 1: // データロード
		t = GetNowCount();
		Image::Instance()->Init("data/image/image.csv");
		Sound::Instance()->Init();
		//ショットデータ読み込み
		PlayerBullet::Load();
		//セーブデータ読み込み
		Save::Instance()->LoadSaveData();
		//フォントデータ読み込み
		ChangeFont("MS ゴシック");
		SetFontThickness(3);
		SetFontSize(16);
		ChangeFontType(1);
		fonts.push_back(std::make_shared<Font>("梅PゴシックC5", 24, 4, "data/font/ume-pgc5.ttf"));
		fonts.push_back(std::make_shared<Font>("梅PゴシックC5", 16, 3, "data/font/ume-pgc5.ttf", DX_FONTTYPE_ANTIALIASING_EDGE));
		//ロードにかかった時間
		t = GetNowCount() - t;
		// ロードが1000ms以下なら1000msまで待機
		if (t < 1000) Sleep(1000 - t);
		++state;
		break;
	case 2:
		if (Bright::Instance()->ChangeBright(0, 30)) return new SceneTitle();
	}
	DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0xffffff, TRUE);
	DrawGraph(60, 40, images[0], TRUE);

	return this;
}
Пример #24
0
/* ================================================ */
bool FpsManager::IsUpdateTiming()
{
	uint32_t nowTime = GetNowCount();

	//! インスタンス作成からのフレーム
	uint32_t nowFrame = (nowTime - s_instancCreateTime)*m_fps/1000;
	//! 前回更新時のフレーム
	uint32_t framePreUpdate = (s_preUpdateTime - s_instancCreateTime)*m_fps/1000;

	if( nowFrame != framePreUpdate ){
		//! 更新時間を更新
		s_preUpdateTime = nowTime;
		++m_updateCounter;
		return true;
	}else{
		//! まだフレーム更新タイミングでない
		return false;
	}
}
Пример #25
0
EnemyAIBase::EnemyAIBase(void)
: m_enemyMine( NULL )
, m_isReady( false )
{
	if( !s_pAttackGun ){
		// 攻撃銃作成。共有+ランダムで発射なので発射のインターバルはなし
		s_pAttackGun = AttackGun::CreateGun( Common::OWNER_ENEMY );
		AttackGun::GunState &gunStatus = s_pAttackGun->UpdateGunState();
		gunStatus.m_shootInterval = 0;
	}
	if( !s_pAttackBlade ){
		// 斬撃クラス作成。共有
		s_pAttackBlade = AttackBlade::CreateAttackBlade( Common::OWNER_ENEMY );
		AttackBlade::BladeState &bladeStatus = s_pAttackBlade->UpdateBladeState();
		bladeStatus.m_damage = 20;
	}

	// AIの開始時間を保持しておく
	m_thisAIStartTime  = GetNowCount();
}
Пример #26
0
void disp_frame()
{
	static int draw_x = 0;
	static unsigned int e = GetNowCount();
	int y, cell_x, cell_y;
	int r,g,b;
	char key[256];	// 入力状態を格納する
	

	cell_x = W_CELL*draw_x;
	for (y=0; y<H_SIZE; y++)
	{
		pat2rgb(pat[y][draw_x], &r, &g, &b);

		cell_y = H_CELL*y;
		//DrawBox(cell_x, cell_y, cell_x+W_CELL, cell_y+H_CELL, GetColor(r,g,b), 1);	// 隙間なしバージョン
		DrawBox(cell_x, cell_y, cell_x+W_CELL-1, cell_y+H_CELL-1, GetColor(r,g,b), 1);	// 隙間ありバージョン
	}

	// 実行するたびに次の列を描画する
	draw_x = (draw_x+1) % H_SIZE;


	//1/60秒間隔でループ。
	//while (GetNowCount() - e < (1.0/60*1000)) { Sleep(10); }
	//e = GetNowCount();

	// 入力信号を取得
	GetHitKeyStateAll(key);
	U_BTN = key[KEY_INPUT_UP];
	D_BTN = key[KEY_INPUT_DOWN];
	R_BTN = key[KEY_INPUT_RIGHT];
	L_BTN = key[KEY_INPUT_LEFT];
	BTN1  = key[KEY_INPUT_Z];
	BTN2  = key[KEY_INPUT_X];
}
Пример #27
0
void Player::update(double *shotX, double *shotY, int *weaponNum, int *status , bool *_wasAttacked){


	//キーのチェック
	frame++;

	if (!wasAttackedFlag){	//ダメージ判定中は動けないようにしておく。

		if (CheckHitKey(KEY_INPUT_LEFT) == 1 && _x > 0){
			direction = Left;
			_x -= 4;
			_gCount++;
			if (_gCount >= 10){
				if (_gNum == 3)
					_gNum = 4;
				else
					_gNum = 3;
				_gCount = 0;
			}
		}
		if (CheckHitKey(KEY_INPUT_RIGHT) == 1 && _x < 421){
			direction = Right;
			_x += 4;
			_gCount++;
			if (_gCount >= 10){
				if (_gNum == 0)
					_gNum = 1;
				else
					_gNum = 0;
				_gCount = 0;
			}
		}

		int i = 0;	//一応一発まで設置可能にしておく。

		changing_weapon(i);
		*weaponNum = weapon_n;

		if (CheckHitKey(KEY_INPUT_Z) == 1 && _weapon[i].sf_p == false && GetNowCount() - T_weapons > 300){//設置!
			if (_gNum <= 2)
				_gNum = 2;
			else
				_gNum = 5;

			placing(i, weapon);
			T_weapons = GetNowCount();
		}

		if (CheckHitKey(KEY_INPUT_UP) == 1 && GetNowCount() - T_changing > 500){
			if (weapon_n == 2){
				weapon_n = 0;
			}
			else{
				weapon_n++;
			}
			flag_changed = true;
			T_changing = GetNowCount();
		}


		_weapon[i].weapon_B->setWeaponStatus(*status);

		if (_weapon[i].sf_p == true){
			_weapon[i].weapon_B->update();
			*shotX = _weapon[i].weapon_B->getX();
			*shotY = _weapon[i].weapon_B->getY();
			_weapon[i].weapon_B->checkForPlayer(_weapon[i].sf_p);	//お試し程度で実装
			_pipe[i].pipe->checkForPlayer(_weapon[i].sf_p);
		}
		*status = _weapon[i].weapon_B->getWeaponStatus();
	}


	if (*_wasAttacked){
		if (!CheckSoundMem(DamegeSound)){
			PlaySoundMem(DamegeSound, DX_PLAYTYPE_BACK);
		}
		*_wasAttacked = false;
		wasAttackedFlag = true;
	}

	if (wasAttackedFlag){
		if (wasAttackedFrame >= 50){
			wasAttackedFrame = 0;
			wasAttackedFlag = false;
			_live--;
			_x = 0;
			_y = 518;
		}
		else{
			++wasAttackedFrame;
		}
	}
}
Пример #28
0
void soloplay_main(){
  Input input;
  Mode status = TITLE;

  graresource.initialize();
  decoder.initialize();
  Shooting *shooting;
  int fpsTimer = GetNowCount();

  while (true){
    if (status == TITLE){
      input.getKeyInput();
      if (input.buttonA()){
        status = SELECT;
      }
  	  ClearDrawScreen();
      // 後で差し替える nakao
      DrawString( 100, 100, "TITLE", WHITE, GREY);
      //DrawGraph( 0, 0, "TITLE.bmp", false);
      ScreenFlip();
    } else if (status == SELECT){
      input.getKeyInput();
      if (input.buttonA()){
        shooting = new Shooting(1);
        status = SHOOTING;
      } else if (input.buttonB()){
        status = TITLE;
      }
  	  ClearDrawScreen();
      // 後で差し替える nakao
      DrawString( 100, 100, "SELECT", WHITE, GREY);
      DrawString( 100, 200, "If push button A, game start.", WHITE, GREY);
      DrawString( 100, 300, "If push button B, back to title.", WHITE, GREY);
      ScreenFlip();
    } else if (status == SHOOTING){
   		input.getKeyInput();
      // todo treat dead client
      //while(true){
      //  int lostNetWork = GetLostNetWork();
      //}
      shooting->setInput(0, input.encode());
      shooting->action();
      
      //if (SHOOTING) shooting.action();
      //else if (TITLE) {
      //  drawTitle;
      //} else if (){

      //}
      

#ifdef _DEBUG_

		  // debug messages
		  //dxout << serverMessage << dxendl;

#endif // _DEBUG_

		  //string clientMessage = graresource.getMessages();
		  //server.send(clientMessage);
      vector<int> mess___ = graresource.getMessages();
		  decoder.draw( mess___);
		  graresource.clear();
	    int term;
	    term = GetNowCount()-fpsTimer;

		  if(16-term>0){
  			Sleep(16-term);
		  }

	    fpsTimer = GetNowCount();
      if (!shooting->isValid()){
        delete shooting;
        status = SELECT;
      }

    } else {
      assert( false && "solo main");
    }
    // Windows 特有の面倒な処理をDXライブラリにやらせる
    // -1 が返ってきたらループを抜ける
    if( ProcessMessage() < 0 ) break ;

    // もしESCキーが押されていたらループから抜ける
    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) break;
  }
}
Пример #29
0
void server_main(){
  graresource.initialize();
  static const int BLACK = GetColor(0, 0, 0);
  static const int WHITE = GetColor(255, 255, 255);
	ServerConnection server(PORT);
	server.startListen();
	while(server.size() < CLIENT_NUM){
		DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK, 1);
		DrawFormatString(60, 60, WHITE, "access: %d", server.size());
		ScreenFlip();
		Sleep(10);
		server.action();
    // Windows 特有の面倒な処理をDXライブラリにやらせる
    // -1 が返ってきたらループを抜ける
    if( ProcessMessage() < 0 ) exit(1) ;

    // もしESCキーが押されていたらループから抜ける
    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) exit(1);
	}
	server.endListen();
	DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK, 1);
	DrawFormatString(60, 60, WHITE, "access: %d", server.size());
	DrawFormatString(60, 80, WHITE, "game start", server.size());
	ScreenFlip();
  Shooting shooting(CLIENT_NUM);
  // 移動ルーチン
	int fpsTimer = GetNowCount();
  while( 1 ){
		string serverMessage;
    // todo treat dead client
    //while(true){
    //  int lostNetWork = GetLostNetWork();
    //}

		for(int i = 0; i < server.size(); ++i){
      if(server.receive(i, serverMessage) >= 0){
        while(server.receive(i, serverMessage) >= 0);
        // receive succssessed
        shooting.setInput(i, serverMessage);
      }else{
        // receive failed
        shooting.clearInput(i);
      }
	  }
    shooting.action();

		// debug messages
		dxout << serverMessage << dxendl;

		vector<int> clientMessage = graresource.getMessages();

		DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK, 1);
		DrawFormatString(60, 60, WHITE, "access: %d", server.size());
		DrawFormatString(60, 80, WHITE, "game start", server.size());
		//DrawFormatString(60, 100, WHITE, clientMessage.c_str());
		ScreenFlip();

		server.send(clientMessage);
	  graresource.clear();
	  int term;
	  term = GetNowCount()-fpsTimer;
	  if(16-term>0){
			Sleep(16-term);
		}
	  fpsTimer = GetNowCount();

		if (!shooting.isValid()) break;
    // Windows 特有の面倒な処理をDXライブラリにやらせる
    // -1 が返ってきたらループを抜ける
    if( ProcessMessage() < 0 ) break ;

    // もしESCキーが押されていたらループから抜ける
    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) break;
  }
}
Пример #30
0
void network_soloplay_main(){
	//画像読み込み
  graresource.initialize();
	decoder.initialize();
	ServerConnection server(PORT);
	ClientConnection client(PORT, SERVER_IP);
	server.startListen();
  ClearDrawScreen();
  const static int titleGraph = LoadGraph( "../graphic/ShootingTitle.jpg");
  DrawGraph( 0, 0, titleGraph, false);
  ScreenFlip();

	if(!client.connect()){
		exit(1);
	}
	while(server.getClientNum() < CLIENT_NUM){
    ClearDrawScreen();
    DrawGraph( 0, 0, titleGraph, false);
		DrawFormatString(300, 500, WHITE, "access: %d", server.getClientNum());
    ScreenFlip();
		Sleep(10);
		server.acceptNewConnection();
    // Windows 特有の面倒な処理をDXライブラリにやらせる
    // -1 が返ってきたらループを抜ける
    if( ProcessMessage() < 0 ) exit(1) ;

    // もしESCキーが押されていたらループから抜ける
    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) exit(1);
	}
  Shooting *shooting= new Shooting(CLIENT_NUM);
  // 移動ルーチン
	int fpsTimer = GetNowCount();
	Input input;
	int playerNum = server.getClientNum();
  while( 1 ){

		//server.acceptNewConnection();
		//server.checkLostConnection();

		input.getKeyInput();
		client.send(input.encode());
		string serverMessage;
    // todo treat dead client
    //while(true){
    //  int lostNetWork = GetLostNetWork();
    //}
		for(int i = 0; i < server.getClientNum(); ++i){
      if(server.receive(i, serverMessage) >= 0){
        while(server.receive(i, serverMessage) >= 0);
        // receive succssessed
        shooting->setInput(i, serverMessage);
      }else{
        // receive failed
        shooting->clearInput(i);
      }
	  }
    shooting->action();

#ifdef _DEBUG_

		// debug messages
		dxout << serverMessage << dxendl;

#endif // _DEBUG_

    //string clientMessage = graresource.getMessages();
    //server.send(clientMessage);
		vector<int> clientMessage = graresource.getMessages();
		server.send(clientMessage);

		graresource.clear();
	  int term;
	  term = GetNowCount()-fpsTimer;

		if(16 - term > 0){
			vector<int> clientMessage;
			if(client.receive(clientMessage) >= 0){
				while(client.receive(clientMessage) >= 0);
				decoder.draw(clientMessage);
			}

			term = GetNowCount()-fpsTimer;


			if(16-term>0){
				Sleep(16-term);
			}
		}

	  fpsTimer = GetNowCount();

		if (!shooting->isValid()){
			delete shooting;
			shooting = new Shooting(CLIENT_NUM);
		}
    // Windows 特有の面倒な処理をDXライブラリにやらせる
    // -1 が返ってきたらループを抜ける
    if( ProcessMessage() < 0 ) break ;

    // もしESCキーが押されていたらループから抜ける
    if( CheckHitKey( KEY_INPUT_ESCAPE ) ) break;
  }
	server.endListen();
}