Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - Kody

Pages: [1]
1
Graphics / Game Freezing
« on: July 08, 2011, 06:44:58 pm »
Quote from: "Haikarainen"
This code is a mess, protip is to get some kindof order by creating classes and stuff. Make it all structural.


As an example, like this?

Code: [Select]

while(App.IsOpened())
{
   sf::Event Event;
   while(App.GetEvent(Event))
   {
      if(Event.Type == sf::Event::Closed)
         App.Close();
   }

      App.Clear();

      App.Draw(Map);

      MapSelect();

      GameStart();

      App.Display();
}
 


Quote from: "aquaglow"
The simplest thing is setting some breakpoints and stepping through your code with a debugger (gdb if you're using g++, visual studio/xcode have a debugger integrated in the IDE). If you're not familiar with using a debugger it's worth investing the time to learn.


Can you give me some links for how to learn debugging?

I'm using Visual Studio 2008.

2
Graphics / Game Freezing
« on: July 07, 2011, 08:48:45 pm »
I'm having trouble keeping my game running. My code below makes my game freeze up and not respond. Can anyone help me understand why and how to fix it?

Code: [Select]
int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32), "World Domination");

srand( time(NULL) );

sf::Clock Clock;

int PlayerHealth = 100;
int EnemyHealth = 100;

int lvl = 0;

bool map1Highlighted = false;
bool map2Highlighted = false;
bool map1Selected = false;
bool map2Selected = false;

bool isStarted = false;
bool gameStarted = false;

sf::Image MapLoad;
if(!MapLoad.LoadFromFile("Images/Edited.png"))
return EXIT_FAILURE;

sf::Sprite Map(MapLoad);

Map.SetPosition(0,0);
Map.SetScale(1.f,1.f);

sf::Image MapLoad2;
if(!MapLoad2.LoadFromFile("Images/Select_1.png"))
return EXIT_FAILURE;

sf:: Image MapLoad3;
if(!MapLoad3.LoadFromFile("Images/Select_2.png"))
return EXIT_FAILURE;

sf::String map1Text;
map1Text.SetFont(sf::Font::GetDefaultFont());
map1Text.SetText("North America");
map1Text.SetSize(15);
map1Text.SetPosition(55,160);
map1Text.SetColor(sf::Color(255,0,0,255));

sf::String map2Text;
map2Text.SetFont(sf::Font::GetDefaultFont());
map2Text.SetText("South America");
map2Text.SetSize(15);
map2Text.SetPosition(135,350);
map2Text.SetColor(sf::Color(255,0,0,255));

sf::String startText;
startText.SetFont(sf::Font::GetDefaultFont());
startText.SetText("Player 1's Turn");
startText.SetSize(75);
startText.SetPosition(250,250);
startText.SetColor(sf::Color(255,0,0,255));

while(App.IsOpened())
{
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
}

App.Clear();

float timer = Clock.GetElapsedTime();

App.Draw(Map);

float ElaspedTime = App.GetFrameTime();
int randomMap = 1 + rand() % 2;

if(map1Selected == false && map2Selected == false)
{
if(App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
if(App.GetInput().GetMouseX() > 50 && App.GetInput().GetMouseX() < 150 && App.GetInput().GetMouseY() > 0 && App.GetInput().GetMouseY() < 300)
{
Map.SetImage(MapLoad2);
map2Highlighted = false;
map1Highlighted = true;
}
}

if(map1Selected == false && map2Selected == false)
{
if(App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
if(App.GetInput().GetMouseX() > 100 && App.GetInput().GetMouseX() < 300 && App.GetInput().GetMouseY() > 300 && App.GetInput().GetMouseY() < 600)
{
Map.SetImage(MapLoad3);
map1Highlighted = false;
map2Highlighted = true;
}
}

if(map1Selected == false && map2Selected == false)
if(App.GetInput().IsKeyDown(sf::Key::R))
if(randomMap == 1)
{
Map.SetImage(MapLoad2);
map2Highlighted = false;
map1Highlighted = true;
Sleep(250);
}
else
{
Map.SetImage(MapLoad3);
map1Highlighted = false;
map2Highlighted = true;
Sleep(250);
}

if(map1Highlighted == true)
{
App.Draw(map1Text);
if(App.GetInput().IsKeyDown(sf::Key::Return))
map1Selected = true;
}

if(map2Highlighted == true)
{
App.Draw(map2Text);
if(App.GetInput().IsKeyDown(sf::Key::Return))
map2Selected = true;
}

if(map1Selected == true || map2Selected == true)
{
Map.SetImage(MapLoad);
if(map1Highlighted == true)
map1Text.SetColor(sf::Color(0,255,0,255));
if(map2Highlighted == true)
map2Text.SetColor(sf::Color(0,255,0,255));
isStarted = true;
}

if(isStarted == true)
{
App.Draw(startText);
Sleep(2000);
startText.SetText("");
lvl = 1;
}

if(lvl == 1)
{
bool Pturn = false;
bool Eturn = false;;
if(PlayerHealth <= 0)
{
App.Close();
}
else
{
if(EnemyHealth <= 0)
{
App.Close();
}
else
{
Pturn = true;
}
}

if(Pturn == true)
{
if(App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
{
EnemyHealth = EnemyHealth - 10;
Eturn = true;
Pturn = false;
}
}
if(Eturn == true)
{
PlayerHealth = PlayerHealth - 10;
Pturn = true;
Eturn = false;
}
}

App.Display();

}

return EXIT_SUCCESS;
}

Pages: [1]
anything