Example #1
0
void World::update(Snake &player, Textbox &textbox) {
	if (player.getPosition() == _item) {
		player.extend();
		player.increaseScore();

		textbox.add("You ate an apple. Score:" + std::to_string(player.getScore()));

		while(player.checkCollisionWithNewItem(_item))
			respawnApple();
	}

	int gridSizeX = _windowSize.x / _blockSize;
	int gridSizeY = _windowSize.y / _blockSize;

	if (player.getPosition().x <= 0
		|| player.getPosition().y <= 0
		|| player.getPosition().x >= gridSizeX - 1
		|| player.getPosition().y >= gridSizeY - 1) {

		player.lose();
	}
}