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.
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
{
38 /** the movement animation class */
39 boost::weak_ptr
<Animation
> m_movement_animation
;
41 /** the step in the explosion */
44 /** the explosion object */
45 SpriteExplosion
* m_explosion
;
47 /** rotation factor */
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;
64 Sprite(const QPixmap
& pix
, KGameCanvasAbstract
* canvas
, const QPoint
& location
);
67 /** duplicates the piece */
68 Sprite
* duplicate() const;
70 void setThumb(const QImage
& thumb
);
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
);
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(); }