SDLPP: RenderObject - use Vec2D

This commit is contained in:
zvon 2021-03-15 14:43:56 +01:00
parent 6ecdb6d90d
commit 8540573455
2 changed files with 11 additions and 11 deletions

View File

@ -2,6 +2,7 @@
#include <cmath> #include <cmath>
namespace SDLPP { namespace SDLPP {
/* wheter to use entire texture rather than just a part of it */
bool RenderObject::entireTexture() { bool RenderObject::entireTexture() {
return src_rect.x == -1 || src_rect.y == -1 || src_rect.w == -1 || return src_rect.x == -1 || src_rect.y == -1 || src_rect.w == -1 ||
src_rect.h == -1; src_rect.h == -1;
@ -28,14 +29,14 @@ void RenderObject::render() {
} }
} }
void RenderObject::setPos( double x, double y ) { void RenderObject::setPos( double x, double y ) {
original = { x, y }; setPos( Vec2D< double >( x, y ) );
updateSizeAndPosition();
} }
void RenderObject::setPos( const std::pair< double, double > &pos ) { void RenderObject::setPos( const std::pair< double, double > &pos ) {
setPos( pos.first, pos.second ); setPos( Vec2D< double >( pos.first, pos.second ) );
} }
void RenderObject::setPos( const Vec2D< double > &vec ) { void RenderObject::setPos( const Vec2D< double > &vec ) {
setPos( vec.getX(), vec.getY() ); original = vec;
updateSizeAndPosition();
} }
Vec2D< double > RenderObject::getPos() const { Vec2D< double > RenderObject::getPos() const {
return original; return original;
@ -99,14 +100,13 @@ void RenderObject::setMovementSpeed( double speed ) {
movementSpeed = speed; movementSpeed = speed;
} }
void RenderObject::addMovement( int x, int y ) { void RenderObject::addMovement( int x, int y ) {
movementDirection.first += x; movementDirection += { x, y };
movementDirection.second += y;
} }
void RenderObject::resetMovementX() { void RenderObject::resetMovementX() {
movementDirection.first = 0; movementDirection = { 0, movementDirection.getY() };
} }
void RenderObject::resetMovementY() { void RenderObject::resetMovementY() {
movementDirection.second = 0; movementDirection = { movementDirection.getX(), 0 };
} }
void RenderObject::clearColided() { void RenderObject::clearColided() {
colidedWith.clear(); colidedWith.clear();
@ -155,10 +155,10 @@ void RenderObject::move( int ticks ) {
if ( permanent ) if ( permanent )
return; return;
auto addx = auto addx =
static_cast< double >( movementSpeed * movementDirection.first ) * static_cast< double >( movementSpeed * movementDirection.getX() ) *
( static_cast< double >( ticks ) / 1000 ); ( static_cast< double >( ticks ) / 1000 );
auto addy = auto addy =
static_cast< double >( movementSpeed * movementDirection.second ) * static_cast< double >( movementSpeed * movementDirection.getY() ) *
( static_cast< double >( ticks ) / 1000 ); ( static_cast< double >( ticks ) / 1000 );
if ( std::isnan( addx ) || std::isnan( addy ) ) if ( std::isnan( addx ) || std::isnan( addy ) )
return; return;

View File

@ -109,7 +109,7 @@ protected:
std::shared_ptr< Renderer > renderer; std::shared_ptr< Renderer > renderer;
std::shared_ptr< CollisionPolygon > polygon; std::shared_ptr< CollisionPolygon > polygon;
double movementSpeed = 0; double movementSpeed = 0;
std::pair< int, int > movementDirection = { 0, 0 }; Vec2D< int > movementDirection = { 0, 0 };
std::vector< std::shared_ptr< RenderObject > > colidedWith; std::vector< std::shared_ptr< RenderObject > > colidedWith;
uint64_t id = -1; uint64_t id = -1;
bool hidden = false; bool hidden = false;