Skip to content

Commit 37d46f2

Browse files
committed
Refactoring
1 parent 1295295 commit 37d46f2

21 files changed

+208
-692
lines changed

OpenRocket/OpenRocket/Asteroid.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "Asteroid.h"
22
#include "Constants.h"
33

4-
glm::vec4 Asteroid::circlePoint = { 1.0f, 0.0f, 0.f, 1.f };
5-
glm::vec4 Asteroid::circleCenter = { 0.f, 0.0f, 0.f, 1.f };
4+
glm::vec4 Asteroid::circlePoint = { 1.0f, 0.0f, 0.0f, 1.0f };
5+
glm::vec4 Asteroid::circleCenter = { 0.0f, 0.0f, 0.0f, 1.0f };
66

77
Asteroid::Asteroid(float radius = 40.0f, int nrOfVertices = 16, glm::vec4 coordinates = glm::vec4(0.0f,0.0f, 0.0f, 0.0f),
88
glm::vec4 colors = glm::vec4(0.0f, 0.0f,0.0f,0.0f)) :
@@ -11,7 +11,9 @@ Asteroid::Asteroid(float radius = 40.0f, int nrOfVertices = 16, glm::vec4 coordi
1111
coordinates(coordinates),
1212
colors(colors),
1313
translatedDistance(0),
14-
currentZone(Constants::SAFE) {
14+
currentZone(Constants::SAFE),
15+
asteroidMatrix(glm::mat4(1.0f))
16+
{
1517
textureIndex = rand() % Constants::nrOfTextures;
1618
};
1719

@@ -27,7 +29,7 @@ bool Asteroid::inLowerHalf() {
2729
return !this->belowViewport() && this->isInViewport() && this->getRealY() < Constants::height;
2830
}
2931

30-
string Asteroid::getCurrentZone() {
32+
string Asteroid::getCurrentZone() const {
3133
return this->currentZone;
3234
}
3335

@@ -41,11 +43,11 @@ void Asteroid::updateState() {
4143
}
4244
}
4345

44-
float Asteroid::getX() {
46+
float Asteroid::getX() const {
4547
return this->coordinates.x;
4648
}
4749

48-
float Asteroid::getRealY() {
50+
float Asteroid::getRealY() const {
4951
return this->coordinates.y - this->translatedDistance;
5052
}
5153

@@ -56,10 +58,19 @@ void Asteroid::setX(float newXOffset) {
5658
void Asteroid::setY(float newYOffset) {
5759
this->coordinates.y = newYOffset;
5860
}
59-
int Asteroid::getTextureIndex() {
61+
62+
int Asteroid::getTextureIndex() const {
6063
return this->textureIndex;
6164
}
62-
float Asteroid::getTranslatedDistance() { return this->translatedDistance; }
65+
66+
void Asteroid::setAsteroidMatrix(glm::mat4 matrix) { asteroidMatrix = matrix; }
67+
68+
glm::mat4 Asteroid::getAsteroidMatrix() const { return asteroidMatrix; }
69+
70+
float Asteroid::getTranslatedDistance() const { return this->translatedDistance; }
71+
6372
void Asteroid::setTranslatedDistance(float distance) { this->translatedDistance = distance; }
64-
float Asteroid::getRadius() { return this->radius; }
65-
float Asteroid::getY() { return this->coordinates.y; }
73+
74+
float Asteroid::getRadius() const { return this->radius; }
75+
76+
float Asteroid::getY() const { return this->coordinates.y; }

OpenRocket/OpenRocket/Asteroid.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ class Asteroid {
2121
float translatedDistance;
2222
string currentZone;
2323
int textureIndex;
24+
2425
public:
2526
glm::mat4 asteroidMatrix;
2627
static glm::vec4 circlePoint;
2728
static glm::vec4 circleCenter;
28-
public:
29+
2930
Asteroid(float, int, glm::vec<4, float, (glm::qualifier)0>, glm::vec<4, float, (glm::qualifier)0>);
3031
~Asteroid() { };
3132

3233
bool isInViewport();
3334
void updateState();
3435
bool inLowerHalf();
35-
bool belowViewport();
36-
37-
string getCurrentZone();
38-
void setCurrentZone(string);
36+
bool belowViewport();
3937

40-
float getX();
41-
float getY();
42-
float getRadius();
43-
float getTranslatedDistance();
44-
int getTextureIndex();
45-
glm::mat4 getAsteroidMatrix() { return asteroidMatrix; }
38+
float getX() const;
39+
float getY() const;
40+
float getRadius() const;
41+
float getTranslatedDistance() const;
42+
int getTextureIndex() const;
43+
glm::mat4 getAsteroidMatrix() const;
44+
string getCurrentZone() const;
45+
float getRealY() const;
4646

4747
void setX(float);
48-
float getRealY();
4948
void setY(float);
5049
void setTranslatedDistance(float);
51-
void setAsteroidMatrix(glm::mat4 matrix) { asteroidMatrix = matrix; }
50+
void setAsteroidMatrix(glm::mat4);
51+
void setCurrentZone(string);
5252
};

OpenRocket/OpenRocket/Bullet.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,31 @@ Bullet::Bullet(float radius, float posX, float posY) :
1414
bool Bullet::aboveViewport() {
1515
return this->y > Constants::height;
1616
}
17+
18+
float Bullet::getRadius() const {
19+
return radius;
20+
}
21+
22+
float Bullet::getX() const {
23+
return x;
24+
}
25+
26+
float Bullet::getY() const {
27+
return y;
28+
}
29+
30+
float Bullet::getTranslatedDistance() const {
31+
return translatedDistance;
32+
}
33+
34+
void Bullet::setX(float x) {
35+
this->x = x;
36+
}
37+
38+
void Bullet::setY(float y) {
39+
this->y = y;
40+
}
41+
42+
void Bullet::setTranslatedDistance(float distance) {
43+
translatedDistance = distance;
44+
}

OpenRocket/OpenRocket/Bullet.h

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,17 @@ class Bullet {
88
float y;
99

1010
public:
11-
Bullet(float radius, float posX, float posY);
12-
~Bullet();
11+
Bullet(float, float, float);
12+
~Bullet() {}
1313

14-
float getRadius() const {
15-
return radius;
16-
}
14+
float getRadius() const;
15+
float getX() const;
16+
float getY() const;
17+
float getTranslatedDistance() const;
1718

18-
float getX() const {
19-
return x;
20-
}
21-
22-
float getY() const {
23-
return y;
24-
}
25-
26-
float getTranslatedDistance() const {
27-
return translatedDistance;
28-
}
29-
30-
void setX(float x) {
31-
this->x = x;
32-
}
33-
34-
void setY(float y) {
35-
this->y = y;
36-
}
37-
38-
void setTranslatedDistance(float distance) {
39-
translatedDistance = distance;
40-
}
19+
void setX(float);
20+
void setY(float);
21+
void setTranslatedDistance(float);
4122

4223
bool aboveViewport();
43-
44-
};
24+
};
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "Constants.h"
22

33
const char* Constants::title = "Open Rocket";
4-
const float Constants::PI = 3.141592;
4+
const float Constants::PI = 3.141592f;
55
const int Constants::width = 800;
66
const int Constants::height = 450;
77
const int Constants::nrOfStars = 1000;
88
const int Constants::maxX = 1600;
99
const int Constants::maxY = 900;
1010
const int Constants::nrOfAsteroids = 20;
1111
const int Constants::nrOfAsteroidsPerFrame = 10;
12-
const float Constants::TWO_PI = 6.28;
12+
const float Constants::TWO_PI = 6.28f;
1313
const int Constants::nrOfVerticesPerCircle = 18;
1414
const float Constants::distanceBetweenAsteroids = 150.0f;
1515
const float Constants::asteroidMovingUnit = 0.15f;
@@ -18,8 +18,8 @@ const float Constants::maxYDistance = 4 * Constants::height;
1818
const std::string Constants::xCoord = "x";
1919
const std::string Constants::yCoord = "y";
2020
const std::string Constants::RED = "Red Zone";
21-
const std::string Constants::SAFE= "Safe Zone";
22-
const std::vector<const char*> Constants::textureImages{
21+
const std::string Constants::SAFE = "Safe Zone";
22+
const std::vector<const char*> Constants::textureImages {
2323
"blueAsteroid.png",
2424
"brightOrangeAsteroid.png",
2525
"darkBlueAsteroid.png",
@@ -28,9 +28,9 @@ const std::vector<const char*> Constants::textureImages{
2828
"turquoiseAsteroid.png"
2929
};
3030
const int Constants::nrOfTextures = 6;
31-
const float Constants::bulletSpeed = 0.1;
31+
const float Constants::bulletSpeed = 0.1f;
3232
const double Constants::bulletSpawnCooldown = 0.1;
3333
const float Constants::bulletRadius = 2.5f;
3434
const int Constants::nrOfBulletsPerFrame = 8;
3535
const int Constants::maxLives = 3;
36-
const double Constants::timeToEscapeAsteroid = 1;
36+
const double Constants::timeToEscapeAsteroid = 1.0;

0 commit comments

Comments
 (0)