void AsteroidsGame::OnUpdate(const GameTime& time)
{
	updateBound();
	collisionDetect(time); 
	auto title = "Time: " + to_string(time.TotalSeconds()) + " Score: " + to_string(score);
	title += " Life: " + to_string(life) + " Level: " + to_string(level);
	glfwSetWindowTitle(m_window, title.c_str());
}
Esempio n. 2
0
bool Game::Run()
{
    if(!Initialize())
    {
        Log::Error << "Could not initialize GLFW window.\n";
        return false;
    }
    
    GameTime time;

    
    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(m_window))
    {
        /* Poll for and process events */
        glfwPollEvents();
        
        Update(time);
        
        
        gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
        
        Render(time);
        
        /* Render here */
        /* Swap front and back buffers */
        glfwSwapBuffers(m_window);
        
        auto title = "Time: " + std::to_string(time.TotalSeconds());
        
        glfwSetWindowTitle(m_window, title.c_str());
                           
        time.Update();
    }
    
    Dispose();
    
    return true;
    
}
Esempio n. 3
0
void Material::SetUniforms(const GameTime& time)
{
	SetUniform("GameTimeTotalSeconds", time.TotalSeconds());
	SetUniform("TimeScale", 0.5f);
}
void AsteroidsGame::ProcessInput(const GameTime& time)
{
	auto* window = Game::Instance().Window();

	if (status == GameStatus::running)
	{
		shipInstance->ProcessInput(time);
		if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
		{
			static float lastShotTime = 0;
			if (time.TotalSeconds() - lastShotTime >= 0.5)
			{
				shipShot();
				lastShotTime = time.TotalSeconds();
			}
		}
		if (glfwGetKey(window, GLFW_KEY_KP_ADD) == GLFW_PRESS)
		{
			static float lastAddTime = 0;
			if (time.TotalSeconds() - lastAddTime >= 0.5)
			{
				showNAsteroid(1);
				lastAddTime = time.TotalSeconds();
			}
		}
	}

	if (glfwGetKey(window, GLFW_KEY_PAGE_UP) == GLFW_PRESS)
	{
		auto& camRotate = Game::Camera.Transform.Rotation;
		if (camRotate.X <= 2 * PI)
		{
			camRotate.X += 0.01f;
		}
		else
		{
			camRotate = 0;
		}
	}
	if (glfwGetKey(window, GLFW_KEY_PAGE_DOWN) == GLFW_PRESS)
	{
		auto& camRotate = Game::Camera.Transform.Rotation;
		if (camRotate.X >= 0)
		{
			camRotate.X -= 0.01f;
		}
		else
		{
			camRotate = 2*PI;
		}
	}

	static bool lastStatusForEnter = false;
	if (glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_KP_ENTER) == GLFW_PRESS)
	{
		lastStatusForEnter = true;
	}
	else
	{
		if (lastStatusForEnter == true)//means key was pressed down and released
		{
			if (status == GameStatus::pause)
			{
				status = GameStatus::running;
			}
			else if (status == GameStatus::running)
			{
				status = GameStatus::pause;
			}
			else if (status == GameStatus::over)
			{
				reset();
			}
			lastStatusForEnter = false;
		}
	}
	
}