-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnakeNode.cpp
More file actions
122 lines (101 loc) · 2.42 KB
/
Copy pathSnakeNode.cpp
File metadata and controls
122 lines (101 loc) · 2.42 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
112
113
114
115
116
117
118
119
120
121
122
#include <SFML/Graphics.hpp>
#include <cmath>
#include <iostream>
#include "SnakeNode.h"
using namespace sfSnake;
const float SnakeNode::Width = 25.f;
const float SnakeNode::Height = 14.f;
const float SnakeNode::Radius = 15.f;
Rectangle::Rectangle(sf::Vector2f position)
: position_(position)
{
shape_.setPosition(position_);
shape_.setOrigin(SnakeNode::Width / 2, SnakeNode::Height / 2);
shape_.setFillColor(sf::Color(253, 220, 222));
shape_.setSize(sf::Vector2f(SnakeNode::Width, SnakeNode::Height));
}
void Rectangle::setPosition(sf::Vector2f position)
{
position_ = position;
shape_.setPosition(position_);
}
void Rectangle::setPosition(float x, float y)
{
position_.x = x;
position_.y = y;
shape_.setPosition(position_);
}
void Rectangle::setRotation(float x)
{
shape_.setRotation(x);
}
void Rectangle::move(float xOffset, float yOffset)
{
position_.x += xOffset;
position_.y += yOffset;
shape_.setPosition(position_);
shape_.setRotation(-180 / 3.14 * atan2(xOffset, yOffset));
}
sf::FloatRect Rectangle::getBounds() const
{
return shape_.getGlobalBounds();
}
sf::Vector2f Rectangle::getPosition() const
{
return position_;
}
float Rectangle::getRotation() const
{
return shape_.getRotation();
}
void Rectangle::render(sf::RenderWindow &window)
{
window.draw(shape_);
}
Circle::Circle(sf::Vector2f position)
: position_(position)
{
shape_.setOrigin(SnakeNode::Radius, SnakeNode::Radius);
shape_.setPosition(position_);
shape_.setFillColor(sf::Color(253, 89, 92));
shape_.setRadius(SnakeNode::Radius);
}
void Circle::setPosition(sf::Vector2f position)
{
position_ = position;
shape_.setPosition(position_);
}
void Circle::setPosition(float x, float y)
{
position_.x = x;
position_.y = y;
shape_.setPosition(position_);
}
void Circle::setRotation(float x)
{
shape_.setRotation(x);
}
void Circle::move(float xOffset, float yOffset)
{
position_.x += xOffset;
position_.y += yOffset;
shape_.setPosition(position_);
shape_.setRotation(-180 / 3.14 * atan2(xOffset, yOffset));
}
sf::FloatRect Circle::getBounds() const
{
sf::FloatRect bounds(shape_.getPosition().x - SnakeNode::Radius / 1.414, shape_.getPosition().y - SnakeNode::Radius / 1.414, SnakeNode::Radius * 1.414, SnakeNode::Radius * 1.414);
return bounds;
}
sf::Vector2f Circle::getPosition() const
{
return position_;
}
float Circle::getRotation() const
{
return shape_.getRotation();
}
void Circle::render(sf::RenderWindow &window)
{
window.draw(shape_);
}