-
Notifications
You must be signed in to change notification settings - Fork 0
/
Food.cpp
38 lines (31 loc) · 877 Bytes
/
Food.cpp
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
#include "Food.hpp"
#include <iostream>
Food::Food(int minX, int minY, int maxX, int maxY, int size)
{
for (int i{minX}; i < maxX; i += size)
xValues.push_back(i);
for (int i{minY}; i < maxY; i += size)
yValues.push_back(i);
Block.w = size;
Block.h = size;
srand(time(0));
Pos[0] = xValues[rand() % xValues.size()];
srand(time(0));
Pos[1] = yValues[rand() % yValues.size()];
}
int Food::GetX() {return Pos[0];}
int Food::GetY() {return Pos[1];}
void Food::Eat()
{
srand(time(0));
Pos[0] = xValues[rand() % xValues.size()];
srand(time(0));
Pos[1] = yValues[rand() % yValues.size()];
}
void Food::Draw(SDL_Renderer *renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
Block.x = Pos[0];
Block.y = Pos[1];
SDL_RenderDrawRect(renderer, &Block);
}