Example #1
0
bool GameLayer::ifCollideBody(Point pos){
    bool value = false;
    Snake* node;
    for (int i =0; i<body.size(); i++) {
        node = body.at(i);
        Point nodepos = node->getPosition();
        if(nodepos==pos){
            value = true;
        }
    }
    return value;
}
Example #2
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();
	}
}