Ejemplo n.º 1
0
void MainGame::gameLoop(){
	while (_gameState != GameState::EXIT) {
		//used for frame time measuring
		_fpsLimiter.begin();
		processInput();

		_time += 0.01f;

		_camera.update();

		//update bullets
		for (int i = 0; i < _bullets.size(); i++) {
			if (_bullets[i].update()) {
				_bullets[i] = _bullets.back();
				_bullets.pop_back();
			}
			else {
				i++;
			}
			
		}

		drawGame();
		_fps = _fpsLimiter.end();

		static int count = 0;
		count++;
		if (count == 10000) {
			std::cout << _fps << std::endl;
			count = 0;
		}
	}
}
Ejemplo n.º 2
0
//This is the main game loop for our program
void MainGame::gameLoop() {

    //Will loop until we set _gameState to EXIT
    while (_gameState != GameState::EXIT) {
       
        _fpsLimiter.begin();

        processInput();
        _time += 0.1;

		grid->runGasSimulation();

        _camera.update();
		//std::cout << _fps << std::endl;
		updateGame();

        drawGame();

        _fps = _fpsLimiter.end();

        //print only once every 10 frames
        static int frameCounter = 0;
        frameCounter++;
        if (frameCounter == 1000) {
            std::cout << _fps << std::endl;
            frameCounter = 0;
        }
    }
}
Ejemplo n.º 3
0
void  MainGame::gameLoop()
{

	while (_gameState != GameState::EXIT)
	{
		//frame time measure
		float startTicks = SDL_GetTicks();
		processInput();

		_camera.update();
		drawGame();

		_time += 0.1f;
		calculateFPS();
		//print olny once every 10 frames
		static int frameCounter = 0;
		if (frameCounter == 10)
		{
			std::cout << _fps << std::endl;
			frameCounter = 0;
		}
		frameCounter++;

		float frameTicks = SDL_GetTicks() - startTicks;
		//limiting fps 
		if (1000.0f/_maxFPS >frameTicks)
		{
			SDL_Delay((1000.0f/_maxFPS)-frameTicks);
		}
	}

};
Ejemplo n.º 4
0
int main( int argc, char* argv[] )
{		
	//Create the game framework
	Initialise(SCREEN_X, SCREEN_Y, false);

	initGame();

	do {
		g_iFrameCounter++;

		if(g_iFrameCounter > 5000)
		{
			g_iFrameCounter = 0;
		}

		ClearScreen();
		updateGame();
		drawGame();

		if( checkExit() )
		{
			break;
		}
		
	} while( FrameworkUpdate() == false );

	destroyGame();

	Shutdown();

	return 0;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
    errlog = fopen("errlog.txt", "a");
    Difficulty d;
    /* check command line args */
    if (argc != 3)
        exit(1);
    if (strcmp(argv[1], "-d"))
        exit(1);
    switch (argv[2][0]) {
    case '1':
        d = BEGINNER;
        break;
    case '2':
        d = INTERMEDIATE;
        break;
    case '3':
        d = EXPERT;
        break;
    default:
        exit(1);
    }
    setUp();
    Game *g = newGame(d);
    while (!(g->gameOver)) {
        drawGame(g);
        pollInput(g);
    }
    free(g);
    quitWithError("Game over");
    return 0;
}
Ejemplo n.º 6
0
void Game::gameLoop() {
   const double dt = 16.66666666666;
   double currentTime = SDL_GetTicks();
   double newTime;
   double frameTime;
   double accumelator = 0.0;

   unsigned int updates = 0;
   unsigned int frames = 0;
   unsigned int seconds = 0;
   while(!e.input->windowClosed()) {
      newTime = SDL_GetTicks();
      frameTime = newTime - currentTime;
      currentTime = newTime;
      accumelator += frameTime;

      while(accumelator >= dt) {
         update();
         updates++;
         accumelator -= dt;
      }

      drawGame();
      frames++;
      if(SDL_GetTicks() - seconds > 1000) {
         //printf("Updates: %d\nFrames: %d\nMouse X: %d\nMouse Y: %d\n", updates, frames, Input::getMouseX(e.camera), Input::getMouseY(e.camera));
         updates = 0;
         frames = 0;
         seconds = SDL_GetTicks();
      }
   }
}
Ejemplo n.º 7
0
void MainGame::gameLoop() {
    
    Bengine::FpsLimiter fpsLimiter;
    fpsLimiter.setMaxFPS(60.0f);

    // Main loop
    while (_gameState == GameState::PLAY) {
        fpsLimiter.begin();

        checkVictory();
		if (_timeElapsed > 100 && !_soldiersSpawned)
			initSoldiers();
		else
			_timeElapsed++;

        processInput();
       
        updateAgents();

        updateBullets();

        _camera.setPosition(_player->getPosition());

        _camera.update();

        drawGame();

        _fps = fpsLimiter.end();
    }
}
Ejemplo n.º 8
0
//This is the main game loop for our program
void MainGame::gameLoop() {

    //Will loop until we set _gameState to EXIT
    while (_gameState != GameState::EXIT) {
        //Used for frame time measuring
        float startTicks = SDL_GetTicks(); 

        processInput();
        _time += 0.01;

        _camera.update();

        drawGame();
        calculateFPS();

        //print only once every 10 frames
        static int frameCounter = 0;
        frameCounter++;
        if (frameCounter == 10) {
            std::cout << _fps << std::endl;
            frameCounter = 0;
        }

        float frameTicks = SDL_GetTicks() - startTicks;
        //Limit the FPS to the max FPS
        if (1000.0f / _maxFPS > frameTicks) {
            SDL_Delay((Uint32)(1000.0f / _maxFPS - frameTicks));
        }
    }
}
Ejemplo n.º 9
0
int main() {
  init();

  while (true) {
    setGameInput();
    game->update();
    if (!game->isActive()) {
      showGameOver();
      wait(.1f);
      getch();
      nodelay(stdscr, FALSE);
      int ch = getch();
      if (ch == 'q' || ch == 'Q') {
        break;
      } else {
        game->newGame({gameWidth / 3, gameHeight / 3}, direction::RIGHT, STARTLENGTH);
        nodelay(stdscr, TRUE);
      }
    }
    drawGame();
    refresh();
    wait(0.1f);
  }

  endwin();
  return 0;
}
Ejemplo n.º 10
0
void MainGame::gameLoop()
{
	Skengine::FpsLimiter fpsLimiter;
	fpsLimiter.setMaxFPS(60);
	while (_currentState == GAME_STATE::PLAY)
	{
		fpsLimiter.begin();



		processInput();
		_camera.setPosition(_player->getPosition());
		_camera.update();
		//UPDUATE AGENTS
		for (int i = 0; i < _humans.size(); i++)
		{
			_humans[i]->update(_levels[_currentLevel]->getLevelData(), _humans, _zombies);
		}
		for (int i = 0; i < _humans.size(); i++)
		{
			for (int j = i + 1; j < _humans.size(); j++)
			{
				_humans[i]->collideWithAgent(_humans[j]);
			}
		}

		//Add Zombies
		drawGame();

		_fps = fpsLimiter.end();
	}
}
Ejemplo n.º 11
0
void MainVidGame::gameLoop() {

	while (_gameState != GameState::EXIT) {
		processInput();
		drawGame();
	}

}
Ejemplo n.º 12
0
void Game::gameLoop() {
	while (_gameState != GameState::EXIT) {
		processInput();

		_time += 0.01f;

		drawGame();
	}
}
Ejemplo n.º 13
0
bool Engine::fillLiquidContainer()
{
    //query item from player to fill
    std::vector<int> filter;
    filter.push_back(OBJ_ITEM_CONTAINER_LIQUID);
    Item *titem = selectItemFromInventory(m_Player->getInventory(), "Fill what?", filter);
    ContainerLiquid *tcl = dynamic_cast<ContainerLiquid*>(titem);
    if(tcl == NULL) return false;

    //get direction of source
    m_MessageManager->addMessage("Fill from what source?");
    m_Screen->clear();
    drawGame();
    //drawString(0, m_ScreenTilesHeight-1, "Fill from what source?");
    m_Screen->display();

    //get tile to draw liquid from
    sf::Vector2i ppos = m_Player->getPosition();
    getDirectionFromUser(&ppos);

    //check that tile is valid liquid source
    if(m_MapTiles[m_CurrentMap->getTile(ppos.x, ppos.y)]->hasLiquid() )
    {
        //check if item container type can fill from source liquid
        Liquid *source = m_MapTiles[m_CurrentMap->getTile(ppos.x, ppos.y)]->getLiquid();

        //if container is not empty
        if(!tcl->isEmpty())
        {
            //if liquid types do not match
            if(tcl->getLiquidType() != source)
            {
                std::stringstream fmsg;
                fmsg << "Need to empty " << tcl->getName() << " before filling with " << source->getName();
                m_MessageManager->addMessage(fmsg.str() );
                return false;
            }
        }

        //go ahead and fill with source liquid
        tcl->fillWithLiquid(source);
        std::stringstream fmsg;
        fmsg << "Filled " << tcl->getName() << " with " << source->getName();
        m_MessageManager->addMessage(fmsg.str() );

    }
    else
    {
        m_MessageManager->addMessage("There is no liquid source there!");
        return false;
    }

    return true;

}
Ejemplo n.º 14
0
Game *startGame()
{
	Game *game = malloc(sizeof(Game));
	
	game->renderer = start_UI(0);
	game->map      = newMap();
		
	drawGame(game);
	
	return game;
}
Ejemplo n.º 15
0
void GUI::Game::Game::draw(sf::RenderWindow& window) {
	window.clear();

	if (settingsMenu) {
		settingsMenu->draw(window);
	} else {
		window.setView(gameView);
		drawGame(window);
		window.setView(guiView);
		Container::draw(window);
	}
}
Ejemplo n.º 16
0
void RubikGame::gameLoop()
{
	while(_gameState != GameState::EXIT)
	{
		frameSetUp();
		processInput();
		timeProgress();
		updateCamera();
		drawGame();
		frameTearDown();
	}
}
Ejemplo n.º 17
0
/*
* Game execution: Gets input events, processes game logic and draws sprites on the screen
*/
void Game::gameLoop() {	
	_gameState = GameState::PLAY;
	while (_gameState != GameState::EXIT) {		
			//Start synchronization between refresh rate and frame rate
		_fpsLimiter.startSynchronization();
			//Process the input information (keyboard and mouse)
		processInput();
			//Draw the objects on the screen
		drawGame();	
			//Force synchronization
		_fpsLimiter.forceSynchronization();
	}
}
Ejemplo n.º 18
0
void MainGame::gameLoop(){

	NeroEngine::FpsLimter _fpsLimter;
	_fpsLimter.setMaxFps(60.0f);

	const float CAMERA_SCALA = 2.0f;
	_camera.setScale(CAMERA_SCALA);
	
	const int  MAX_PHYSISC_STEPS = 1.0f;
	const float DESIREO_FPS = 60.0f;
	const float MS_PER_SECOND = 1000;
	const float MAX_DETLA_TIME = 1.0f;
	const float DESIREO_FRAMETIME = MS_PER_SECOND / DESIREO_FPS;
	float previousTicks = SDL_GetTicks();
	while (_gameState==GameState::PLAY){
		_fpsLimter.begin();
		float newTicks = SDL_GetTicks();
		float frameTime = newTicks - previousTicks;
		previousTicks = newTicks;

		float totalDeltaTime = frameTime / DESIREO_FRAMETIME;

		checkVictory();

		processInput();
		int i = 0;
		while (totalDeltaTime>=0.0f && i<MAX_PHYSISC_STEPS)
		{
			_deltaTime = 1.0f;// std::min(totalDeltaTime, MAX_DETLA_TIME);
			updateAgent(_deltaTime);
			updateBullet(_deltaTime);
			
			//_miniMap.update([=](std::vector<Zombie*> zombies, std::vector<Human*> humans)->void{
				
			//});

			totalDeltaTime += _deltaTime;
			i++;
		}
		
		_particleEngine.update(_deltaTime);

		_camera.setPosition(_player->getAgentPos());

		_camera.update();
		
		drawGame();

		_fps = _fpsLimter.end();
	}
}
Ejemplo n.º 19
0
/**
* Render the game on the screen
*/
void Game::renderGame() {
		//Clear the screen
	_graphic.clearWindow();

		//Draw the screen's content based on the game state
	if (_gameState == GameState::MENU) {
		drawMenu();
	}
	else {
		drawGame();
	}
		//Refresh screen
	_graphic.refreshWindow();
}
Ejemplo n.º 20
0
// Interrupcion
void interruptHandler() {
   static u8 i, j;   // Static variable to be preserved from call to call
   
   //cpct_setBorder(interruptId+1);

   if(scene == G_sceneGame && interruptId == 5) {
      drawGame();
   }

   // Count one more interrupt. There are 6 interrupts in total (0-5)
   if (++interruptId > 5) {
      interruptId = 0;
      if(++j > 1) {
         j = 0;
      }
   }
}
Ejemplo n.º 21
0
main() {
    // this counter is used to control the rate of refreshing
    uint16_t cnt = 0;

    meggyInit();
    // Serial out stuff
//    sei();
    while (1) {
        // snake.length * 10 is used to offset the overhead brought by
        // calculations of the snake body. Since the bigger the body is, the
        // longer time it takes to compute
        cnt > 300 - snake.length * 10 ? loop(&cnt) : cnt++;
        if (gameStage == Ongoing) {
            drawGame( );
            checkCollision(&gameStage, snake);
        }
    }
}
Ejemplo n.º 22
0
void Game::Go()
{
    Event evt;

    while(pWnd->isOpen())
    {

        while (pWnd->pollEvent(evt))
        {
            processEvent(evt);
        }

        pWnd->clear();
        updateGame();
        drawGame();
        pWnd->display();
    }
}
Ejemplo n.º 23
0
void MainGame::gameLoop() {
	HackEngine::FpsLimiter fpsLimiter;
	fpsLimiter.setMaxFps(60.0f);
	
	while (_gameState  == GameState::PLAY){
		fpsLimiter.begin();

		processInput();
		
		updateAgents();

		_camera.setPosition(_player->getPosition());

		_camera.update();

		drawGame();
		_fps = fpsLimiter.end();
	}
}
Ejemplo n.º 24
0
static void init() {
  initscr();
  cbreak();
  keypad(stdscr, TRUE);
  nodelay(stdscr, TRUE);
  noecho();
  curs_set(0);
  srand(time(NULL));

  getmaxyx(stdscr, screenHeight, screenWidth);
  gameHeight = screenHeight - 2;
  gameWidth = (screenWidth - 2 - (screenWidth % 2 == 0 ? 0 : 1)) / 2;
  game = new Game(gameWidth, gameHeight);
  game->newGame({gameWidth / 3, gameHeight / 3}, direction::RIGHT, STARTLENGTH);

  drawBorder();
  drawGame();
  refresh();
}
Ejemplo n.º 25
0
void playBattleship(void) {

	char board[SIZE], mask[SIZE];
	char previousMove[] = "N/A";
	int missilesFired = 0, score = 0, missilesRemaining = 100;
	char coord[] = "N/A";
	char c = 0;

	initGame(board, mask);
	
	do {
		
		drawGame(board, missilesFired, missilesRemaining, score, previousMove);
		printf("Missles Fired:%d  Missles Remaining:%d\n", missilesFired, missilesRemaining);
		printf("Current Score %d  \n", score);
		checkMove(coord);
		updateData(board, mask, &missilesFired, &missilesRemaining, &score, previousMove, coord);
	} while (missilesRemaining > 0 && score != 110);
	getchar();
}
Ejemplo n.º 26
0
void MainGame::gameLoop()
{
    while ( _gameState != GameState::EXIT) {
        _fpsLimiter.begin();

        processInput();
        _time += 0.01;

        _camera.update();

        for (int i = 0; i < _bullets.size();)
        {
            // Update all bullets
            if (_bullets[i].update() == true)
            {
                _bullets[i] = _bullets.back();
                _bullets.pop_back();
            }
            else
            {
                i++;
            }

        }

        drawGame();

        _fps = _fpsLimiter.end();

        //print only once every 10 frames
        static int frameCounter = 0;
        frameCounter++;
        if(frameCounter == 10000)
        {
            std::cout << _fps << std::endl;
            frameCounter = 0;
        }


    }
}
Ejemplo n.º 27
0
void loadGame(Game *game)
{
	int x, y;
	
	int **map      = readFile("map.txt");
	int **position = readFile("position.txt");

	for (x = 0; x < 100; x++) {
		for (y = 0; y < 100; y++) {
			game->map->cases[y][x]->digged = map[x][y];
		}
		
		free(map[x]);
	}
	
	free(map);
	
	game->map->center = game->map->cases[position[0][0]][position[1][0]];
	
	drawGame(game);
}
Ejemplo n.º 28
0
	void ZombieGame::draw(Uint32 deltaTime) {
		gui::Component::draw(deltaTime);

		++frame_;
		lastFramTime_ += deltaTime;
		if (frame_ == 60) {
			meanFrameTime_ = lastFramTime_/1000.f;
			frame_ = 0;
			lastFramTime_ = 0;
		}
		
		viewPosition_ += 10 * deltaTime/1000.f * (refViewPosition_ - viewPosition_);
		
		if (started_) {
			updateGame(deltaTime / 1000.f);
		}

		drawGame(deltaTime / 1000.f);
				
		refViewPosition_ = humanState_.position_ + 0.5 * humanState_.velocity_;
	}
