forked from University/epr24pr42-ojanssen2
big bang v2
This commit is contained in:
parent
d48e9d7b28
commit
27589cc385
18 changed files with 2847 additions and 378 deletions
15
Util/GameState.h
Normal file
15
Util/GameState.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
namespace game
|
||||
{
|
||||
/// Beschreibt den aktuellen GameState
|
||||
enum class GameState
|
||||
{
|
||||
RUNNING,
|
||||
HIT_BY_GHOST,
|
||||
QUITTING,
|
||||
};
|
||||
} // game
|
||||
|
||||
#endif //GAMESTATE_H
|
47
Util/Vector2d.cpp
Normal file
47
Util/Vector2d.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "Vector2d.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
Vector2d::Vector2d(const int x, const int y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
void Vector2d::update(const int& x, const int& y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
void Vector2d::change_x(const int& amount) {
|
||||
this->x += amount;
|
||||
}
|
||||
|
||||
void Vector2d::change_y(const int& amount) {
|
||||
this->y += amount;
|
||||
}
|
||||
|
||||
Vector2d Vector2d::normalize() {
|
||||
Vector2d v = *this;
|
||||
if (v.x < 0)
|
||||
v.x *= -1;
|
||||
if (v.y < 0)
|
||||
v.y *= -1;
|
||||
return v;
|
||||
}
|
||||
|
||||
bool Vector2d::eq(const Vector2d& position) const {
|
||||
return this->x == position.x && this->y == position.y;
|
||||
}
|
||||
|
||||
|
||||
Vector2d Vector2d::get_new_updated(const int& diff_x, const int& diff_y) const {
|
||||
Vector2d new_position = *this;
|
||||
new_position.change_x(diff_x);
|
||||
new_position.change_y(diff_y);
|
||||
|
||||
return new_position;
|
||||
}
|
||||
|
||||
} // game
|
51
Util/Vector2d.h
Normal file
51
Util/Vector2d.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef POSITION_H
|
||||
#define POSITION_H
|
||||
|
||||
namespace game
|
||||
{
|
||||
/// Ein Vector aus zwei zahlen.
|
||||
/// Kann eine Position oder eine Differenz zwischen zwei Positionen darstellen.
|
||||
struct Vector2d
|
||||
{
|
||||
// struct -> members public by default
|
||||
// Die beiden Variablen des Vectors
|
||||
int x;
|
||||
int y;
|
||||
|
||||
/// Ein Vector aus zwei zahlen.
|
||||
/// Kann eine Position oder eine Differenz zwischen zwei Positionen darstellen.
|
||||
/// @param x Die 'X'-Koordinate
|
||||
/// @param y Die 'Y'-Koordinate
|
||||
Vector2d(int x, int y);
|
||||
|
||||
/// Aktualisiere die Werte des Vectors
|
||||
/// @param x Die neue 'X'-Koordinate
|
||||
/// @param y Die neue 'Y'-Koordinate
|
||||
void update(const int& x, const int& y);
|
||||
|
||||
/// Verschiebe den X Wert des Vektors um eine Anzahl
|
||||
/// @param amount Die zu verschiebene Anzahl
|
||||
void change_x(const int& amount);
|
||||
|
||||
/// Verschiebe den Y Wert des Vektors um eine Anzhal
|
||||
/// @param amount Die zu verschiebene Anzahl
|
||||
void change_y(const int& amount);
|
||||
|
||||
/// Kriege einen normalisierten Vektor zurück
|
||||
/// @returns Den aktuellen Vektor als normalisierter Vektor
|
||||
Vector2d normalize();
|
||||
|
||||
/// Kontrolliere, ob ein Vektor einem anderen Enspricht
|
||||
/// @param position Die Position mit der verglichen werden soll
|
||||
/// @returns Ob die Position die gleiche ist
|
||||
bool eq(const Vector2d& position) const;
|
||||
|
||||
/// Kriege einen Vektor, der mit den gegebenen Werten verschoben worden ist
|
||||
/// @param diff_x Die Verschiebung auf der X-Achse
|
||||
/// @param diff_y Die Verschiebung auf der Y-Achse
|
||||
/// @returns Den berrechneten Vektor
|
||||
Vector2d get_new_updated(const int& diff_x, const int& diff_y) const;
|
||||
};
|
||||
} // game
|
||||
|
||||
#endif //POSITION_H
|
Loading…
Add table
Add a link
Reference in a new issue