-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshit.cpp
More file actions
53 lines (50 loc) · 1.37 KB
/
shit.cpp
File metadata and controls
53 lines (50 loc) · 1.37 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
#include "shit.h"
Shit::Shit()
{
shitImg = newimage();
getimage(shitImg, "./cpp-snake-ege/assets/shit.jpg");
// getimage(shitImg, "./assets/shit.jpg"); // exe file
}
void Shit::draw()
{
for (auto &p : shit_position)
{
putimage(p.x, p.y, shitImg);
}
}
void Shit::generateRandomly(Point& food, vector<Point>& wall_position, Snake& snake, SecondSnake& secondSnake)
{
int x = rand() % ((WINDOW_WIDTH - 2 * GRID_SIZE) / GRID_SIZE) * GRID_SIZE + GRID_SIZE;
int y = rand() % ((WINDOW_HEIGHT - 2 * GRID_SIZE) / GRID_SIZE) * GRID_SIZE + GRID_SIZE;
if (x == food.x && y == food.y)
{
generateRandomly(food, wall_position, snake, secondSnake);
return;
}
for (auto &p : snake.getBody())
{
if (x == p.x && y == p.y)
{
generateRandomly(food, wall_position, snake, secondSnake);
return;
}
}
for (auto &p : secondSnake.getBody())
{
if (x == p.x && y == p.y)
{
generateRandomly(food, wall_position, snake, secondSnake);
return;
}
}
for (auto &p : wall_position)
{
if (x == p.x && y == p.y)
{
generateRandomly(food, wall_position, snake, secondSnake);
return;
}
}
Point p = {x, y};
shit_position.push_back(p);
}