Esempio n. 1
0
void Play() {
	//Use a quit flag to start a game loop
	bool quit = false;
	SDL_Event event;
	Uint32 lastEvent = 0;


	while(!quit) {
		//While there are events to pull...
		while(SDL_PollEvent(&event) != 0) {
			//Handle each one
			//SDL_QUIT is something like hitting the Red X on the top right of screen. Also added support for ESC quit
			if(event.type == SDL_QUIT) {
				quit = true;
			}

			if(event.key.keysym.sym == SDLK_ESCAPE) {
				quit = true;
				//Menu();
				//continue;
			}
			for(int i = 0; i != TILE_TOTAL; ++i) {
				tTiles[i].HandleEvent(&event, lastEvent);
			}
			//std::cout << lastEvent <<std::endl;
		}

		if(IWin('X')) {
			std::cout << "\n\nX Wins" << std::endl;
			ResetGame();
		} else if(IWin('O')) {
			std::cout << "\n\nO Wins" << std::endl;
			ResetGame();
		}

		//If its not my turn, let the computer go
		if(isMyTurn == false) {
			ComputersTurn();
		}



		//Clear screen with white
		SDL_SetRenderDrawColor(theRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(theRenderer);

		DrawBoard();

		SDL_RenderPresent(theRenderer);


	}
	//Quit is true at this point so we return
	return;
}
Esempio n. 2
0
void GameApp::RenderFrame(void)
{
    //glClear(GL_COLOR_BUFFER_BIT);
    //context.DrawBackground();
    //context.DrawTexture(context.GetBackground(),0 , 0);

    if(GameStatus == GAME_NOT_OVER)
    {
        context.DrawBackground();
        //context.DrawTexture(context.GetBackground(),0 , 0);
        for(int x = 0; x < 9; x++)
        {
            if(TicTacToeBoard.GetCellStatus(x) == TicTacToeBoard.BOARD_CELL_PLAYERX) context.DrawTexture(context.GetPlayerXTexture(), (x % 3 * 200), (x / 3 * 200));
            else
            if(TicTacToeBoard.GetCellStatus(x) == TicTacToeBoard.BOARD_CELL_PLAYERO) context.DrawTexture(context.GetPlayerOTexture(), (x % 3 * 200), (x / 3 * 200));
        }
    }
    if(GameStatus == GAMEOVER_X_WINS)
    {
        context.DrawTexture(context.GetXWinsScreen(), 0, 0);
        SDL_GL_SwapBuffers();
        SDL_Delay(3000);
        ResetGame();
    }
    if(GameStatus == GAMEOVER_O_WINS)
    {
        context.DrawTexture(context.GetOWinsScreen(), 0, 0);
        SDL_GL_SwapBuffers();
        SDL_Delay(3000);
        ResetGame();
    }
    if(GameStatus == GAMEOVER_TIE)
    {
        context.DrawTexture(context.GetTieScreen(), 0, 0);
        SDL_GL_SwapBuffers();
        SDL_Delay(3000);
        ResetGame();
    }


    SDL_GL_SwapBuffers();
//    ILenum Error;
//    while ((Error = ilGetError()) != IL_NO_ERROR) {
//        printf("%d: %s/n", Error, iluErrorString(Error));
//    }
//
//    GLenum glError;
//    while ((glError = glGetError()) != GL_NO_ERROR) {
//        printf("%d: %s\n", glError, gluErrorString(glError));
//    }

}
Esempio n. 3
0
void UpdateBall()
{
  BallRect.x += BallXVel;
  BallRect.y += BallYVel;

  //If the ball hits the player, make it bounce
  if(RectsOverlap(BallRect, PlayerPaddleRect))
    {
      BallXVel = rand()%BALL_MAX_SPEED + 1;
      Mix_PlayChannel(-1, BallBounceSound, 0);
    }

  //If the ball hits the enemy, make it bounce
  if(RectsOverlap(BallRect, EnemyPaddleRect))
    {
      BallXVel = (rand()%BALL_MAX_SPEED +1) * -1;
      Mix_PlayChannel(-1, BallBounceSound, 0);
    }

  //Make sure the ball doesn't leave the screen and make it
  //bounce randomly
  if(BallRect.y < 0)
    {
      BallRect.y = 0;
      BallYVel = rand()%BALL_MAX_SPEED + 1;
      Mix_PlayChannel(-1, BallBounceSound, 0);
    }

  if(BallRect.y > SCREEN_HEIGHT - BallRect.h)
    {
      BallRect.y = SCREEN_HEIGHT - BallRect.h;
      BallYVel = (rand()%BALL_MAX_SPEED + 1)* -1;
      Mix_PlayChannel(-1, BallBounceSound, 0);
    }

  //If player scores
  if(BallRect.x > SCREEN_WIDTH)
    {
      PlayerScore++;
      Mix_PlayChannel(-1, PlayerScoreSound, 0);
      ResetGame();
    }

  //If enemy scores
  if(BallRect.x < 0-BallRect.h)
    {
      EnemyScore++;
      Mix_PlayChannel(-1, EnemyScoreSound, 0);
      ResetGame();
    }
}
Esempio n. 4
0
void BattleExitConfirmationDeinit(Window *window)
{
	if(!battleCleanExit)
	{
		ResetGame();
	}
}
Esempio n. 5
0
BOOL SGBattle::OnEnter( int gameMode )
{
	SFRoom* pRoom = GetOwner()->GetOwner();
	SFRoom::RoomMemberMap& roomMember = pRoom->GetRoomMemberMap();

	m_nGameState = SG_GAME_PLAY;
	m_dwLastPlayTickCount = GetTickCount();

	SFASSERT(roomMember.size() != 0 && roomMember.size() <= SEVENGAME_MEMBER_NUM);

	m_pSevenGameManager->Reset();

	int playerCount = 0;
	for (auto& iter : roomMember)
	{
		SFPlayer* pPlayer = iter.second;
		m_pSevenGameManager->AddUser(pPlayer->GetSerial());

		playerCount++;
	}

	int botSerial = -1;
	while(playerCount < SEVENGAME_MEMBER_NUM)
	{
		m_pSevenGameManager->AddUser(botSerial);
		botSerial--;
		playerCount++;
	}

	ResetGame();

	return TRUE;
}
Esempio n. 6
0
// Player Presses Enter to Replay the Game
void ShipRace::ReplayGame()
{
	if (gDInput->keyDown(DIK_RETURN))
	{
		ResetGame();
	}
}
Esempio n. 7
0
File: main.c Progetto: ryanlamo/lab5
__interrupt void Port_1_ISR(void)
{
	if (gamedone == 0)
	{
	TestForButtonPress(BIT1);
	TestForButtonPress(BIT2);
	TestForButtonPress(BIT3);
	TestForButtonPress(BIT4);
	}
	else{
		ResetGame(BIT1);
		ResetGame(BIT2);
		ResetGame(BIT3);
		ResetGame(BIT4);

	}

}
void CTicTacView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{

	// 게임 그리드를 정의하는 굵은 검정선을 왼쪽마우스 DB 클릭하면
	// 게임을 재설정

	CClientDC	dc(this);
	if( dc.GetPixel( point) == RGB(0, 0, 0))
		ResetGame();

	CView::OnLButtonDblClk(nFlags, point);
}
Esempio n. 9
0
void IGameController::StartRound()
{
	ResetGame();

	++m_RoundCount;

	// start countdown if there're enough players, otherwise abort to warmup
	if(HasEnoughPlayers())
		SetGameState(IGS_START_COUNTDOWN);
	else
		SetGameState(IGS_WARMUP_GAME, TIMER_INFINITE);
}
Esempio n. 10
0
void Game::WinGame( )
{
	m_GameTimer.Stop( );
	float time = m_GameTimer.GetTime( );

	if( time < m_BestTime )
	{
		m_BestTime = time;
		SaveHighScore( );
	}

	ResetGame( );
}
Esempio n. 11
0
void IGameController::StartRound()
{
	ResetGame();
	
	m_RoundStartTick = Server()->Tick();
	m_SuddenDeath = 0;
	m_GameOverTick = -1;
	GameServer()->m_World.m_Paused = false;
	m_aTeamscore[0] = 0;
	m_aTeamscore[1] = 0;
	m_ForceBalanced = false;
	dbg_msg("game","start round type='%s' teamplay='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS);
}
Esempio n. 12
0
void App::Draw() {
	TextRenderer t(0.04, 0.04);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	m_sky->DrawCurrentFrame(0, 0, 1.0, 1.0);
	

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	{
		comparePos(m_player);
		glTranslatef(0, -(getPos() * Engine::Get().getRenderer()->getTileHeigth() - 0.45), 0);
		glMatrixMode(GL_MODELVIEW);

		m_level_view.setLevel(m_level, getPos());
		m_level_view.draw(getPos());
		

		m_player->draw();
		if (m_player->getY() < getPos() - 10.5) {
			m_score_submit.reset(new ScoreSubmit(m_player->getPoints()));
			ResetGame();
			Engine::Get().setGameState(GS::ScoreSubmit);
			m_hall_of_fame->setActual(false);
		}

	}
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);	
	
	if (m_player->getPoints() % 50 == 0 || m_player->getPoints() % 50 == 1) {
		if (pos > 10) {
			base_speed = 0.05 + (m_player->getPoints() / 50) * 0.03;
			t.drawText("Speed up!", 0.4, 0.5);
		}

	}

	t.drawText("Points: " + IntToStr(m_player->getPoints()), 0.1, 0.9);
	if (is_paused) {
		t.SetSize(0.07, 0.07);
		t.drawText("GAME PAUSED", 0.15, 0.6);
		t.SetSize(0.04, 0.04);
		t.drawText("Press SPACE to continue", 0.05, 0.5);
		t.drawText("Press ESCAPE to quit", 0.1, 0.4);
	}
	glLoadIdentity();


	SDL_GL_SwapBuffers();
}
void CTicTacView::CheckForGameOver()
{
	int nWinner;

	//그리드에 세 개의 연속 X나 O가 있으면 승자를 선언하고 새로 게임을 시작
	if( nWinner = IsWinner ())
	{
		CString string = (nWinner == EX) ? _T("X wins!") : _T("O Win!");

		MessageBox(string, _T("Game Over"), MB_ICONEXCLAMATION | MB_OK);

		ResetGame();
	}

	// 그리드가 가득차면 새 게임을 시작
	else if( IsDraw() )
	{
		MessageBox(_T("It's a draw!"), _T("Game Over"), 
			MB_ICONEXCLAMATION | MB_OK);

		ResetGame();
	}
}
Esempio n. 14
0
void IGameController::StartRound()
{
	ResetGame();

	m_RoundStartTick = Server()->Tick();
	m_SuddenDeath = 0;
	m_GameOverTick = -1;
	GameServer()->m_World.m_Paused = false;
	m_aTeamscore[TEAM_RED] = 0;
	m_aTeamscore[TEAM_BLUE] = 0;
	m_ForceBalanced = false;
	char aBuf[256];
	str_format(aBuf, sizeof(aBuf), "start round type='%s' teamplay='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS);
	GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
}
void MyPS2Application::GameOver()
{
	if (!game_over_loaded)
	{
		printf("Loading Game Over sprite\n");
		LoadGameOver();
	}
	
	RenderGameOver();
	
	if ((pad[0].buttons & PAD_START))
	{
		printf("Reseting da f*****g game!");
		ResetGame();
	}
}
	void UpdateGameState()
	{
		switch (m_CurrentState)
		{
		case EGS_STARTUP:
			// Created a few dummy RBCs on initial startup to set the scene until a new game is started
			if (!m_pSplashScreen && m_GameObjects[EGO_RBC].size() == 0)
			{
				for (int j=0; j<8; ++j)
				{
					DoSpawnGameObject( GameObjectSpawnParams( EGO_RBC ) );
				}
			}

			break;
		case EGS_NEWGAME:
			if (!m_pSplashScreen)
			{
				CreateInitialGameObjects();

				SetGameState(EGS_PLAYING);
			}

			break;
		case EGS_PLAYING:
			if (m_GameObjects[EGO_WBC].size() == 0)
			{
				SetGameState(EGS_INFECTIONWON);
				CreateSplashScreen( "//GUI/infectionwin.tga", 1.0f, 0.5f, 0.0f, false );
			}
			else if (m_GameObjects[EGO_VIRUS].size() == 0 && m_GameObjects[EGO_INFECTED].size() == 0)
			{
				SetGameState(EGS_IMMUNEWON);
				CreateSplashScreen( "//GUI/immunewin.tga", 1.0f, 0.5f, 0.0f, false );
			}

			break;
		case EGS_IMMUNEWON:
		case EGS_INFECTIONWON:
			if (!m_pSplashScreen)
			{
				ResetGame();
			}

			break;
		}
	}
Esempio n. 17
0
void handle_init(AppContextRef ctx) {
	(void)ctx;
	PblTm currentTime;
	unsigned int unixTime;

	resource_init_current_app(&APP_RESOURCES);

	get_time(&currentTime);
	unixTime = GetUnixTime(&currentTime);
	SetRandomSeed(unixTime);

	InitializeExitConfirmationWindow();
	
	handle_minute_tick(ctx, NULL);

	ResetGame();
	ShowAdventureWindow();
}
Esempio n. 18
0
void App::ProcessEvents() {
	if (!is_paused)
		updatePos(delta_time);

	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_VIDEORESIZE) {
			Engine::Get().Resize(event.resize.w, event.resize.h);
		}
		else if (event.type == SDL_QUIT){
			in_game = false;
			break;
		}
		else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
			if (is_paused) {
				Engine::Get().setGameState(GS::Menu);
				ResetGame();
			}
			else
				is_paused = true;
		}
		else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) {
			if (is_paused)
				is_paused = false;
		}
		else if (!is_paused) {
			if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_UP) {
				m_player->jump();
			}
			else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_LEFT) {
				m_player->goLeft();
			}
			else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RIGHT) {
				m_player->goRight();
			}
			else if (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_LEFT) {
				m_player->stopLeft();
			}
			else if (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_RIGHT) {
				m_player->stopRight();
			}
		}
	}
}
Esempio n. 19
0
void IGameController::StartMatch()
{
	ResetGame();

	m_RoundCount = 0;
	m_aTeamscore[TEAM_RED] = 0;
	m_aTeamscore[TEAM_BLUE] = 0;

	// start countdown if there're enough players, otherwise do warmup till there're
	if(HasEnoughPlayers())
		SetGameState(IGS_START_COUNTDOWN);
	else
		SetGameState(IGS_WARMUP_GAME, TIMER_INFINITE);

	Server()->DemoRecorder_HandleAutoStart();
	char aBuf[256];
	str_format(aBuf, sizeof(aBuf), "start match type='%s' teamplay='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS);
	GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
}
Esempio n. 20
0
bool GameManager::LastMenuDecision(int lastMenu)
{
	if (lastMenu == 0)
	{
		InitializeGame();
		m_Player1->InitializePlayer();
		m_Player2->InitializePlayer();
		return false;
	}
	else if (lastMenu == 1)
	{
		ResetGame();
		return false;
	}
	else
	{
		return true;
	}
}
Esempio n. 21
0
void buttonClick(WMWidget *w, void *ptr)
{
    char buffer[300];

    if (SlideButton((int)ptr)) {
	MoveCount++;

	if (CheckWin()) {
	    sprintf(buffer, "You finished the game in %i moves.", MoveCount);

	    if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
				"Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
		exit(0);
	    }
	    
	    ResetGame();
	}
    }
}
Esempio n. 22
0
int main(int argc, char *argv[])
{
	int result = 0;
	if(!init())
	{
		result = 1;
		goto exit;
	}

	//Initialize startup music
	musicType = constants::BarnBeat;

	ResetGame();

	result = GameLoop();

exit:
	shutdown();
	return result;
}
Esempio n. 23
0
bool ExampleUpdate(float dt)
{
    IW_PROFILE("update");

    UpdateScreenOrientation();

    m_pAnimator->Update(dt);
    m_pSplinePoly2Tri->SetSpline(m_pAnimator->GetCurrentSpline());
    m_pSplinePoly2Tri->Generate();

    m_pBall->Update(dt);

    if (s_Accelerometer)
    {
        //iAccX = iClamp(iAccX, 0, 70
        m_pBall->SetAcceleration(Vector2i((int16)s3eAccelerometerGetX(), (int16)s3eAccelerometerGetY()));
    }

    // check collision

    //if (m_pSplineTriFan->IsPointWithin(m_pBall->GetPos()))
    //{
    //	IwGxPrintString(10, 10, "collision yes", true);
    //}
    //else
    //{
    //	IwGxPrintString(10, 10, "collision no", true);
    //	g_fLife += -0.1f * dt;
    //}

    char strLife[50];
    sprintf(strLife, "life left: %f", g_fLife);
    IwGxPrintString(10, 20, strLife, true);

    if (g_fLife <= 0.0f)
    {
        ResetGame();
    }

    return true;
}
Esempio n. 24
0
int main (int argc, char *argv[]){
	
	PrintVersion();  //Print game info
    InitGFX();       //Setup SDL
    LoadSprites();   //Load the game sprites
    ResetGame();     //Reset the game

    done = 0;
    while (!done){
        //Check for user input
        GetInput();

        //Draw the graphics
        RenderScreen();
    }
    
    //Free the game sprites
    FreeSprites();  

    return 0;
}
Esempio n. 25
0
// -----------------------------------------------------------------------------
// CSIPExEngine::ConstructL
// Symbian 2nd phase constructor can leave.
// Initializes the game data, socket and sip engines and all state objects.
// -----------------------------------------------------------------------------
//
void CSIPExEngine::ConstructL()
    {
    // Init all state objects
    iStateIdle          = new (ELeave) TSIPExStateIdle;
    iStateRegistering   = new (ELeave) TSIPExStateRegistering;
    iStateRegistered    = new (ELeave) TSIPExStateRegistered;
    iStateInviting      = new (ELeave) TSIPExStateInviting;
    iStateConnecting    = new (ELeave) TSIPExStateConnecting;
    iStateLocal         = new (ELeave) TSIPExStateLocal;
    iStateRemote        = new (ELeave) TSIPExStateRemote;
    iStateAcceptingSIP  = new (ELeave) TSIPExStateAcceptingSIP;

    iSocketEngine = CSIPExSocketEngine::NewL( *this );
    iSIPEngine = CSIPExSIPEngine::NewL( KUidSIPExApp, this );

    // Set the first state as active state
    iActiveState = iStateIdle;

    // Reset game data
    ResetGame();
    }
