-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.cpp
107 lines (88 loc) · 1.93 KB
/
classes.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
#include <SFML/Graphics.hpp>
#include <cmath>
#include "classes.hpp"
int round(float number)
{
return (int) floor(number + 0.5);
}
Pair::Pair(int setX, int setY)
{
x = setX;
y = setY;
}
Pair::Pair()
{
x = 0;
y = 0;
}
Pair addPair(Pair const &addOne, Pair const &addTwo)
{
return Pair(addOne.x + addTwo.x, addOne.y + addTwo.y);
}
Pair scalarPair(int scalar, Pair const &onePair)
{
return Pair(scalar * onePair.x, scalar * onePair.y);
}
Pair rotate(Pair const &vector, float degree)
{
Pair rotated_vector;
rotated_vector.x = round(vector.x * cos(degree) - vector.y * sin(degree));
rotated_vector.y = round(vector.y * cos(degree) + vector.x * sin(degree));
return rotated_vector;
}
//-------------------
Wall::Wall(Pair setLocation, Pair setSize, sf::Color setColor)
{
location = setLocation;
size = setSize;
color = setColor;
rectangle.setPosition(location.x, location.y);
rectangle.setSize(sf::Vector2f(size.x, size.y));
rectangle.setFillColor(color);
}
Pair Wall::getLocation()
{
return location;
}
Pair Wall::getSize()
{
return size;
}
void Wall::move(Pair units)
{
location = addPair(location, units);
rectangle.setPosition(location.x, location.y);
}
void Wall::draw(sf::RenderWindow& window)
{
window.draw(rectangle);
}
//--------------------------
Ball::Ball(Pair setLocation, Pair setVelocity, int setRadius, sf::Color setColor)
{
radius = setRadius;
circle.setRadius(radius);
location = setLocation;
circle.setPosition(location.x - radius, location.y - radius);
velocity = setVelocity;
color = setColor;
circle.setFillColor(color);
}
void Ball::setPos(Pair newLocation)
{
location = newLocation;
circle.setPosition(location.x - radius, location.y - radius);
}
void Ball::move(Pair units)
{
location = addPair(location, units);
circle.setPosition(location.x, location.y);
}
void Ball::update()
{
move(velocity);
}
void Ball::draw(sf::RenderWindow& window)
{
window.draw(circle);
}