Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (3)
#ifndef __COMPONENT__COLLISION_H__
#define __COMPONENT__COLLISION_H__
#include "components/components-generic.h"
#include "maths/maths.h"
class cCollision : public CComponentGeneric
{
public:
double radius = 0.0;
cCollision(){}
cCollision( float rad )
: radius( rad ) {}
};
#endif // __COMPONENT__COLLISION_H__
\ No newline at end of file
#ifndef __COMPONENT__INPUT_H__
#define __COMPONENT__INPUT_H__
#include "components/components-generic.h"
#include "maths/maths.h"
class cInput : public CComponentGeneric
{
public:
bool up = false;
bool down = false;
bool left = false;
bool right = false;
bool shoot = false;
};
#endif // __COMPONENT__INPUT_H__
#ifndef __COMPONENT__POINT_BAR_H__
#define __COMPONENT__POINT_BAR_H__
#include "components/components-generic.h"
#include "maths/maths.h"
class cPointBar : public CComponentGeneric
{
public:
cPointBar( uint16_t value )
: _total(value), _current(value) {}
private:
uint16_t _total;
uint16_t _current;
};
#endif // __COMPONENT__POINT_BAR_H__
#ifndef __COMPONENT__SHAPE_H__
#define __COMPONENT__SHAPE_H__
#include "components/components-generic.h"
#include "maths/maths.h"
class cShape : public CComponentGeneric
{
public:
cShape( uint8_t verticies )
: _verticies( verticies ) {}
private:
uint8_t _verticies;
};
#endif // __COMPONENT__SHAPE_H__
...@@ -7,10 +7,14 @@ ...@@ -7,10 +7,14 @@
class cTransform : public CComponentGeneric class cTransform : public CComponentGeneric
{ {
public: public:
Vec2 position; Vec2 position = { 0.0, 0.0 };
Vec2 velocity; Vec2 velocity = { 0.0, 0.0 };
Vec2 scale; Vec2 scale = { 0.0, 0.0 };
double angle; double angle = 0.0;
cTransform(){}
cTransform( const Vec2 &pos, const Vec2 &vel, float ang )
: position(pos), velocity(vel), angle(ang) {}
}; };
......
...@@ -6,29 +6,34 @@ ...@@ -6,29 +6,34 @@
#include "logger.h" #include "logger.h"
#include "components/cTransform.h" #include "components/cTransform.h"
#include "components/cScore.h" #include "components/cScore.h"
#include "components/cShape.h"
#include "components/cCollision.h"
class Entity class Entity
{ {
// friend class EntityManager; friend class EntityManager;
public: public:
Entity( const std::string& tag, size_t id ); /** @todo make this private */
~Entity(); ~Entity();
bool isAlive() { return this->_alive; } bool isActive() { return this->_active; }
bool isDead() { return ! this->_alive; } bool isDestroyed() { return ! this->_active; }
void kill() { this->_alive = false; } void destroy() { this->_active = false; }
const size_t id() const { return this->_id; }
// Component Variables // Component Variables
const std::string& tag() { return this->_tag; } const std::string& tag() { return this->_tag; }
private: private:
Entity( const std::string& tag, size_t id ); /** @todo make this private */
Logger& _logger; Logger& _logger;
cScore _score; cScore _score;
cTransform _transform; cTransform _transform;
cShape _shape = {0};
cCollision _collision;
bool _active = true;
const size_t _id = 0; const size_t _id = 0;
const std::string _tag = "Default"; const std::string _tag = "Default";
bool _alive = true;
}; };
......
...@@ -46,6 +46,7 @@ class GameEngine ...@@ -46,6 +46,7 @@ class GameEngine
EntityManager _entityManager; EntityManager _entityManager;
Logger& _logger; Logger& _logger;
bool _paused = false;
Window* _window; Window* _window;
std::vector<Asset> _assets; /** @todo : move this to scene */ std::vector<Asset> _assets; /** @todo : move this to scene */
...@@ -54,7 +55,10 @@ class GameEngine ...@@ -54,7 +55,10 @@ class GameEngine
std::map< std::string, Scene* > _scenes; std::map< std::string, Scene* > _scenes;
/* Systems */ /* Systems */
// sUserInput // void sMovement();
// void sUserInput();
// void sRender();
// void sCollision();
}; };
#endif // __GAME_H__ #endif // __GAME_H__
#ifndef UTILS_LOGGER_H #ifndef UTILS_LOGGER_H
#define UTILS_LOGGER_H #define UTILS_LOGGER_H
#include <string> #include <string>
......
...@@ -12,15 +12,23 @@ class Vec2 ...@@ -12,15 +12,23 @@ class Vec2
Vec2( float xIn, float yIn ); Vec2( float xIn, float yIn );
bool operator == ( const Vec2 rhs ) const; bool operator == ( const Vec2 rhs ) const;
bool operator != ( const Vec2 rhs ) const;
Vec2 operator + ( const Vec2 rhs ) const; Vec2 operator + ( const Vec2 rhs ) const;
Vec2 operator * ( const Vec2 rhs ) const;
Vec2 operator - ( const Vec2 rhs ) const; Vec2 operator - ( const Vec2 rhs ) const;
Vec2 operator * ( const Vec2 rhs ) const;
Vec2 operator * ( const float scale ) const; Vec2 operator * ( const float scale ) const;
Vec2 operator / ( const Vec2 rhs ) const;
Vec2 operator / ( const float scale ) const;
void operator += ( const Vec2 & rhs ); void operator += ( const Vec2 & rhs );
void operator -= ( const Vec2 & rhs ); void operator -= ( const Vec2 & rhs );
void operator *= ( const Vec2 & rhs ); void operator *= ( const Vec2 & rhs );
void operator *= ( const float rhs ); void operator *= ( const float rhs );
void operator /= ( const Vec2 & rhs );
void operator /= ( const float rhs );
float dist( const Vec2 &rhs ) const;
float length(); float length();
void normalise(); void normalise();
}; };
......
...@@ -66,7 +66,8 @@ TEST_SRC_OBJ_FILES = $(patsubst $(SRC_DIR)/%.cpp,$(TEST_BUILD_DIR)/%.src.o,$(SRC ...@@ -66,7 +66,8 @@ TEST_SRC_OBJ_FILES = $(patsubst $(SRC_DIR)/%.cpp,$(TEST_BUILD_DIR)/%.src.o,$(SRC
# Output executable # Output executable
TARGET = $(BIN_DIR)/game TARGET = $(BIN_DIR)/game
all: $(TARGET) # all: $(TARGET) $(TEST_TARGET)
all: $(TARGET) test
test: $(TEST_TARGET) test: $(TEST_TARGET)
./$(TEST_TARGET) ./$(TEST_TARGET)
...@@ -95,5 +96,7 @@ clean: ...@@ -95,5 +96,7 @@ clean:
rm -rf ./*~ ./*.swp ./*.gcno rm -rf ./*~ ./*.swp ./*.gcno
rm -rf *~ rm -rf *~
remake: clean $(TARGET)
run: $(TARGET) run: $(TARGET)
./$(TARGET) ./$(TARGET)
...@@ -26,7 +26,7 @@ void EntityManager::update() ...@@ -26,7 +26,7 @@ void EntityManager::update()
{ {
for( auto entity : this->_entities ) for( auto entity : this->_entities )
{ {
if( entity->isDead() ) if( entity->isDestroyed() )
{ {
/** @todo Implement this with a clean deletion taking into account iterator invalidation /** @todo Implement this with a clean deletion taking into account iterator invalidation
*/ */
......
...@@ -6,6 +6,13 @@ Vec2::Vec2( float xIn, float yIn ) ...@@ -6,6 +6,13 @@ Vec2::Vec2( float xIn, float yIn )
: x( xIn ), y( yIn ) : x( xIn ), y( yIn )
{}; {};
bool Vec2::operator != ( const Vec2 rhs ) const {
return !(
abs( this->x - rhs.x ) < 0.01
) && (
abs( this->y - rhs.y ) < 0.01
);
}
bool Vec2::operator == ( const Vec2 rhs ) const { bool Vec2::operator == ( const Vec2 rhs ) const {
return ( return (
abs( this->x - rhs.x ) < 0.01 abs( this->x - rhs.x ) < 0.01
...@@ -16,12 +23,22 @@ bool Vec2::operator == ( const Vec2 rhs ) const { ...@@ -16,12 +23,22 @@ bool Vec2::operator == ( const Vec2 rhs ) const {
Vec2 Vec2::operator + ( const Vec2 rhs ) const { return Vec2( this->x + rhs.x, this->y + rhs.y ); } Vec2 Vec2::operator + ( const Vec2 rhs ) const { return Vec2( this->x + rhs.x, this->y + rhs.y ); }
Vec2 Vec2::operator - ( const Vec2 rhs ) const { return Vec2( this->x - rhs.x, this->y - rhs.y ); } Vec2 Vec2::operator - ( const Vec2 rhs ) const { return Vec2( this->x - rhs.x, this->y - rhs.y ); }
Vec2 Vec2::operator * ( const Vec2 rhs ) const { return Vec2( this->x * rhs.x, this->y * rhs.y ); } Vec2 Vec2::operator * ( const Vec2 rhs ) const { return Vec2( this->x * rhs.x, this->y * rhs.y ); }
Vec2 Vec2::operator / ( const Vec2 rhs ) const { return Vec2( this->x / rhs.x, this->y / rhs.y ); }
Vec2 Vec2::operator * ( const float scale ) const { return Vec2( this->x * scale, this->y * scale ); } Vec2 Vec2::operator * ( const float scale ) const { return Vec2( this->x * scale, this->y * scale ); }
Vec2 Vec2::operator / ( const float scale ) const { return Vec2( this->x / scale, this->y / scale ); }
void Vec2::operator += ( const Vec2 & rhs ) { this->x += rhs.x; this->y += rhs.y; } void Vec2::operator += ( const Vec2 & rhs ) { this->x += rhs.x; this->y += rhs.y; }
void Vec2::operator -= ( const Vec2 & rhs ) { this->x -= rhs.x; this->y -= rhs.y; } void Vec2::operator -= ( const Vec2 & rhs ) { this->x -= rhs.x; this->y -= rhs.y; }
void Vec2::operator *= ( const Vec2 & rhs ) { this->x *= rhs.x; this->y *= rhs.y; } void Vec2::operator *= ( const Vec2 & rhs ) { this->x *= rhs.x; this->y *= rhs.y; }
void Vec2::operator *= ( const float scale ) { this->x *= scale; this->y *= scale; } void Vec2::operator *= ( const float scale ) { this->x *= scale; this->y *= scale; }
void Vec2::operator /= ( const Vec2 & rhs ) { this->x /= rhs.x; this->y /= rhs.y; }
void Vec2::operator /= ( const float scale ) { this->x /= scale; this->y /= scale; }
float Vec2::dist( const Vec2 &rhs ) const
{
float x = this->x - rhs.x;
float y = this->y - rhs.y;
return sqrtf( x*x + y*y );
}
float Vec2::length() float Vec2::length()
{ return sqrtf( this->x*this->x + this->y*this->y ); } { return sqrtf( this->x*this->x + this->y*this->y ); }
void Vec2::normalise() void Vec2::normalise()
......
...@@ -5,8 +5,13 @@ ...@@ -5,8 +5,13 @@
#include "maths/vec2.h" #include "maths/vec2.h"
TEST_CASE( "Testing Operator Comparisons" ) { TEST_CASE( "Testing Operator Comparisons" ) {
float epsilon = 1e-10;
Vec2 a( 1, 5 ); Vec2 a( 1, 5 );
Vec2 b( 2, 4 ); Vec2 b( 2, 4 );
float scale_a = 100;
float scale_b = 0.5;
float scale_c = 0;
SUBCASE( "Addition" ) SUBCASE( "Addition" )
{ {
...@@ -14,10 +19,36 @@ TEST_CASE( "Testing Operator Comparisons" ) { ...@@ -14,10 +19,36 @@ TEST_CASE( "Testing Operator Comparisons" ) {
CHECK( c.x == 3 ); CHECK( c.x == 3 );
CHECK( c.y == 9 ); CHECK( c.y == 9 );
} }
SUBCASE( "Multiplication" )
{
Vec2 c = a * b;
CHECK( c.x == 2 );
CHECK( c.y == 20 );
Vec2 d = c * c;
CHECK( d.x == 4 );
CHECK( d.y == 400 );
}
SUBCASE( "Division" )
{
Vec2 c = a / b;
Vec2 d = b / a;
CHECK( abs( c.x - (1.0 / 2.0) ) < epsilon );
CHECK( abs( c.y - (5.0 / 4.0) ) < epsilon );
CHECK( abs( d.x - (2.0) ) < epsilon );
CHECK( abs( d.y - (4.0 / 5.0) ) < epsilon );
}
SUBCASE( "Subtraction" ) SUBCASE( "Subtraction" )
{ {
Vec2 c = a - b; Vec2 c = a - b;
CHECK( c.x == -1 ); CHECK( c.x == -1 );
CHECK( c.y == 1 ); CHECK( c.y == 1 );
} }
} SUBCASE( "Division" )
{
Vec2 c = a * scale_c;
CHECK( c.x == 0.0 );
CHECK( c.y == 0.0 );
}
}
\ No newline at end of file