Removed AlgebraicNotation from the variant API.
[tagua/yd.git] / src / sprite.h
blobeba6af78c40fa6fed96e9e057f01c0feb95d1106
1 /*
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.
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 /** the piece id (for convenience) */
37 int m_id;
39 /** the piece color (for convenience, could be -1) */
40 int m_color;
42 /** the piece type (for convenience, could be -1) */
43 int m_type;
45 QPixmap m_pixmap;
47 /** the movement animation class */
48 boost::weak_ptr<Animation> m_movement_animation;
51 /** the step in the explostion */
52 float m_explode_step;
54 /** the explostion object */
55 SpriteExplosion* m_explosion;
57 /** rotation factor */
58 float m_rotation;
60 /** scaling factor */
61 float m_scale;
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;
72 public:
73 /** Constructor */
74 Sprite(const QPixmap& pix, KGameCanvasAbstract* canvas, const QPoint& location);
75 virtual ~Sprite();
77 /** duplicates the piece */
78 Sprite* duplicate() const;
80 void setThumb(const QImage& thumb);
81 void removeThumb();
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);
108 #ifdef DEBUG_PIECE
109 int m_dummy_opacity;
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(); }
124 #endif
127 #endif // SPRITE_H