forked from jaildesigner-jailgames/coffee_crisis
release v1.3 beta 1
This commit is contained in:
132
source/movingsprite.cpp
Normal file
132
source/movingsprite.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include "const.h"
|
||||
#include "movingsprite.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite()
|
||||
{
|
||||
init(0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
MovingSprite::~MovingSprite()
|
||||
{
|
||||
init(0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Iniciador
|
||||
void MovingSprite::init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece el alto y el ancho del sprite
|
||||
setWidth(w);
|
||||
setHeight(h);
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
setPosX(x);
|
||||
setPosY(y);
|
||||
|
||||
// Establece la velocidad X,Y del sprite
|
||||
setVelX(velx);
|
||||
setVelY(vely);
|
||||
|
||||
// Establece la aceleración X,Y del sprite
|
||||
setAccelX(accelx);
|
||||
setAccelY(accely);
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
setTexture(texture);
|
||||
|
||||
// Establece el renderizador
|
||||
setRenderer(renderer);
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(0, 0, w, h);
|
||||
}
|
||||
|
||||
// Mueve el sprite
|
||||
void MovingSprite::move()
|
||||
{
|
||||
mPosX += mVelX;
|
||||
mPosY += mVelY;
|
||||
|
||||
mVelX += mAccelX;
|
||||
mVelY += mAccelY;
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render()
|
||||
{
|
||||
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
float MovingSprite::getPosX()
|
||||
{
|
||||
return mPosX;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
float MovingSprite::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
float MovingSprite::getVelX()
|
||||
{
|
||||
return mVelX;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
float MovingSprite::getVelY()
|
||||
{
|
||||
return mVelY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
float MovingSprite::getAccelX()
|
||||
{
|
||||
return mAccelX;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
float MovingSprite::getAccelY()
|
||||
{
|
||||
return mAccelY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float x)
|
||||
{
|
||||
mPosX = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosY(float y)
|
||||
{
|
||||
mPosY = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelX(float x)
|
||||
{
|
||||
mVelX = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelY(float y)
|
||||
{
|
||||
mVelY = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelX(float x)
|
||||
{
|
||||
mAccelX = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelY(float y)
|
||||
{
|
||||
mAccelY = y;
|
||||
}
|
||||
Reference in New Issue
Block a user