1
General / Exporting an SFML Project in Code::Blocks
« on: February 08, 2012, 02:54:16 pm »
That's great thanks very much!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
void GameClass::gameLoop()
{
sf::Event currentEvent; //Creates an instance of sf Event called currentEvent which will monitor the gameState whilst the program is running
gameWindow.GetEvent(currentEvent); //Assigns the currentEvent to gameWindow
switch(gameState) //Monitors the changes within gameState and applies the appropriate implementation depending on the cases below
{
case GameClass::Playing: //Alter the game environment so that all sprites are drawn to stage ready for the user to play
{
sf::Clock enemyClock;
bool enemyHit = false;
while((enemyClock.GetElapsedTime()<5.f)&&(enemyHit == false))
{
gameWindow.Clear(sf::Color(0,0,0)); //Clears all images off screen and reverts it to a black screen
enemy.drawCharacter(gameWindow);
player.drawCharacter(gameWindow);
gameWindow.Display();
cout<<"Time: "<<enemyClock.GetElapsedTime()<<endl;
if(currentEvent.Type == sf::Event::Closed)
{
gameState = GameClass::Exiting; //If the 'X' button is closed on the gameWindow then the gameState changes to Exiting
}
switch(currentEvent.Type)
{
case sf::Event::MouseButtonPressed:
switch (currentEvent.MouseButton.Button)
{
case sf::Mouse::Left:
{
player.setIsFiringStatus(true);
player.fireWeapon();
//Debug to test if enemy is being hit
int enemyX = enemy.enemySprite.GetPosition().x;
int enemyY = enemy.enemySprite.GetPosition().y;
int playerX = player.userCursor.GetPosition().x;
int playerY = player.userCursor.GetPosition().y;
if(((((enemyX - playerX)>0)&&(enemyX - playerX)<30)&&((enemyY - playerY)>0)&&(enemyY - playerY)<30)||((((playerX - enemyX)>0)&&(playerX - enemyX)<30)&&(((playerY - enemyY)>0)&&(playerY - enemyY)<30)))
{
enemyHit = true;
cout<<"Enemy hit"<<endl;
break;
//enemy.setEnemyPosition();
}
player.setIsFiringStatus(false);
break;
}
default:
break;
}
break;
case sf::Event::MouseButtonReleased:
//cout<<"Mouse button released"<<endl;
break;
case sf::Event::MouseMoved:
{
//Need to update the position of the mouse/cursor sprite
player.userCursor.SetPosition((currentEvent.MouseMove.X), (currentEvent.MouseMove.Y));
break;
}
default:
break;
}
break;
}
if(enemyHit)
{
player.addToUserScore(100);
cout<<"Score: "<<player.getUserScore()<<endl;
enemy.setEnemyPosition();
//enemyClock.Reset();
}
/*if(enemyClock.GetElapsedTime()>5.f)
{
enemy.setEnemyPosition();
}*/
}
default: //Prevents warnings
break;
}
}