1 #include <Entities/FruitManager.hpp> 2 #include <Engine/Helpers/Utils.hpp> 3 #include <Config/Globals.hpp> 12 for (std::vector<Fruit>::iterator it = this->fruit.begin(); it != this->fruit.end();)
14 if (player->headHit((*it).x, (*it).y))
17 it = this->fruit.erase(it);
28 int diff = (this->amount - this->fruit.size());
31 for (
int i = 0; i < (diff); i++)
36 return (this->amount);
40 this->fruit.push_back(
Fruit(x, y));
51 newx = Utils::Random::between(1, board->getW() - 2);
52 newy = Utils::Random::between(1, board->getH() - 2);
54 }
while (player->
bodyHit(newx, newy) ||
55 board->
isWall(newx, newy));
57 this->
add(newx, newy);
59 void FruitManager::draw(Window* win)
61 for (
unsigned int i = 0; i < (this->fruit.size()); i++)
65 Globals::Theme::fruit);
void add(int x, int y)
Creates a fruit, adding it at #x, #y.
bool eatenFruit(Player *player)
Tells if the #player has eaten a fruit this frame.
void update(Player *player, Board *board)
Updates internal fruits, adding them to the #board and making sure it doesn't touch #player.
A level where the snake runs and eats fruits.
bool isWall(int x, int y)
Tells if there's a wall at #x #y.
int getAmount()
Returns the maximum size we can store within this manager.
void addRandomly(Board *board, Player *player)
Creates a fruit randomly within boundaries of #board, making sure that it's not inside #player.
bool bodyHit(int x, int y, bool isCheckingHead=false)
Tells if something at #x and #y collides with any part of the snake.
FruitManager(int amount)
Creates a Fruit container that has at most #amount fruits at once on the screen.