fysxasteroids/engine/Sprite.h

72 lines
1.6 KiB
C++

#ifndef SPRITE_H
#define SPRITE_H
#include <cmath>
namespace Engine {
class Sprite {
public:
Sprite() {
mScale = 1.;
mWidth = 0;
mHeight = 0;
mGlTextureName = 0;
mAnimation = false;
mSubSpriteCount = 1;
}
bool LoadFromPNG (const std::string &filename);
void DrawAt (float xpos, float ypos, float zpos);
void DrawAt2D (float xpos, float ypos);
unsigned int GetWidth() { return mWidth; };
unsigned int GetHeight() { return mHeight; };
void SetScale (float scale) { mScale = scale; };
void SetAnimation (int frame_count, float frame_rate) {
mAnimation = true;
mAnimationFrameCount = frame_count;
mAnimationFrameRate = frame_rate;
mAnimationTimer = 0.;
mWidth = static_cast<unsigned int>(ceil (static_cast<float> (mWidth / mAnimationFrameCount)));
}
void ResetAnimation () {
mAnimationTimer = 0.;
}
void UpdateAnimation (float seconds) {
mAnimationTimer += seconds;
while (mAnimationTimer >= mAnimationFrameCount / mAnimationFrameRate) {
mAnimationTimer -= mAnimationFrameCount / mAnimationFrameRate;
}
}
void SetSubSpriteCount (const unsigned int count) {
mSubSpriteCount = count;
mWidth = static_cast<unsigned int>(ceil (static_cast<float> (mWidth / mSubSpriteCount)));
}
unsigned int GetSubSpriteCount () const {
return mSubSpriteCount;
}
void DrawSubAt (unsigned int index, float xpos, float ypos, float zpos);
private:
float mScale;
unsigned int mWidth;
unsigned int mHeight;
unsigned int mGlTextureName;
unsigned int mSubSpriteCount;
bool mAnimation;
int mAnimationFrameCount;
float mAnimationTimer;
float mAnimationFrameRate;
};
}
#endif /* SPRITE_H */