diff options
author | gregory guy <gregory-tde@laposte.net> | 2021-04-26 18:43:25 +0200 |
---|---|---|
committer | gregory guy <gregory-tde@laposte.net> | 2021-05-20 20:16:35 +0200 |
commit | 749694a3f2fecddf44633067c24851d8719b181e (patch) | |
tree | 27c58f5c28223c8ae9aa5a01409a5e12ff0c52ca /tdescreensaver/kdesavers/tdeasciiquarium/sprite.cpp | |
parent | b0ef1b76e6bc94f5a8a35b9a43573eab81bca459 (diff) | |
download | tdeartwork-749694a3f2fecddf44633067c24851d8719b181e.tar.gz tdeartwork-749694a3f2fecddf44633067c24851d8719b181e.zip |
asciiquarium: Add cmake build support, app is renamed tdeasciiquarium.
Signed-off-by: gregory guy <gregory-tde@laposte.net>
Diffstat (limited to 'tdescreensaver/kdesavers/tdeasciiquarium/sprite.cpp')
-rw-r--r-- | tdescreensaver/kdesavers/tdeasciiquarium/sprite.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tdescreensaver/kdesavers/tdeasciiquarium/sprite.cpp b/tdescreensaver/kdesavers/tdeasciiquarium/sprite.cpp new file mode 100644 index 00000000..11d7d360 --- /dev/null +++ b/tdescreensaver/kdesavers/tdeasciiquarium/sprite.cpp @@ -0,0 +1,64 @@ +#include "sprite.h" + +Sprite::Sprite(Screen* screen, int x, int y, int z, int frameDelay): + m_screen(screen), m_currentFrame(0), m_x(x), m_y(y), m_z(z), + m_isKilled(false), m_killAfterLastFrame(false), + m_ticksSinceFrameChange(0), m_frameDelay(frameDelay) +{ +} + +void Sprite::addFrame(const Frame& frame) +{ + m_frames.append(frame); +} + +void Sprite::erase() +{ + m_frames[m_currentFrame].erase(m_screen, m_x, m_y); +} + +void Sprite::paint() +{ + m_frames[m_currentFrame].paint(m_screen, m_x, m_y); +} + +bool Sprite::timerTick() +{ + ++m_ticksSinceFrameChange; + if (m_ticksSinceFrameChange * m_screen->msPerTick() < m_frameDelay) + return false; + + //Ring! Ring! + m_ticksSinceFrameChange = 0; + return true; +} + +bool Sprite::tickUpdate() +{ + if (m_frames.size() == 1) + return false; + + if (!timerTick()) + return false; + + erase(); + + ++m_currentFrame; + if (m_currentFrame == m_frames.size()) + { + m_currentFrame = 0; + + if(m_killAfterLastFrame) + { + erase(); + kill(); + } + } + + return true; +} + +TQRect Sprite::geom() const +{ + return TQRect(m_x, m_y, m_frames[0].width(), m_frames[0].height()); +} |