Ejemplo n.º 29
0
void movePerso(Game *game, SDL_Keycode key)
{
	switch (key) {
		case SDL_SCANCODE_UP:
			updateMapCenter(game->map, 0, -1);
			break;
			
		case SDL_SCANCODE_DOWN :
			updateMapCenter(game->map, 0, 1);
			break;
			
		case SDL_SCANCODE_LEFT :
			updateMapCenter(game->map, -1, 0);
			break;
			
		case SDL_SCANCODE_RIGHT :
			updateMapCenter(game->map, 1, 0);
			break;
	}
	
	drawGame(game);
}
Ejemplo n.º 30
0
//This is the main game loop for our program
void MainGame::gameLoop() 
{

    //Will loop until we set _gameState to EXIT
    while (_gameState != GameState::EXIT)
	{
       
        _fpsLimiter.begin();

        processInput();
        _time += 0.1f;

        _camera.update();

        // Update all bullets
        for (unsigned int i = 0; i < _bullets.size();)
		{
            if (_bullets[i].update() == true)
			{
                _bullets[i] = _bullets.back();
                _bullets.pop_back();
            } 
			else 
			{
                i++;
            }
        }

        drawGame();

        _fps = _fpsLimiter.end();

		static SDLopenGL::CTimer timer;
        if (timer.TimeOver(1000)) 
		{
			std::cout << SDLopenGL::string_format("FPS: %7.2f\n", _fps);
        }
    }
}