Back to index

kdeartwork  4.3.2
sprite.h
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 #ifndef AA_SPRITE_H
00029 #define AA_SPRITE_H
00030 
00031 #include <QVector>
00032 
00033 #include "frame.h"
00034 
00048 class Sprite
00049 {
00050 protected:
00051     Screen* m_screen;   
00052     int m_currentFrame; 
00053     int m_x;  
00054     int m_y;  
00055     int m_z;  
00056 
00057     QVector<Frame> m_frames;      
00058     bool m_isKilled;              
00059     bool m_killAfterLastFrame;    
00060     int  m_ticksSinceFrameChange; 
00061     int  m_frameDelay;            
00062 
00069     bool timerTick();
00070 
00071 public:
00082     Sprite(Screen* screen, int x, int y, int z, int frameDelay = 100);
00083 
00088     virtual ~Sprite()
00089     {
00090     }
00091 
00097     virtual bool canCollide() const { return false; }
00098 
00106     virtual void collision (Sprite *sprite)
00107     {
00108         Q_UNUSED(sprite); // Base class does nothing.
00109     }
00110 
00117     void addFrame(const Frame& frame);
00118 
00124     void setFrameDelay(int delay)
00125     {
00126         m_frameDelay = delay;
00127     }
00128 
00136     void setDieAfterLastFrame(bool dieAfterLast)
00137     {
00138         m_killAfterLastFrame = dieAfterLast;
00139     }
00140 
00144     Screen *screen() const
00145     {
00146         return m_screen;
00147     }
00148 
00153     bool isKilled() const
00154     {
00155         return m_isKilled;
00156     }
00157 
00161     int depth() const
00162     {
00163         return m_z;
00164     }
00165 
00170     QRect geom() const;
00171 
00178     void erase();
00179 
00183     void paint();
00184 
00189     virtual void kill()
00190     {
00191         m_isKilled = true;
00192     }
00193 
00194     //main animation hook. Should return true + erase if something changed
00204     virtual bool tickUpdate();
00205 };
00206 
00207 #endif
00208 
00209 // vim: set et ts=8 sw=4: