1/*
2 * Copyright (C) 2000-2005 Stefan Schimanski <1Stein@gmx.de>
3 * Copyright (C) 2007 Tomasz Boczkowski <tboczkowski@onet.pl>
4 *
5 * This file is part of the KDE project "KBounce"
6 *
7 * KBounce is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * KBounce is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with KBounce; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifndef BALL_H
24#define BALL_H
25
26#include <KGameRenderedItem>
27
28#include "gameobject.h"
29
30class KBounceRenderer;
31class KBounceBoard;
32
33/**
34 * KGameRenderedItem representing a ball
35 */
36class KBounceBall : public KGameRenderedItem
37{
38 public:
39 static const int BALL_ANIM_DELAY;
40 static const qreal BALL_RELATIVE_SIZE;
41
42 /**
43 * Constructor
44 */
45 KBounceBall( KBounceRenderer* renderer, KBounceBoard* board );
46 /**
47 * Destructor
48 */
49 ~KBounceBall();
50
51 /**
52 * Changes ball's state when collisions have been detected
53 * Called once per frame before advance()
54 */
55 void collide( const KBounceCollision& collision );
56 /**
57 * Performs move calculations
58 * This method is called once per frame
59 */
60 void goForward();
61 /**
62 * Updates ball position and pixmap.
63 * This method is called once per frame.
64 */
65 void update();
66
67 /*
68 * Returns ball's bounding rect in board coordinate system
69 * @see relativePos()
70 */
71 QRectF ballBoundingRect() const;
72 /*
73 * Returns ball's bounding rect expected in next frame
74 * used by colision test
75 */
76 QRectF nextBoundingRect() const;
77 /**
78 * Returns ball's position in board coordinate system.
79 * Relative board's coordinates are indepentent of actual GameWidget size.
80 */
81 QPointF relativePos();
82 /**
83 * Sets ball's position in board coordinate system.
84 * @see relativePos()
85 */
86 void setRelativePos( qreal x, qreal y );
87 /**
88 * Sets ball's position in board coordinate system
89 */
90 void setVelocity( qreal vX, qreal vY );
91 /**
92 * Returns ball's velocity in board coordinate system
93 */
94 KBounceVector velocity() const;
95
96
97 /**
98 * Sets width and height of ball.
99 */
100 void resize( const QSize& tileSize );
101 /**
102 * Rechecks the number of frames of ball animation and sets new pixmaps.
103 * This method is useful when changing game theme.
104 */
105 void resetPixmaps();
106 /**
107 * Sets a random ball's frame
108 */
109 void setRandomFrame();
110
111 protected:
112 KBounceRenderer* m_renderer;
113 KBounceBoard* m_board;
114 /**
115 * Time after emiting previous sound. If the value is too small,
116 * ball will not emit hit sound.
117 */
118 int m_soundDelay;
119 /**
120 * Size of a ball in GameWidget depentant coordinate system
121 */
122 QSize m_size;
123 /**
124 * Number of frames of ball's animation.
125 */
126 int m_framesNum;
127 qreal m_xPos;
128 qreal m_yPos;
129 KBounceVector m_velocity;
130 bool m_reflectX;
131 bool m_reflectY;
132 QRectF m_nextBoundingRect;
133};
134
135
136#endif
137
138