-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbodypart.cpp
More file actions
67 lines (56 loc) · 1.19 KB
/
Copy pathbodypart.cpp
File metadata and controls
67 lines (56 loc) · 1.19 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
#include "bodypart.hpp"
#include "constvars.hpp"
BodyPart::BodyPart()
{
partShape.setSize(sf::Vector2f(CELL_SIZE,CELL_SIZE));
partShape.setPosition(sf::Vector2f(500.0f,500.0f));
partShape.setFillColor(sf::Color(150,255,150));
}
BodyPart::BodyPart(sf::Vector2f position)
{
partShape.setSize(sf::Vector2f(CELL_SIZE,CELL_SIZE));
partShape.setPosition(position);
partShape.setFillColor(sf::Color(150,255,150));
}
void BodyPart::move(Direction dir)//(U)p (D)own (L)eft (R)ight
{
lastPosition = partShape.getPosition();
switch(dir)
{
case Up:
partShape.move(0,-SNAKE_SPEED);
break;
case Down:
partShape.move(0,SNAKE_SPEED);
break;
case Left:
partShape.move(-SNAKE_SPEED,0);
break;
case Right:
partShape.move(SNAKE_SPEED,0);
break;
default:
break;
}
}
void BodyPart::draw(sf::RenderWindow *win)
{
win->draw(partShape);
}
sf::Vector2f BodyPart::getPosition()
{
return partShape.getPosition();
}
sf::Vector2f BodyPart::getLastPosition()
{
return lastPosition;
}
void BodyPart::setPosition(sf::Vector2f newPos)
{
lastPosition = partShape.getPosition();
partShape.setPosition(newPos);
}
void BodyPart::setColor(sf::Color newColor)
{
partShape.setFillColor(newColor);
}