-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.h
143 lines (138 loc) · 3.57 KB
/
Node.h
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef NODE_H_INCLUDED
#define NODE_H_INCLUDED
#include "Random.h"
#include "PenjinTypes.h"
enum NodeType
{
RED_NODE = 1,
BLUE_NODE,
GREEN_NODE,
CUSTOM_NODE // Used for pickups, adds to snakes dominant type
};
class Node
{
public:
Node()
{
pos.x = 0;
pos.y = 0;
colour = CUSTOM_NODE;
}
Node(Vector2df pos)
{
this->pos = pos;
colour = CUSTOM_NODE;
}
Node(int X,int Y)
{
pos = Vector2df(X,Y);
colour = CUSTOM_NODE;
}
Node(Node* n)
{
pos = n->getPos();
colour = n->getColour();
}
void randomiseColour()
{
randGen.setLimits(RED_NODE,BLUE_NODE*4);
colour = (uint)randGen.nextInt();
if(colour<4)
colour=BLUE_NODE;
else if(colour >=4 && colour<8)
colour=GREEN_NODE;
else
colour=RED_NODE;
}
uint getColour(){return colour;};
void render(Sprite& red, Sprite& green,Sprite& blue)
{
if(colour == RED_NODE)
{
red.setPosition(pos.x, pos.y);
red.render();
}
else if(colour == GREEN_NODE)
{
green.setPosition(pos.x, pos.y);
green.render();
}
else if(colour == BLUE_NODE)
{
blue.setPosition(pos.x, pos.y);
blue.render();
}
}
void render( AnimatedSprite& red, AnimatedSprite& green,AnimatedSprite& blue)
{
if(colour == RED_NODE)
{
red.setPosition(pos.x, pos.y);
red.render();
}
else if(colour == GREEN_NODE)
{
green.setPosition(pos.x, pos.y);
green.render();
}
else if(colour == BLUE_NODE)
{
blue.setPosition(pos.x, pos.y);
blue.render();
}
}
void setColour(uint colour){this->colour = colour;};
void updateXY(Vector2df velocity)
{
// Sort X first
if(velocity.x < 0)
{
if(pos.x < 0 )
{
pos.x = 320;
}
}
else
{
if(pos.x > 312)
{
pos.x = 0;
}
}
pos.x += velocity.x;
// Now handle y
if(velocity.y < 0)
{
if(pos.y < 0 )
{
pos.y = 240;
}
}
else
{
if(pos.y > 232)
{
pos.y = 0;
}
}
pos.y += velocity.y;
}
void setX(float x){pos.x = x;};
void setX(int x){pos.x = x;};
void setY(float y){pos.y = y;};
void setY(int y){pos.y = y;};
void randomisePos()
{
randGen.setLimits(30,210);
pos = Vector2df(randGen.nextInt(),randGen.nextInt());
}
void setPos(Vector2df pos){this->pos = pos;};
Vector2df getPos(){return pos;};
float getX(){return pos.x;};
float getY(){return pos.y;};
private:
RandomClass randGen;
Vector2df pos;
uint colour;
};
#endif // NODE_H_INCLUDED