-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfruit.cpp
More file actions
31 lines (27 loc) · 695 Bytes
/
Copy pathfruit.cpp
File metadata and controls
31 lines (27 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "fruit.hpp"
#include "constvars.hpp"
#include <SFML/System/Vector2.hpp>
#include <ctime>
#include <cstdlib>
Fruit::Fruit()
{
fruitShape.setSize(sf::Vector2f(CELL_SIZE,CELL_SIZE));
this->reset();
fruitShape.setFillColor(sf::Color::Red);
}
void Fruit::reset()
{
std::srand(std::time(nullptr));
float newPosX = std::rand()%(int)(WIN_WIDTH/CELL_SIZE)*CELL_SIZE;
float newPosY = std::rand()%(int)(WIN_HEIGHT/CELL_SIZE)*CELL_SIZE;
fruitShape.setPosition(sf::Vector2f(newPosX,newPosY));
//fruitShape.setPosition(sf::Vector2f(15.0f,15.0f));
}
sf::Vector2f Fruit::getPosition()
{
return fruitShape.getPosition();
}
void Fruit::draw(sf::RenderWindow &win)
{
win.draw(fruitShape);
}