Esempio n. 26
0
// Initialization functions
void GameApp::InitApp(void)
{
    #ifndef GL_ARB_texture_non_power_of_two
        printf("DOES NOT SUPPORT NON POWER OF TWO!!\n");
    #else
        printf("DOES SUPPORT NON POWER OF TWO!!\n");
    #endif
    printf("InitApp...\n");
    ResW = 600;
    ResH = 600;
//    ilInit();
    InitializeSDL();
    InitializeDrawContext(ResW, ResH);
    ResetGame();
    InstallTimer();

    //player1 = new GameSprite;
//    PlayerX.SetWorldX(0);
//    PlayerX.SetWorldY(0);
//    PlayerX.SetOrientation(0.0);
    //context.DrawTexture(context.GetBackground(),0 , 0);
}
Esempio n. 27
0
gpsp4Qt::gpsp4Qt(QWidget *parent)
    : QWidget(parent), m_buf(NULL), m_softKeys(0), m_hardKeys(0), m_errorDialog(NULL)
{
    QWidget::setAttribute(Qt::WA_AcceptTouchEvents);
    QThread::currentThread()->setPriority( QThread::NormalPriority );
    showFullScreen();
    setFocusPolicy(Qt::StrongFocus);
	
    //create button widgets
   
    m_dpad = new DPadWidget( this );
    connect(m_dpad, SIGNAL(showMenu()), this, SLOT( showAntSnesMenu()) );
    
    m_rightButtons = new rightbuttonwidget( this );

    m_audio = new CAntAudio();
    
    m_adaptation = new gpspadaptation( this, m_audio );
    
    //connect all adaptation stuff
    connect(this, SIGNAL(Start()), m_adaptation, SLOT(Start()) );
    connect(this, SIGNAL(Stop()), m_adaptation, SLOT(Stop()) );
     
    connect(this, SIGNAL(saveState(int)), m_adaptation, SLOT(savegpspState(int)) );
    connect(this, SIGNAL(loadState(int)), m_adaptation, SLOT(loadgpspState(int)) );
    connect(this, SIGNAL(resetgpsp()), m_adaptation, SLOT(ResetGame()) );
    connect(this, SIGNAL(exitgpsp()), m_adaptation, SLOT(exitgpsp()) );
    connect(this, SIGNAL(doLoadROM(QString,TGPSPSettings)), m_adaptation, SLOT(LoadRom(QString,TGPSPSettings)) );
    connect(m_adaptation, SIGNAL(dispatchErrorNote(QString)), this, SLOT(showErrorNote(QString)) );
    
    connect(this, SIGNAL(Start()), this, SLOT(listencontrols()) );
    
    g_adaption = this;
    //create graphics for the button overlay
    LoadButtons();
    
}
Esempio n. 28
0
int InitGame()
{
  //Init SDL
  if(!InitSDL())
    return 0;

  //Load Files
  if(!LoadFiles())
    return 0;

  //Initiatialize game variables

  //Set scores to 0
  PlayerScore = 0;
  EnemyScore = 0;

  //This can also set the initial variables
  ResetGame();

  //Play Music
  Mix_PlayMusic(GameMusic, -1);

  return 1;
}
void Game::ShowMenu()
{
  MainMenu mainMenu;
  MainMenu::MenuResult result = mainMenu.Show(_mainWindow);
  switch(result)
  {
  case MainMenu::Exit:
     _gameState = Game::Exiting;
     break;
   case MainMenu::Play:
	InstructionScreen instructionScreen;
	instructionScreen.Show(_mainWindow);
    ResetGame();
    _gameState = Game::Playing;
     break;
   case MainMenu::Music:
	 _gameState = Game::ShowingMenu;
	 if(ServiceLocator::GetAudio()->IsSongPlaying())
	 {
		ServiceLocator::GetAudio()->StopAllSounds();
	 }
	 break;
  }
}
Esempio n. 30
0
void HK_Reset(int, bool justPressed) {ResetGame();}