1 /* 2 This file is part of the KDE project "KBounce" 3 4 SPDX-FileCopyrightText: 2000-2005 Stefan Schimanski <1Stein@gmx.de> 5 SPDX-FileCopyrightText: 2007 Tomasz Boczkowski <tboczkowski@onet.pl> 6 7 SPDX-License-Identifier: LGPL-2.0-or-later 8 */ 9 10 #ifndef BALL_H 11 #define BALL_H 12 13 #include <KGameRenderedItem> 14 15 #include "gameobject.h" 16 17 class KBounceRenderer; 18 class KBounceBoard; 19 20 /** 21 * KGameRenderedItem representing a ball 22 */ 23 class KBounceBall : public KGameRenderedItem 24 { 25 public: 26 static const int BALL_ANIM_DELAY; 27 static const qreal BALL_RELATIVE_SIZE; 28 29 /** 30 * Constructor 31 */ 32 KBounceBall( KBounceRenderer* renderer, KBounceBoard* board ); 33 /** 34 * Destructor 35 */ 36 ~KBounceBall() override; 37 38 /** 39 * Changes ball's state when collisions have been detected 40 * Called once per frame before advance() 41 */ 42 void collide( const KBounceCollision& collision ); 43 /** 44 * Performs move calculations 45 * This method is called once per frame 46 */ 47 void goForward(); 48 /** 49 * Updates ball position and pixmap. 50 * This method is called once per frame. 51 */ 52 void update(); 53 54 /* 55 * Returns ball's bounding rect in board coordinate system 56 * @see relativePos() 57 */ 58 QRectF ballBoundingRect() const; 59 /* 60 * Returns ball's bounding rect expected in next frame 61 * used by colision test 62 */ 63 QRectF nextBoundingRect() const; 64 /** 65 * Returns ball's position in board coordinate system. 66 * Relative board's coordinates are indepentent of actual GameWidget size. 67 */ 68 QPointF relativePos(); 69 /** 70 * Sets ball's position in board coordinate system. 71 * @see relativePos() 72 */ 73 void setRelativePos( qreal x, qreal y ); 74 /** 75 * Sets ball's position in board coordinate system 76 */ 77 void setVelocity( qreal vX, qreal vY ); 78 /** 79 * Returns ball's velocity in board coordinate system 80 */ 81 KBounceVector velocity() const; 82 83 84 /** 85 * Sets width and height of ball. 86 */ 87 void resize( const QSize& tileSize ); 88 /** 89 * Rechecks the number of frames of ball animation and sets new pixmaps. 90 * This method is useful when changing game theme. 91 */ 92 void resetPixmaps(); 93 /** 94 * Sets a random ball's frame 95 */ 96 void setRandomFrame(); 97 98 protected: 99 KBounceRenderer* m_renderer; 100 KBounceBoard* m_board; 101 /** 102 * Time after emiting previous sound. If the value is too small, 103 * ball will not emit hit sound. 104 */ 105 int m_soundDelay; 106 /** 107 * Size of a ball in GameWidget depentant coordinate system 108 */ 109 QSize m_size; 110 /** 111 * Number of frames of ball's animation. 112 */ 113 int m_framesNum; 114 qreal m_xPos; 115 qreal m_yPos; 116 KBounceVector m_velocity; 117 bool m_reflectX; 118 bool m_reflectY; 119 QRectF m_nextBoundingRect; 120 }; 121 122 #endif 123