1/*
2 * Copyright (C) 2000-2005 Stefan Schimanski <1Stein@gmx.de>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free
16 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef BOARD_H
20#define BOARD_H
21
22#include <QObject>
23#include <QGraphicsItemGroup>
24
25#include <QList>
26#include <QSize>
27
28#include "gameobject.h"
29#include "renderer.h"
30
31#define TILE_NUM_H 20
32#define TILE_NUM_W 32
33
34
35class KBounceBall;
36class KBounceWall;
37
38class KBounceBoard: public QGraphicsObject
39{
40 Q_OBJECT
41
42 public:
43 enum TileType{ Empty, Free, Border, Wall, Temp };
44
45 explicit KBounceBoard( KBounceRenderer *renderer );
46 ~KBounceBoard();
47
48 QPixmap applyWallsOn(QPixmap background) const;
49 void resize( QSize& size );
50 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
51
52 void newLevel( int level );
53 void setPaused( bool );
54
55 void buildWall( const QPointF& pos, bool vertical );
56
57 int balls();
58 int filled();
59
60 KBounceCollision checkCollision( void* object, const QRectF& rect, int type );
61 KBounceCollision checkCollisionTiles( const QRectF& rect );
62 void checkCollisions();
63
64 QPoint mapPosition( const QPointF& pos ) const;
65 QRectF boundingRect() const;
66
67 void setBallVelocity(qreal velocity);
68 void setWallVelocity(qreal velocity);
69 signals:
70 void ballsChanged( int balls );
71 void fillChanged( int fill );
72 void wallDied();
73
74 protected slots:
75 void tick();
76 void wallFinished( int x1, int y1, int x2, int y2 );
77
78 private:
79 void clear();
80 void fill( int x, int y );
81
82 KBounceRenderer* m_renderer;
83
84 TileType m_tiles[TILE_NUM_W][TILE_NUM_H];
85 QSize m_tileSize;
86 int m_filled;
87
88 QList<KBounceBall*> m_balls;
89 QList<KBounceWall*> m_walls;
90
91 QTimer* m_clock;
92
93
94 qreal m_ballVelocity;
95 qreal m_wallVelocity;
96};
97
98#endif // BOARD_H
99
100