示例#1
0
void Player::approach()
{
	bool overDueX = false;
	bool overDueY = false;
	if (pos == posGoal_)
		return;
	else
	{
		Game::display.SetPos(pos, ' ');
		if (pos.x != posGoal_.x)
		{
			pos.x > posGoal_.x ? (pos.x - deltaT_<posGoal_.x ? overDueX = true : overDueX = false) : (pos.x + deltaT_>posGoal_.x ? overDueX = true : overDueX = false);
			pos.x > posGoal_.x ? pos.x-= deltaT_ : pos.x+= deltaT_;
		}
		if (pos.y != posGoal_.y)
		{
			pos.y > posGoal_.y ? (pos.y - deltaT_<posGoal_.y ? overDueY = true : overDueY = false) : (pos.y + deltaT_>posGoal_.y ? overDueY = true : overDueY = false);
			pos.y > posGoal_.y ? pos.y -= deltaT_ : pos.y += deltaT_;
		}
		if (overDueX == true) pos.x = posGoal_.x;
		if (overDueY == true) pos.y = posGoal_.y;
	}
	if (Game::display.GetPos(pos) == '@')
	{
		spawnApple();
		ateApple = true;
	}
	else if (Game::display.GetPos(pos) == snakeGraphic_)
	{
		gameOver();
	}
	Game::display.SetPos(pos, playerGraphic_);
}
示例#2
0
void Application::simulate()
{
    if (m_lives > 0)
    {
        deleteApples();

        ++m_step;
        m_world.Step(1.0f / 60.0f, 6, 2);

        spawnApple();
    }
}