Fix use of singleton pattern.
[tagua/yd.git] / src / sprite.h
blobcc871547eab608302bd3e17eaf0a27a132bfd702
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef SPRITE_H
12 #define SPRITE_H
14 #include "kgamecanvas.h"
15 #include "random.h"
16 #include <boost/weak_ptr.hpp>
17 #include <QPixmap>
19 class QPoint;
20 class QImage;
21 class Animation;
22 class FadeAnimation;
23 class SpriteExplosion;
25 #undef DEBUG_PIECE
27 /**
28 * @class Sprite <sprite.h>
29 * @brief The sprite of a piece.
31 * This class is a KGameCanvasPixmap that enables a few nifty
32 * effects and keeps some piece-related information.
34 class Sprite : public KGameCanvasPixmap {
35 private:
36 QPixmap m_pixmap;
38 /** the movement animation class */
39 boost::weak_ptr<Animation> m_movement_animation;
41 /** the step in the explosion */
42 float m_explode_step;
44 /** the explosion object */
45 SpriteExplosion* m_explosion;
47 /** rotation factor */
48 float m_rotation;
50 /** scaling factor */
51 float m_scale;
53 /** creates a new explosion object */
54 SpriteExplosion* createExplosion(Random& random);
56 /** painting implementation */
57 virtual void paint(QPainter* p);
59 /** returns the rectangle having to be painted */
60 virtual QRect rect() const;
62 public:
63 /** Constructor */
64 Sprite(const QPixmap& pix, KGameCanvasAbstract* canvas, const QPoint& location);
65 virtual ~Sprite();
67 /** duplicates the piece */
68 Sprite* duplicate() const;
70 void setThumb(const QImage& thumb);
71 void removeThumb();
73 /** updates the pixmap */
74 /* NOTE for paolo: why virtual? */
75 virtual void setPixmap(const QPixmap&);
77 /** set the movement animation */
78 void setMovementAnimation(const boost::shared_ptr<Animation>& animation);
80 /** returns the movement animation */
81 boost::weak_ptr<Animation> movementAnimation() const;
83 // void setFadeAnimation(const boost:shared_ptr<FadeAnimation>& animation);
84 // boost:weak_ptr<FadeAnimation> fadeAnimation() const;
86 /** set the explosion step (you have to call setupExplosion before) */
87 void setExplosionStep(float f);
89 /** set the rotations factor */
90 void setRotation(float f);
92 /** set the scaling factor */
93 void setScale(float f);
95 /** prepares a new explosion animation */
96 void setupExplosion(Random& random);
98 #ifdef DEBUG_PIECE
99 int m_dummy_opacity;
100 bool m_dummy_visible;
102 void update_from_dummy(){
103 KGameCanvasItem::show();
104 KGameCanvasItem::setOpacity(m_dummy_visible ? 64+m_dummy_opacity*3/8 : 64);
107 /* those should be enough, even if they are not virtual, as Piece is never casted IIRC */
108 int opacity(){ return m_dummy_opacity; }
109 int visible(){ return m_dummy_visible; }
110 void setOpacity(int v){ m_dummy_opacity=v; update_from_dummy(); }
111 void setVisible(bool v){ m_dummy_visible=v; update_from_dummy(); }
112 void show(){ m_dummy_visible=true; update_from_dummy(); }
113 void hide(){ m_dummy_visible=false; update_from_dummy(); }
114 #endif
117 #endif // SPRITE_H