-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCat.cpp
More file actions
executable file
·111 lines (102 loc) · 2.56 KB
/
Cat.cpp
File metadata and controls
executable file
·111 lines (102 loc) · 2.56 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
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
/*
Made with ❤ by srinSkit.
Created on 12 April 2018.
*/
#include <GL/glut.h>
#include "Cat.h"
#include "Common.h"
#include "AutoPilot.h"
#include "Graphics.h"
Cat::Cat(int localOriginX, int localOriginY, bool isStaticModel, bool hide)
: Model(localOriginX, localOriginY, isStaticModel, hide) {
health = 9;
}
void Cat::update() {
if (autoMove && !moveStack.empty()) {
Cell *cell = moveStack.top();
int xt = cell->gridx, yt = cell->gridy;
gridToWorld(xt, yt);
if (x < xt - 1)
x += 2;
else if (x < xt)
x++;
if (x > xt + 1)
x -= 2;
else if (x > xt)
x--;
if (y < yt - 1)
y += 2;
else if (y < yt)
y++;
if (y > yt + 1)
y -= 2;
else if (y > yt)
y--;
if (x == xt && y == yt) {
delete cell;
moveStack.pop();
}
while (moveStack.empty()) {
int gx = rangeRandom(0, 9), gy = rangeRandom(0, 9);
if (coolMan.unsafe(gx, gy))continue;
int ix = x, iy = y;
worldToGrid(ix, iy);
moveStack = autoPilotG(ix, iy, gx, gy);
}
}
if (!insideView(x, y))
destroy();
}
void Cat::enableAutoMove() {
autoMove = true;
while (moveStack.empty()) {
int gx = rangeRandom(0, 9), gy = rangeRandom(0, 9);
if (coolMan.unsafe(gx, gy))continue;
int ix = x, iy = y;
worldToGrid(ix, iy);
moveStack = autoPilotG(ix, iy, gx, gy);
}
}
void Cat::onHit() {
health--;
if (health <= 0) {
coolMan.pop(this);
destroy();
}
score += 4;
}
Cat *cat = nullptr;
void loadCatMod() {
cat = new Cat(worldWidth / 4, worldHeight / 3, false, false);
auto v = new Vertex[8];
v[0].set(-20, -20);
v[1].set(20, -20);
v[2].set(20, 20);
v[3].set(15, 35);
v[4].set(10, 20);
v[5].set(-10, 20);
v[6].set(-15, 35);
v[7].set(-20, 20);
auto element = new Element(8, v, GL_POLYGON);
element->setColor(50, 255, 50);
cat->addElement(element);
v = new Vertex[4];
v[0].set(5, 5);
v[1].set(15, 5);
v[2].set(15, 15);
v[3].set(5, 15);
element = new Element(4, v, GL_POLYGON);
element->setColor(0, 0, 0);
cat->addElement(element);
v = new Vertex[4];
v[0].set(-5, 5);
v[1].set(-15, 5);
v[2].set(-15, 15);
v[3].set(-5, 15);
element = new Element(4, v, GL_POLYGON);
element->setColor(0, 0, 0);
cat->addElement(element);
}
void unloadCatMod() {
delete cat;
}