Exemplo n.º 1
0
// Perform a single application step, return exit flag if encountered
int Application::run()
{
  // Update current scene, switch to the next scene if
  // need be (in which case we break from the loop and restart).
  Scene* next = NULL;
  // FIXME - the multiplication by two is a lazy fix for Black Dog
  if(scene->update(&next, (this_tick - prev_tick) / 1000.0f * 2 * MAX_FPS)
      != Scene::NO_CHANGE)
    return setScene(next);

  // Redraw everything, game objects included
  draw();

  // Regulate the number of frames per second, pausing if nessecary
  wait();

  // Treat input events, check for exit conditions.
  int flag = treatEvents();
  if(flag == Application::BACK)
    // Attempt to return to previous Inteface - if impossible, return EXIT
    return setScene(scene->previous());
  else
    // Pass on either EXIT or CONTINUE code
    return flag;
}
Exemplo n.º 2
0
//!-----------------------------------------------------------------------------
//! MAIN
//!-----------------------------------------------------------------------------
int main(int argc, char** argv, char** envp)
{
  // open window
  sf::RenderWindow window(sf::VideoMode(WINDOW_W, WINDOW_H), WINDOW_TITLE);
  window.setFramerateLimit(MAX_FPS);

  // create game objects
  n1.neighbours[0] = &n2;
  n1.neighbours[1] = &n3;
  n2.neighbours[2] = &n3;

  // main loop
  while (window.isOpen())
  {
    // deal with events
    if(treatEvents(window) == STOP)
      window.close();

    // update the game
    if(update(getDelta()) == STOP)
      window.close();

    // redraw the game
    renderTo(window);
    window.display();
  }

  // quit
  return EXIT_SUCCESS;
}