2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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.
14 #include "kgamecanvas.h"
16 #include <boost/weak_ptr.hpp>
23 class SpriteExplosion
;
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
{
36 /** the piece id (for convenience) */
39 /** the piece color (for convenience, could be -1) */
42 /** the piece type (for convenience, could be -1) */
47 /** the movement animation class */
48 boost::weak_ptr
<Animation
> m_movement_animation
;
51 /** the step in the explostion */
54 /** the explostion object */
55 SpriteExplosion
* m_explosion
;
57 /** rotation factor */
63 /** creates a new explosion object */
64 SpriteExplosion
* createExplosion(Random
& random
);
66 /** painting implementation */
67 virtual void paint(QPainter
* p
);
69 /** returns the rectangle having to be painted */
70 virtual QRect
rect() const;
74 Sprite(const QPixmap
& pix
, KGameCanvasAbstract
* canvas
, const QPoint
& location
);
77 /** duplicates the piece */
78 Sprite
* duplicate() const;
80 void setThumb(const QImage
& thumb
);
83 /** updates the pixmap */
84 /* NOTE for paolo: why virtual? */
85 virtual void setPixmap(const QPixmap
&);
87 /** set the movement animation */
88 void setMovementAnimation(const boost::shared_ptr
<Animation
>& animation
);
90 /** returns the movement animation */
91 boost::weak_ptr
<Animation
> movementAnimation() const;
93 // void setFadeAnimation(const boost:shared_ptr<FadeAnimation>& animation);
94 // boost:weak_ptr<FadeAnimation> fadeAnimation() const;
96 /** set the explosion step (you have to call setupExplosion before) */
97 void setExplosionStep(float f
);
99 /** set the rotations factor */
100 void setRotation(float f
);
102 /** set the scaling factor */
103 void setScale(float f
);
105 /** prepares a new explosion animation */
106 void setupExplosion(Random
& random
);
110 bool m_dummy_visible
;
112 void update_from_dummy(){
113 KGameCanvasItem::show();
114 KGameCanvasItem::setOpacity(m_dummy_visible
? 64+m_dummy_opacity
*3/8 : 64);
117 /* those should be enough, even if they are not virtual, as Piece is never casted IIRC */
118 int opacity(){ return m_dummy_opacity
; }
119 int visible(){ return m_dummy_visible
; }
120 void setOpacity(int v
){ m_dummy_opacity
=v
; update_from_dummy(); }
121 void setVisible(bool v
){ m_dummy_visible
=v
; update_from_dummy(); }
122 void show(){ m_dummy_visible
=true; update_from_dummy(); }
123 void hide(){ m_dummy_visible
=false; update_from_dummy(); }