SDLPP: RenderObject - use Vec2D
This commit is contained in:
parent
6ecdb6d90d
commit
8540573455
@ -2,6 +2,7 @@
|
||||
#include <cmath>
|
||||
|
||||
namespace SDLPP {
|
||||
/* wheter to use entire texture rather than just a part of it */
|
||||
bool RenderObject::entireTexture() {
|
||||
return src_rect.x == -1 || src_rect.y == -1 || src_rect.w == -1 ||
|
||||
src_rect.h == -1;
|
||||
@ -28,14 +29,14 @@ void RenderObject::render() {
|
||||
}
|
||||
}
|
||||
void RenderObject::setPos( double x, double y ) {
|
||||
original = { x, y };
|
||||
updateSizeAndPosition();
|
||||
setPos( Vec2D< double >( x, y ) );
|
||||
}
|
||||
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 ) {
|
||||
setPos( vec.getX(), vec.getY() );
|
||||
original = vec;
|
||||
updateSizeAndPosition();
|
||||
}
|
||||
Vec2D< double > RenderObject::getPos() const {
|
||||
return original;
|
||||
@ -99,14 +100,13 @@ void RenderObject::setMovementSpeed( double speed ) {
|
||||
movementSpeed = speed;
|
||||
}
|
||||
void RenderObject::addMovement( int x, int y ) {
|
||||
movementDirection.first += x;
|
||||
movementDirection.second += y;
|
||||
movementDirection += { x, y };
|
||||
}
|
||||
void RenderObject::resetMovementX() {
|
||||
movementDirection.first = 0;
|
||||
movementDirection = { 0, movementDirection.getY() };
|
||||
}
|
||||
void RenderObject::resetMovementY() {
|
||||
movementDirection.second = 0;
|
||||
movementDirection = { movementDirection.getX(), 0 };
|
||||
}
|
||||
void RenderObject::clearColided() {
|
||||
colidedWith.clear();
|
||||
@ -155,10 +155,10 @@ void RenderObject::move( int ticks ) {
|
||||
if ( permanent )
|
||||
return;
|
||||
auto addx =
|
||||
static_cast< double >( movementSpeed * movementDirection.first ) *
|
||||
static_cast< double >( movementSpeed * movementDirection.getX() ) *
|
||||
( static_cast< double >( ticks ) / 1000 );
|
||||
auto addy =
|
||||
static_cast< double >( movementSpeed * movementDirection.second ) *
|
||||
static_cast< double >( movementSpeed * movementDirection.getY() ) *
|
||||
( static_cast< double >( ticks ) / 1000 );
|
||||
if ( std::isnan( addx ) || std::isnan( addy ) )
|
||||
return;
|
||||
|
@ -109,7 +109,7 @@ protected:
|
||||
std::shared_ptr< Renderer > renderer;
|
||||
std::shared_ptr< CollisionPolygon > polygon;
|
||||
double movementSpeed = 0;
|
||||
std::pair< int, int > movementDirection = { 0, 0 };
|
||||
Vec2D< int > movementDirection = { 0, 0 };
|
||||
std::vector< std::shared_ptr< RenderObject > > colidedWith;
|
||||
uint64_t id = -1;
|
||||
bool hidden = false;
|
||||
|
Loading…
Reference in New Issue
Block a user