-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFood.cpp
More file actions
67 lines (53 loc) · 1.31 KB
/
Copy pathFood.cpp
File metadata and controls
67 lines (53 loc) · 1.31 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Food.h"
#include <Windows.h>
using namespace std;
Food::Food()
{
};
Food::Food(int whichfood)
:whichfood(whichfood),
pointsPerFood(100),
pos(Vector2f(100.f,100.f))
{
if (texture.getSize().x == 0)
{
std::string _str = std::to_string(whichfood);
if (!texture.loadFromFile("Data/food_" + _str + ".png"))
{
MessageBox(NULL, "Food texture not found !", "ERROR", NULL);
return;
}
}
pointsPerFood = whichfood * 100;
pos.x = rand() % 1200 + 40;
pos.y = rand() % 660 + 40;
sprite.setPosition( pos);
sprite.setTexture(texture);
sprite.scale(0.5f, 0.5f);
Vector2u textureSize = texture.getSize();
sprite.setOrigin(textureSize.x / 2.f, textureSize.y / 2.f);
}
Food::~Food()
{
}
void Food::changeFood( int howmanyFood){
whichfood = (rand() % howmanyFood + 1);
std::string _str = std::to_string(whichfood);
if (!texture.loadFromFile("Data/food_" + _str + ".png"))
{
MessageBox(NULL, "Food texture not found !", "ERROR", NULL);
return;
}
pointsPerFood = whichfood * 100;
clock_food.restart();
pos.x = rand() % 1200 + 40;
pos.y = rand() % 660 + 40;
sprite.setPosition( pos );
sprite.setTexture(texture);
Vector2u textureSize = texture.getSize();
sprite.setOrigin(textureSize.x / 2.f, textureSize.y / 2.f);
}
void Food::setFoodTime()
{
foodTime = this->clock_food.getElapsedTime();
}