Skip to content

Commit aac2de4

Browse files
committed
Merge master into current branch.
2 parents 31e9643 + dd19793 commit aac2de4

File tree

14 files changed

+409
-103
lines changed

14 files changed

+409
-103
lines changed

OpenRocket/OpenRocket/Asteroid.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,64 @@
11
#include "Asteroid.h"
22
#include "Constants.h"
33

4-
glm::vec4 Asteroid::circlePoint = glm::vec4(0.0f);
5-
glm::vec4 Asteroid::circleCenter = glm::vec4(0.0f);
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 };
66

77
Asteroid::Asteroid(float radius = 40.0f, int nrOfVertices = 16, glm::vec4 coordinates = glm::vec4(0.0f,0.0f, 0.0f, 0.0f),
8-
glm::vec4 colors = glm::vec4(0.0f, 0.0f,0.0f,0.0f)) : radius(radius), nrOfVertices(nrOfVertices), coordinates(coordinates), colors(colors), translatedDistance(0), currentZone(Constants::SAFE) {
8+
glm::vec4 colors = glm::vec4(0.0f, 0.0f,0.0f,0.0f)) :
9+
radius(radius),
10+
nrOfVertices(nrOfVertices),
11+
coordinates(coordinates),
12+
colors(colors),
13+
translatedDistance(0),
14+
currentZone(Constants::SAFE) {
915
textureIndex = rand() % Constants::nrOfTextures;
1016
};
17+
1118
bool Asteroid::isInViewport() {
1219
return this->coordinates.y - this->translatedDistance < Constants::height && !this->belowViewport();
1320
}
21+
1422
bool Asteroid::belowViewport() {
1523
return this->coordinates.y - this->translatedDistance < - this->radius;
1624
}
25+
1726
bool Asteroid::inLowerHalf() {
1827
return !this->belowViewport() && this->isInViewport() && this->getRealY() < Constants::height;
1928
}
29+
2030
string Asteroid::getCurrentZone() {
2131
return this->currentZone;
2232
}
33+
2334
void Asteroid::setCurrentZone(string newZone) {
2435
this->currentZone = newZone;
2536
}
37+
2638
void Asteroid::updateState() {
2739
if (Asteroid::inLowerHalf()) {
2840
Asteroid::setCurrentZone(Constants::RED);
2941
}
3042
}
43+
44+
float Asteroid::getX() {
45+
return this->coordinates.x;
46+
}
47+
48+
float Asteroid::getRealY() {
49+
return this->coordinates.y - this->translatedDistance;
50+
}
51+
52+
void Asteroid::setX(float newXOffset) {
53+
this->coordinates.x = newXOffset;
54+
}
55+
56+
void Asteroid::setY(float newYOffset) {
57+
this->coordinates.y = newYOffset;
58+
}
3159
int Asteroid::getTextureIndex() {
3260
return this->textureIndex;
3361
}
34-
float Asteroid::getX() { return this->coordinates.x; }
35-
float Asteroid::getRealY() { return this->coordinates.y - this->translatedDistance; }
36-
void Asteroid::setX(float newXOffset) { this->coordinates.x = newXOffset; }
37-
void Asteroid::setY(float newYOffset) { this->coordinates.y = newYOffset; }
3862
float Asteroid::getTranslatedDistance() { return this->translatedDistance; }
3963
void Asteroid::setTranslatedDistance(float distance) { this->translatedDistance = distance; }
4064
float Asteroid::getRadius() { return this->radius; }

OpenRocket/OpenRocket/Bullet.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Bullet.h"
2+
#include "Constants.h"
3+
#include <iostream>
4+
5+
Bullet::Bullet(float radius, float posX, float posY) :
6+
radius(radius),
7+
x(posX),
8+
y(posY),
9+
translatedDistance(0)
10+
{
11+
12+
}
13+
14+
bool Bullet::aboveViewport() {
15+
return this->y > Constants::height;
16+
}

OpenRocket/OpenRocket/Bullet.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
class Bullet {
4+
private:
5+
float radius;
6+
float translatedDistance;
7+
float x;
8+
float y;
9+
10+
public:
11+
Bullet(float radius, float posX, float posY);
12+
~Bullet();
13+
14+
float getRadius() const {
15+
return radius;
16+
}
17+
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+
}
41+
42+
bool aboveViewport();
43+
44+
};

OpenRocket/OpenRocket/Constants.cpp

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

3-
const char* Constants::title = "Open rocket";
3+
const char* Constants::title = "Open Rocket";
44
const float Constants::PI = 3.141592;
55
const int Constants::width = 800;
66
const int Constants::height = 450;
7-
const int Constants::nrOfStars = 2000;
7+
const int Constants::nrOfStars = 1000;
88
const int Constants::maxX = 1600;
99
const int Constants::maxY = 900;
1010
const int Constants::nrOfAsteroids = 20;
@@ -27,4 +27,8 @@ const std::vector<const char*> Constants::textureImages{
2727
"orangeAsteroid.png",
2828
"turquoiseAsteroid.png"
2929
};
30-
const int Constants::nrOfTextures = 6;
30+
const int Constants::nrOfTextures = 6;
31+
const float Constants::bulletSpeed = 0.1;
32+
const double Constants::bulletSpawnCooldown = 0.1;
33+
const float Constants::bulletRadius = 2.5f;
34+
const int Constants::nrOfBulletsPerFrame = 8;

OpenRocket/OpenRocket/Constants.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ class Constants
2626
static const std::string SAFE;
2727
static const std::vector<const char*> textureImages;
2828
static const int nrOfTextures;
29+
static const float bulletSpeed;
30+
static const double bulletSpawnCooldown;
31+
static const float bulletRadius;
32+
static const int nrOfBulletsPerFrame;
2933
};

0 commit comments

Comments
 (0)