summaryrefslogtreecommitdiffstats
path: root/kbounce/game.h
blob: 1f66c288c5a9d8d61d111628c16301cfc33c3916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED

#include <tqwidget.h>
#include <tqcanvas.h>
#include <tqmemarray.h>

#if HAVE_ARTS
#include <arts/soundserver.h>

using namespace Arts;
#endif

class TQTimer;
class JezzField;

#define FIELD_WIDTH 32
#define FIELD_HEIGHT 20

class Ball : public QCanvasSprite
{
 public:
    Ball(TQCanvasPixmapArray* array, TQCanvas* canvas);

    void update();
    void advance(int stage);
    bool collide( double dx=0, double dy=0 );

 protected:
    int m_animDelay;
    int m_soundDelay;
};


class Wall : public QObject
{
   Q_OBJECT
public:
   enum Direction { Up, Down, Left, Right };

   Wall( JezzField *field, int x, int y, Direction dir, int tile,
	 TQObject *parent=0, const char *name=0 );

   void finish();
   void fill( bool black );

signals:
   void finished( Wall *wall, int tile );

public slots:
   void advance();
   void update();

private:
   bool isFree( int x, int y );

   Direction m_dir;
   JezzField *m_field;
   int m_dx, m_dy;
   int m_x, m_y;
   int m_startX, m_startY;
   int m_tile;
   int m_delay;
   bool m_active;
};


class JezzField : public QCanvas
{
   Q_OBJECT
public:
   JezzField( const TQPixmap &tiles, const TQPixmap &background, TQObject* parent = 0, const char* name = 0 );

   void setGameTile( int x, int y, bool black );
   void setBackground( const TQPixmap &background );

signals:
   void ballCollision( Ball *ball, int x, int y, int tile );

private:
   friend class Ball;
   bool m_background;
   TQPixmap m_tiles;
   TQMemArray<TQPixmap> m_backTiles;

   void setPixmaps( const TQPixmap &tiles, const TQPixmap &background );
   void emitBallCollisiton( Ball *ball, int x, int y, int tile )
      { emit ballCollision( ball, x, y, tile ); }

};


class JezzView : public QCanvasView
{
  Q_OBJECT
public:
   JezzView(TQCanvas* viewing=0, TQWidget* parent=0, const char* name=0, WFlags f=0);

signals:
   void buildWall( int x, int y, bool vertical );

protected:
   void viewportMouseReleaseEvent( TQMouseEvent * );

private:
   bool m_vertical;
};


class JezzGame : public QWidget
{
   Q_OBJECT

public:
   JezzGame( const TQPixmap &background, int ballNum, TQWidget *parent=0, const char *name=0 );
   ~JezzGame();

   int percent();
   static void playSound( const TQString &name );
   void display( const TQString &text, int size=20 );
   void setBackground( const TQPixmap &background );

signals:
   void died();
   void newPercent( int percent );

public slots:
   void start();
   void stop();
   void setSound( bool sound );

protected slots:
   void tick();
   void buildWall( int x, int y, bool vertical );
   void wallFinished( Wall *wall, int tile );
   void ballCollision( Ball *ball, int x, int y, int tile );

protected:
   void makeBlack();
   void fill( int x, int y );
   void fillLeft( int x, int y );
   int m_buf[FIELD_WIDTH][FIELD_HEIGHT];

   JezzField *m_field;
   JezzView *m_view;

   Wall *m_wall1, *m_wall2;

   TQPtrList<Ball> m_balls;
   TQCanvasPixmapArray *m_ballPixmaps;
   TQCanvasText *m_text;

   TQTimer *m_clock;
   bool m_running;
   int m_percent;
   bool m_pictured;

#if HAVE_ARTS
   static SimpleSoundServer *m_artsServer;
#endif
   static TQString m_soundPath;
   static bool m_sound;
};

#endif