Back to index

kdeartwork  4.3.2
sprite.cpp
Go to the documentation of this file.
00001 /*
00002  * Asciiquarium - Native KDE Screensaver based on the Asciiquarium program
00003  *    (c) Kirk Baucom <kbaucom@schizoid.com>, which you can find at
00004  *    http://www.robobunny.com/projects/asciiquarium/
00005  *
00006  * Ported to KDE by Maksim Orlovich <maksim@kde.org> and
00007  * Michael Pyne <michael.pyne@kdemail.net>.
00008  *
00009  * Copyright (c) 2003 Kirk Baucom     <kbaucom@schizoid.com>
00010  * Copyright (c) 2005 Maksim Orlovich <maksim@kde.org>
00011  * Copyright (c) 2005, 2008 Michael Pyne <michael.pyne@kdemail.net>
00012  *
00013  * This program is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU General Public License
00015  * as published by the Free Software Foundation; either version 2
00016  * of the License, or (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License along with
00024  * this program; if not, write to the Free Software Foundation, Inc., 51
00025  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00026  */
00027 
00028 #include "sprite.h"
00029 
00030 #include <QtCore/QRect>
00031 
00032 Sprite::Sprite(Screen* screen, int x, int y, int z, int frameDelay):
00033     m_screen(screen), m_currentFrame(0), m_x(x), m_y(y), m_z(z),
00034     m_isKilled(false), m_killAfterLastFrame(false),
00035     m_ticksSinceFrameChange(0), m_frameDelay(frameDelay)
00036 {
00037 }
00038 
00039 void Sprite::addFrame(const Frame& frame)
00040 {
00041     m_frames.append(frame);
00042 }
00043 
00044 void Sprite::erase()
00045 {
00046     m_frames[m_currentFrame].erase(m_screen, m_x, m_y);
00047 }
00048 
00049 void Sprite::paint()
00050 {
00051     m_frames[m_currentFrame].paint(m_screen, m_x, m_y);
00052 }
00053 
00054 bool Sprite::timerTick()
00055 {
00056     ++m_ticksSinceFrameChange;
00057     if (m_ticksSinceFrameChange * m_screen->msPerTick() < m_frameDelay)
00058         return false;
00059 
00060     //Ring! Ring!
00061     m_ticksSinceFrameChange = 0;
00062     return true;
00063 }
00064 
00065 bool Sprite::tickUpdate()
00066 {
00067     if (m_frames.size() == 1)
00068         return false;
00069 
00070     if (!timerTick())
00071         return false;
00072 
00073     erase();
00074 
00075     ++m_currentFrame;
00076     if (m_currentFrame == m_frames.size())
00077     {
00078         m_currentFrame = 0;
00079 
00080         if(m_killAfterLastFrame)
00081         {
00082             erase();
00083             kill();
00084         }
00085     }
00086 
00087     return true;
00088 }
00089 
00090 QRect Sprite::geom() const
00091 {
00092     return QRect(m_x, m_y, m_frames[0].width(), m_frames[0].height());
00093 }
00094 
00095 
00096 // vim: set et ts=8 sw=4: