File indexing completed on 2024-04-28 04:02:02

0001 /*
0002     SPDX-FileCopyrightText: 2000-2005 Stefan Schimanski <1Stein@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef BOARD_H
0008 #define BOARD_H
0009 
0010 #include <QGraphicsItemGroup>
0011 
0012 #include <QList>
0013 #include <QSize>
0014 
0015 #include "gameobject.h"
0016 #include "renderer.h"
0017 
0018 #define TILE_NUM_H 20
0019 #define TILE_NUM_W 32
0020 
0021 
0022 class KBounceBall;
0023 class KBounceWall;
0024 
0025 class KBounceBoard: public QGraphicsObject
0026 {
0027     Q_OBJECT
0028 
0029     public:
0030         enum TileType{ Empty, Free, Border, Wall, Temp };
0031 
0032         explicit KBounceBoard( KBounceRenderer *renderer );
0033         ~KBounceBoard() override;
0034 
0035         QPixmap applyWallsOn(const QPixmap &background) const;
0036         void resize( QSize& size );
0037         void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {}
0038 
0039         void newLevel( int level );
0040         void setPaused( bool );
0041 
0042         void buildWall( const QPointF& pos, bool vertical );
0043 
0044         int balls();
0045         int filled();
0046 
0047         KBounceCollision checkCollision( void* object, const QRectF& rect, int type );
0048         KBounceCollision checkCollisionTiles( const QRectF& rect );
0049         void checkCollisions();
0050 
0051         QPoint mapPosition( const QPointF& pos ) const;
0052         QRectF boundingRect() const override;
0053 
0054         void setBallVelocity(qreal velocity);
0055         void setWallVelocity(qreal velocity);
0056     Q_SIGNALS:
0057         void ballsChanged( int balls );
0058         void fillChanged( int fill );
0059         void wallDied();
0060 
0061     protected Q_SLOTS:
0062         void tick();
0063         void wallFinished( int x1, int y1, int x2, int y2 );
0064 
0065     private:
0066         void clear();
0067         void fill( int x, int y );
0068 
0069         KBounceRenderer* m_renderer;
0070 
0071         TileType m_tiles[TILE_NUM_W][TILE_NUM_H];
0072         QSize m_tileSize;
0073         int m_filled;
0074 
0075         QList<KBounceBall*> m_balls;
0076         QList<KBounceWall*> m_walls;
0077 
0078         QTimer* m_clock;
0079 
0080 
0081         qreal m_ballVelocity;
0082         qreal m_wallVelocity;
0083 };
0084 
0085 #endif // BOARD_H