-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect_snake_thing.cpp
112 lines (79 loc) · 2.61 KB
/
collect_snake_thing.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Header.h"
void collect_snake_thing::grow_snake() {
if (snake_circs.size() > 1) {
snake_circs.push_back(circle(snake_circs[snake_circs.size() - 1], snake_body_rad));
}
else {
snake_circs.push_back(circle(_pictures[0], snake_body_rad));
}
}
void collect_snake_thing::procces_collisions() {
for (int i = frut_circs.size() - 1; i >= 0; i--) {
if (_pictures.at(0).is_in_rec(frut_circs[i], 0)) {
grow_snake();
frut_circs.erase(frut_circs.begin() + i);
}
/*
if (frut_circs[i].is_in_circle(snake_circs[0], 2.5f)) {
grow_snake();
frut_circs.erase(frut_circs.begin() + i);
}*/
}
for (int i = snake_circs.size() - 1; i >= 0; i--) {
if (_pictures.at(1).is_in_rec(snake_circs[i], 0.5)) {
snake_circs.erase(snake_circs.begin() + i);
}
}
}
void collect_snake_thing::action() {
while ((snake_circs.size() > 0 || frut_circs.size() > 0) && player->food - food_spend >= 0)
{
position dir;
if (GetAsyncKeyState(VK_LEFT))
{
dir.x += -1;
something_changed = true;
}
if (GetAsyncKeyState(VK_RIGHT))
{
dir.x += 1;
something_changed = true;
}
if (GetAsyncKeyState(VK_UP))
{
dir.y += 1;
something_changed = true;
}
if (GetAsyncKeyState(VK_DOWN))
{
dir.y += -1;
something_changed = true;
}
dir.normalise();
_pictures.at(0).sum(dir.mult(speed));
if (snake_circs.size() > 0) {
snake_circs.at(0).move_to(_pictures.at(0), dist_between_body_parts);
}
for (int i = 1; i < snake_circs.size(); i++) {
snake_circs.at(i).move_to(snake_circs.at(i - 1), dist_between_body_parts);
}
if (something_changed == true) {
take_the_food();
procces_collisions();
render();
something_changed = false;
}
}
outtro();
}
void collect_snake_thing::get_possible_loot() {
std::ifstream scull("scull.txt");
std::ifstream dino("dino.txt");
std::ifstream doll("doll.txt");
std::vector<loot> possible_loot = { loot(scull, "a really cool scull", 99, 0, 0), loot(dino, "cute dino figurine", 7, 0, 0), loot(doll, "an ancient (?) doll", 7, 0, 0) };
result_loot = possible_loot[rand_int(0, possible_loot.size() - 1)];
}
void collect_snake_thing::change_dificulty() {
speed -= difficulty_lewel * 0.3;
start_food_am += difficulty_lewel * 6;
}