author | imm <imm> | 2002-08-31 22:42:59 (UTC) |
---|---|---|
committer | imm <imm> | 2002-08-31 22:42:59 (UTC) |
commit | 754ba2082e46197a5b5c7b0885f36ed42785631a (patch) (unidiff) | |
tree | 64bbcccb27725f84fad86f0b25ceb1eba5d47e46 | |
parent | 89587f7c6ae60715644d06a60c16bc5c88075e29 (diff) | |
download | opie-754ba2082e46197a5b5c7b0885f36ed42785631a.zip opie-754ba2082e46197a5b5c7b0885f36ed42785631a.tar.gz opie-754ba2082e46197a5b5c7b0885f36ed42785631a.tar.bz2 |
zbounce -> bounce
-rw-r--r-- | noncore/games/bounce/bounce.pro | 26 | ||||
-rw-r--r-- | noncore/games/bounce/game.cpp (renamed from noncore/games/zbounce/game.cpp) | 2 | ||||
-rw-r--r-- | noncore/games/bounce/game.h (renamed from noncore/games/zbounce/game.h) | 0 | ||||
-rw-r--r-- | noncore/games/bounce/kbounce.cpp | 4 | ||||
-rw-r--r-- | noncore/games/bounce/kbounce.h (renamed from noncore/games/zbounce/kbounce.h) | 0 | ||||
-rw-r--r-- | noncore/games/bounce/main.cpp (renamed from noncore/games/zbounce/main.cpp) | 0 | ||||
-rw-r--r-- | noncore/games/bounce/opie-bounce.control | 20 | ||||
-rw-r--r-- | noncore/games/zbounce/kbounce.cpp | 302 | ||||
-rw-r--r-- | noncore/games/zbounce/opie-zbounce.control | 20 | ||||
-rw-r--r-- | noncore/games/zbounce/zbounce.pro | 26 |
10 files changed, 49 insertions, 351 deletions
diff --git a/noncore/games/bounce/bounce.pro b/noncore/games/bounce/bounce.pro new file mode 100644 index 0000000..7be1fb5 --- a/dev/null +++ b/noncore/games/bounce/bounce.pro | |||
@@ -0,0 +1,26 @@ | |||
1 | TEMPLATE= app | ||
2 | #CONFIG = qt warn_on debug | ||
3 | CONFIG = qt warn_on release | ||
4 | HEADERS = game.h kbounce.h | ||
5 | SOURCES = game.cpp kbounce.cpp main.cpp | ||
6 | INCLUDEPATH+= $(OPIEDIR)/include | ||
7 | DEPENDPATH+= $(OPIEDIR)/include | ||
8 | LIBS += -lqpe | ||
9 | DESTDIR = $(OPIEDIR)/bin | ||
10 | TARGET = bounce | ||
11 | |||
12 | TRANSLATIONS = ../../../i18n/de/bounce.ts \ | ||
13 | ../../../i18n/en/bounce.ts \ | ||
14 | ../../../i18n/es/bounce.ts \ | ||
15 | ../../../i18n/fr/bounce.ts \ | ||
16 | ../../../i18n/hu/bounce.ts \ | ||
17 | ../../../i18n/ja/bounce.ts \ | ||
18 | ../../../i18n/ko/bounce.ts \ | ||
19 | ../../../i18n/no/bounce.ts \ | ||
20 | ../../../i18n/pl/bounce.ts \ | ||
21 | ../../../i18n/pt/bounce.ts \ | ||
22 | ../../../i18n/pt_BR/bounce.ts \ | ||
23 | ../../../i18n/sl/bounce.ts \ | ||
24 | ../../../i18n/zh_CN/bounce.ts \ | ||
25 | ../../../i18n/zh_TW/bounce.ts \ | ||
26 | ../../../i18n/it/bounce.ts | ||
diff --git a/noncore/games/zbounce/game.cpp b/noncore/games/bounce/game.cpp index 7a1a3cd..6ded218 100644 --- a/noncore/games/zbounce/game.cpp +++ b/noncore/games/bounce/game.cpp | |||
@@ -1,606 +1,606 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. | 7 | * version 2 of the License, or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 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 | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | 19 | ||
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <qtimer.h> | 21 | #include <qtimer.h> |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qimage.h> | 23 | #include <qimage.h> |
24 | 24 | ||
25 | #include "game.h" | 25 | #include "game.h" |
26 | 26 | ||
27 | #define TILE_SIZE 9 | 27 | #define TILE_SIZE 9 |
28 | 28 | ||
29 | #define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2)) | 29 | #define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2)) |
30 | #define TILE_FREE (TILE_FIRST + 0) | 30 | #define TILE_FREE (TILE_FIRST + 0) |
31 | #define TILE_BORDER (TILE_FIRST + 1) | 31 | #define TILE_BORDER (TILE_FIRST + 1) |
32 | #define TILE_WALLEND (TILE_FIRST + 2) | 32 | #define TILE_WALLEND (TILE_FIRST + 2) |
33 | #define TILE_WALLUP (TILE_FIRST + 3) | 33 | #define TILE_WALLUP (TILE_FIRST + 3) |
34 | #define TILE_WALLDOWN (TILE_FIRST + 4) | 34 | #define TILE_WALLDOWN (TILE_FIRST + 4) |
35 | #define TILE_WALLLEFT (TILE_FIRST + 5) | 35 | #define TILE_WALLLEFT (TILE_FIRST + 5) |
36 | #define TILE_WALLRIGHT (TILE_FIRST + 6) | 36 | #define TILE_WALLRIGHT (TILE_FIRST + 6) |
37 | 37 | ||
38 | #define GAME_DELAY 15 | 38 | #define GAME_DELAY 15 |
39 | #define BALL_ANIM_DELAY 60 | 39 | #define BALL_ANIM_DELAY 60 |
40 | #define WALL_DELAY 100 | 40 | #define WALL_DELAY 100 |
41 | 41 | ||
42 | #define MS2TICKS( ms ) ((ms)/GAME_DELAY) | 42 | #define MS2TICKS( ms ) ((ms)/GAME_DELAY) |
43 | 43 | ||
44 | Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas) | 44 | Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas) |
45 | : QCanvasSprite( array, canvas ) | 45 | : QCanvasSprite( array, canvas ) |
46 | { | 46 | { |
47 | m_vertical = true; | 47 | m_vertical = true; |
48 | move(3,3); | 48 | move(3,3); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Arrow::update() | 51 | void Arrow::update() |
52 | { | 52 | { |
53 | if ( m_vertical ) | 53 | if ( m_vertical ) |
54 | setFrame( 0 ); | 54 | setFrame( 0 ); |
55 | else | 55 | else |
56 | setFrame( 1 ); | 56 | setFrame( 1 ); |
57 | } | 57 | } |
58 | 58 | ||
59 | void Arrow::changeDirection() | 59 | void Arrow::changeDirection() |
60 | { | 60 | { |
61 | m_vertical = ! m_vertical; | 61 | m_vertical = ! m_vertical; |
62 | update(); | 62 | update(); |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas) | 66 | Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas) |
67 | : QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 ) | 67 | : QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 ) |
68 | { | 68 | { |
69 | } | 69 | } |
70 | 70 | ||
71 | void Ball::update() | 71 | void Ball::update() |
72 | { | 72 | { |
73 | m_animDelay--; | 73 | m_animDelay--; |
74 | if ( m_animDelay<=0 ) | 74 | if ( m_animDelay<=0 ) |
75 | { | 75 | { |
76 | m_animDelay = MS2TICKS(BALL_ANIM_DELAY); | 76 | m_animDelay = MS2TICKS(BALL_ANIM_DELAY); |
77 | int frameNum = frame(); | 77 | int frameNum = frame(); |
78 | frameNum++; | 78 | frameNum++; |
79 | if ( frameNum>=frameCount() ) | 79 | if ( frameNum>=frameCount() ) |
80 | frameNum = 0; | 80 | frameNum = 0; |
81 | setFrame( frameNum ); | 81 | setFrame( frameNum ); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | void Ball::advance(int stage) | 85 | void Ball::advance(int stage) |
86 | { | 86 | { |
87 | bool reflectX = false; | 87 | bool reflectX = false; |
88 | bool reflectY = false; | 88 | bool reflectY = false; |
89 | 89 | ||
90 | // check for collisions | 90 | // check for collisions |
91 | if ( collide(xVelocity(), 0) ) reflectX = true; | 91 | if ( collide(xVelocity(), 0) ) reflectX = true; |
92 | if ( collide(0, yVelocity()) ) reflectY = true; | 92 | if ( collide(0, yVelocity()) ) reflectY = true; |
93 | if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; | 93 | if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; |
94 | 94 | ||
95 | // emit collision | 95 | // emit collision |
96 | QRect r = boundingRect(); | 96 | QRect r = boundingRect(); |
97 | r.moveBy( xVelocity(), yVelocity() ); | 97 | r.moveBy( xVelocity(), yVelocity() ); |
98 | JezzField* field = (JezzField *)canvas(); | 98 | JezzField* field = (JezzField *)canvas(); |
99 | 99 | ||
100 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); | 100 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); |
101 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); | 101 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); |
102 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 102 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
103 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 103 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
104 | 104 | ||
105 | if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else | 105 | if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else |
106 | if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else | 106 | if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else |
107 | if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else | 107 | if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else |
108 | if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); | 108 | if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); |
109 | 109 | ||
110 | // apply reflection | 110 | // apply reflection |
111 | if ( reflectX ) setXVelocity( -xVelocity() ); | 111 | if ( reflectX ) setXVelocity( -xVelocity() ); |
112 | if ( reflectY ) setYVelocity( -yVelocity() ); | 112 | if ( reflectY ) setYVelocity( -yVelocity() ); |
113 | 113 | ||
114 | // update field | 114 | // update field |
115 | update(); | 115 | update(); |
116 | QCanvasSprite::advance( stage ); | 116 | QCanvasSprite::advance( stage ); |
117 | } | 117 | } |
118 | 118 | ||
119 | bool Ball::collide( double dx, double dy ) | 119 | bool Ball::collide( double dx, double dy ) |
120 | { | 120 | { |
121 | QRect r = boundingRect(); | 121 | QRect r = boundingRect(); |
122 | r.moveBy( dx, dy ); | 122 | r.moveBy( dx, dy ); |
123 | JezzField* field = (JezzField *)canvas(); | 123 | JezzField* field = (JezzField *)canvas(); |
124 | 124 | ||
125 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); | 125 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); |
126 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); | 126 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); |
127 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 127 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
128 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 128 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
129 | 129 | ||
130 | return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); | 130 | return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); |
131 | } | 131 | } |
132 | 132 | ||
133 | /*************************************************************************/ | 133 | /*************************************************************************/ |
134 | 134 | ||
135 | Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) | 135 | Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) |
136 | : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), | 136 | : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), |
137 | m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) | 137 | m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) |
138 | { | 138 | { |
139 | // setup position and direction | 139 | // setup position and direction |
140 | m_dx = 0; | 140 | m_dx = 0; |
141 | m_dy = 0; | 141 | m_dy = 0; |
142 | switch ( m_dir ) | 142 | switch ( m_dir ) |
143 | { | 143 | { |
144 | case Up: m_dy = -1; break; | 144 | case Up: m_dy = -1; break; |
145 | case Down: m_dy = 1; break; | 145 | case Down: m_dy = 1; break; |
146 | case Left: m_dx = -1; break; | 146 | case Left: m_dx = -1; break; |
147 | case Right: m_dx = 1; break; | 147 | case Right: m_dx = 1; break; |
148 | } | 148 | } |
149 | 149 | ||
150 | m_x = m_startX; | 150 | m_x = m_startX; |
151 | m_y = m_startY; | 151 | m_y = m_startY; |
152 | 152 | ||
153 | m_field->setTile( m_x, m_y, m_tile ); | 153 | m_field->setTile( m_x, m_y, m_tile ); |
154 | } | 154 | } |
155 | 155 | ||
156 | void Wall::finish() | 156 | void Wall::finish() |
157 | { | 157 | { |
158 | m_active = false; | 158 | m_active = false; |
159 | } | 159 | } |
160 | 160 | ||
161 | bool Wall::isFree( int x, int y ) | 161 | bool Wall::isFree( int x, int y ) |
162 | { | 162 | { |
163 | if ( m_field->tile(x, y)==TILE_FREE ) | 163 | if ( m_field->tile(x, y)==TILE_FREE ) |
164 | { | 164 | { |
165 | // check whether there is a ball at the moment | 165 | // check whether there is a ball at the moment |
166 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, | 166 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, |
167 | TILE_SIZE, TILE_SIZE) ); | 167 | TILE_SIZE, TILE_SIZE) ); |
168 | if ( cols.count()==0 ) | 168 | if ( cols.count()==0 ) |
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | return false; | 172 | return false; |
173 | } | 173 | } |
174 | 174 | ||
175 | void Wall::update() | 175 | void Wall::update() |
176 | { | 176 | { |
177 | } | 177 | } |
178 | 178 | ||
179 | void Wall::advance() | 179 | void Wall::advance() |
180 | { | 180 | { |
181 | update(); | 181 | update(); |
182 | 182 | ||
183 | // move wall | 183 | // move wall |
184 | if ( m_active ) | 184 | if ( m_active ) |
185 | { | 185 | { |
186 | m_delay--; | 186 | m_delay--; |
187 | if ( m_delay<=0 ) | 187 | if ( m_delay<=0 ) |
188 | { | 188 | { |
189 | m_delay = MS2TICKS(WALL_DELAY); | 189 | m_delay = MS2TICKS(WALL_DELAY); |
190 | 190 | ||
191 | // set previous tile | 191 | // set previous tile |
192 | m_field->setTile( m_x, m_y, m_tile ); | 192 | m_field->setTile( m_x, m_y, m_tile ); |
193 | 193 | ||
194 | // check whether next place is still free | 194 | // check whether next place is still free |
195 | if ( isFree(m_x+m_dx, m_y+m_dy) ) | 195 | if ( isFree(m_x+m_dx, m_y+m_dy) ) |
196 | { | 196 | { |
197 | // move ball | 197 | // move ball |
198 | m_x += m_dx; | 198 | m_x += m_dx; |
199 | m_y += m_dy; | 199 | m_y += m_dy; |
200 | 200 | ||
201 | // set tile | 201 | // set tile |
202 | m_field->setTile( m_x, m_y, TILE_WALLEND ); | 202 | m_field->setTile( m_x, m_y, TILE_WALLEND ); |
203 | } else | 203 | } else |
204 | { | 204 | { |
205 | finish(); | 205 | finish(); |
206 | emit finished( this, m_field->tile( m_x+m_dx, m_y+m_dy ) ); | 206 | emit finished( this, m_field->tile( m_x+m_dx, m_y+m_dy ) ); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | void Wall::fill( bool black ) | 212 | void Wall::fill( bool black ) |
213 | { | 213 | { |
214 | if ( m_dx ) | 214 | if ( m_dx ) |
215 | { | 215 | { |
216 | for ( int x=m_startX ; x!=m_x; x+=m_dx ) | 216 | for ( int x=m_startX ; x!=m_x; x+=m_dx ) |
217 | if ( m_field->tile(x, m_startY)==m_tile ) | 217 | if ( m_field->tile(x, m_startY)==m_tile ) |
218 | m_field->setGameTile( x, m_startY, black ); | 218 | m_field->setGameTile( x, m_startY, black ); |
219 | 219 | ||
220 | m_field->setGameTile( m_x, m_startY, black ); | 220 | m_field->setGameTile( m_x, m_startY, black ); |
221 | } else | 221 | } else |
222 | { | 222 | { |
223 | for ( int y=m_startY ; y!=m_y; y+=m_dy ) | 223 | for ( int y=m_startY ; y!=m_y; y+=m_dy ) |
224 | if ( m_field->tile(m_startX, y)==m_tile ) | 224 | if ( m_field->tile(m_startX, y)==m_tile ) |
225 | m_field->setGameTile( m_startX, y, black ); | 225 | m_field->setGameTile( m_startX, y, black ); |
226 | 226 | ||
227 | m_field->setGameTile( m_startX, m_y, black ); | 227 | m_field->setGameTile( m_startX, m_y, black ); |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | /*************************************************************************/ | 231 | /*************************************************************************/ |
232 | 232 | ||
233 | JezzField::JezzField( QPixmap tiles, QObject* parent, const char* name ) | 233 | JezzField::JezzField( QPixmap tiles, QObject* parent, const char* name ) |
234 | : QCanvas( parent, name ), m_tiles( tiles ) | 234 | : QCanvas( parent, name ), m_tiles( tiles ) |
235 | { | 235 | { |
236 | setPixmaps( tiles ); | 236 | setPixmaps( tiles ); |
237 | } | 237 | } |
238 | 238 | ||
239 | void JezzField::setGameTile( int x, int y, bool black ) | 239 | void JezzField::setGameTile( int x, int y, bool black ) |
240 | { | 240 | { |
241 | setTile( x, y, black ? TILE_BORDER : TILE_FREE ); | 241 | setTile( x, y, black ? TILE_BORDER : TILE_FREE ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void JezzField::setPixmaps( QPixmap tiles ) | 244 | void JezzField::setPixmaps( QPixmap tiles ) |
245 | { | 245 | { |
246 | // create new tiles | 246 | // create new tiles |
247 | QPixmap allTiles( TILE_SIZE*(FIELD_WIDTH-2), TILE_SIZE*(FIELD_HEIGHT-1) ); | 247 | QPixmap allTiles( TILE_SIZE*(FIELD_WIDTH-2), TILE_SIZE*(FIELD_HEIGHT-1) ); |
248 | 248 | ||
249 | // handle default tiles | 249 | // handle default tiles |
250 | bitBlt( &allTiles, 0, TILE_SIZE*(FIELD_HEIGHT-2), | 250 | bitBlt( &allTiles, 0, TILE_SIZE*(FIELD_HEIGHT-2), |
251 | &tiles, 0, 0, tiles.width(), tiles.height() ); | 251 | &tiles, 0, 0, tiles.width(), tiles.height() ); |
252 | 252 | ||
253 | // load tiles into canvas | 253 | // load tiles into canvas |
254 | setTiles( allTiles, FIELD_WIDTH, FIELD_HEIGHT, TILE_SIZE, TILE_SIZE ); | 254 | setTiles( allTiles, FIELD_WIDTH, FIELD_HEIGHT, TILE_SIZE, TILE_SIZE ); |
255 | } | 255 | } |
256 | 256 | ||
257 | /*************************************************************************/ | 257 | /*************************************************************************/ |
258 | 258 | ||
259 | JezzView::JezzView(QCanvas* viewing, QWidget* parent, const char* name, WFlags f) | 259 | JezzView::JezzView(QCanvas* viewing, QWidget* parent, const char* name, WFlags f) |
260 | : QCanvasView( viewing, parent, name, f ), m_vertical( false ) | 260 | : QCanvasView( viewing, parent, name, f ), m_vertical( false ) |
261 | { | 261 | { |
262 | setResizePolicy( AutoOne ); | 262 | setResizePolicy( AutoOne ); |
263 | setHScrollBarMode( AlwaysOff ); | 263 | setHScrollBarMode( AlwaysOff ); |
264 | setVScrollBarMode( AlwaysOff ); | 264 | setVScrollBarMode( AlwaysOff ); |
265 | 265 | ||
266 | setCursor( sizeHorCursor ); | 266 | setCursor( sizeHorCursor ); |
267 | } | 267 | } |
268 | 268 | ||
269 | void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) | 269 | void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) |
270 | { | 270 | { |
271 | if ( ev->button() & LeftButton ) | 271 | if ( ev->button() & LeftButton ) |
272 | { | 272 | { |
273 | emit buildWall( ev->x()/TILE_SIZE, ev->y()/TILE_SIZE, m_vertical ); | 273 | emit buildWall( ev->x()/TILE_SIZE, ev->y()/TILE_SIZE, m_vertical ); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | 276 | ||
277 | void JezzView::changeCursor() | 277 | void JezzView::changeCursor() |
278 | { | 278 | { |
279 | m_vertical = !m_vertical; | 279 | m_vertical = !m_vertical; |
280 | if ( m_vertical ) | 280 | if ( m_vertical ) |
281 | { | 281 | { |
282 | setCursor( sizeVerCursor ); | 282 | setCursor( sizeVerCursor ); |
283 | } | 283 | } |
284 | else | 284 | else |
285 | { | 285 | { |
286 | setCursor( sizeHorCursor ); | 286 | setCursor( sizeHorCursor ); |
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | /*************************************************************************/ | 290 | /*************************************************************************/ |
291 | 291 | ||
292 | JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) | 292 | JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) |
293 | : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), | 293 | : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), |
294 | m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) | 294 | m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) |
295 | { | 295 | { |
296 | QString path = QPEApplication::qpeDir()+"pics/zbounce/"; | 296 | QString path = QPEApplication::qpeDir()+"pics/bounce/"; |
297 | 297 | ||
298 | // load gfx | 298 | // load gfx |
299 | m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); | 299 | m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); |
300 | for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) | 300 | for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) |
301 | m_ballPixmaps->image(n)->setOffset( 0, 0 ); | 301 | m_ballPixmaps->image(n)->setOffset( 0, 0 ); |
302 | 302 | ||
303 | m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); | 303 | m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); |
304 | for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) | 304 | for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) |
305 | m_arrowPixmaps->image(n)->setOffset( 0, 0 ); | 305 | m_arrowPixmaps->image(n)->setOffset( 0, 0 ); |
306 | 306 | ||
307 | QPixmap tiles( path + "tiles.png" ); | 307 | QPixmap tiles( path + "tiles.png" ); |
308 | 308 | ||
309 | // create field | 309 | // create field |
310 | m_field = new JezzField( tiles, this, "m_field" ); | 310 | m_field = new JezzField( tiles, this, "m_field" ); |
311 | m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); | 311 | m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); |
312 | 312 | ||
313 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 313 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
314 | m_field->setTile( x, 0, TILE_BORDER ); | 314 | m_field->setTile( x, 0, TILE_BORDER ); |
315 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) | 315 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) |
316 | { | 316 | { |
317 | m_field->setTile( 0, y, TILE_BORDER ); | 317 | m_field->setTile( 0, y, TILE_BORDER ); |
318 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) | 318 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) |
319 | m_field->setTile( x, y, TILE_FREE ); | 319 | m_field->setTile( x, y, TILE_FREE ); |
320 | m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); | 320 | m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); |
321 | } | 321 | } |
322 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 322 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
323 | m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); | 323 | m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); |
324 | 324 | ||
325 | connect( m_field, SIGNAL(ballCollision(Ball *, int, int, int)), this, SLOT(ballCollision(Ball *, int, int, int)) ); | 325 | connect( m_field, SIGNAL(ballCollision(Ball *, int, int, int)), this, SLOT(ballCollision(Ball *, int, int, int)) ); |
326 | 326 | ||
327 | // create view | 327 | // create view |
328 | m_view = new JezzView( m_field, this, "m_view" ); | 328 | m_view = new JezzView( m_field, this, "m_view" ); |
329 | m_view->move( 0, 0 ); | 329 | m_view->move( 0, 0 ); |
330 | m_view->adjustSize(); | 330 | m_view->adjustSize(); |
331 | connect( m_view, SIGNAL(buildWall(int, int, bool)), this, SLOT(buildWall(int, int, bool)) ); | 331 | connect( m_view, SIGNAL(buildWall(int, int, bool)), this, SLOT(buildWall(int, int, bool)) ); |
332 | 332 | ||
333 | // create balls | 333 | // create balls |
334 | for ( int n=0; n<ballNum; n++ ) | 334 | for ( int n=0; n<ballNum; n++ ) |
335 | { | 335 | { |
336 | Ball *ball = new Ball( m_ballPixmaps, m_field ); | 336 | Ball *ball = new Ball( m_ballPixmaps, m_field ); |
337 | m_balls.append( ball ); | 337 | m_balls.append( ball ); |
338 | ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); | 338 | ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); |
339 | ball->setFrame( rand() % 25 ); | 339 | ball->setFrame( rand() % 25 ); |
340 | ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), | 340 | ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), |
341 | 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); | 341 | 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); |
342 | ball->show(); | 342 | ball->show(); |
343 | } | 343 | } |
344 | 344 | ||
345 | // create arrow | 345 | // create arrow |
346 | arrow = new Arrow( m_arrowPixmaps, m_field ); | 346 | arrow = new Arrow( m_arrowPixmaps, m_field ); |
347 | arrow->show(); | 347 | arrow->show(); |
348 | 348 | ||
349 | // create text label | 349 | // create text label |
350 | m_text = new QCanvasText( m_field ); | 350 | m_text = new QCanvasText( m_field ); |
351 | 351 | ||
352 | // create game clock | 352 | // create game clock |
353 | m_clock = new QTimer( this ); | 353 | m_clock = new QTimer( this ); |
354 | connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); | 354 | connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); |
355 | m_clock->start( GAME_DELAY ); | 355 | m_clock->start( GAME_DELAY ); |
356 | 356 | ||
357 | // setup geometry | 357 | // setup geometry |
358 | setFixedSize( m_view->size() ); | 358 | setFixedSize( m_view->size() ); |
359 | } | 359 | } |
360 | 360 | ||
361 | JezzGame::~JezzGame() | 361 | JezzGame::~JezzGame() |
362 | { | 362 | { |
363 | m_balls.clear(); | 363 | m_balls.clear(); |
364 | delete m_view; | 364 | delete m_view; |
365 | delete m_field; | 365 | delete m_field; |
366 | delete m_ballPixmaps; | 366 | delete m_ballPixmaps; |
367 | } | 367 | } |
368 | 368 | ||
369 | void JezzGame::display( QString text, int size ) | 369 | void JezzGame::display( QString text, int size ) |
370 | { | 370 | { |
371 | qDebug("This function \"display\" shouldn't be called!!!"); | 371 | qDebug("This function \"display\" shouldn't be called!!!"); |
372 | if ( !text.isEmpty() ) | 372 | if ( !text.isEmpty() ) |
373 | { | 373 | { |
374 | QFont font( "Helvetica", size, QFont::Bold ); | 374 | QFont font( "Helvetica", size, QFont::Bold ); |
375 | font.setStyleHint( QFont::Helvetica ); | 375 | font.setStyleHint( QFont::Helvetica ); |
376 | m_text->setFont( font ); | 376 | m_text->setFont( font ); |
377 | m_text->setText( text ); | 377 | m_text->setText( text ); |
378 | 378 | ||
379 | QRect size = m_text->boundingRect(); | 379 | QRect size = m_text->boundingRect(); |
380 | m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, | 380 | m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, |
381 | ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); | 381 | ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); |
382 | 382 | ||
383 | m_text->show(); | 383 | m_text->show(); |
384 | } else | 384 | } else |
385 | { | 385 | { |
386 | m_text->hide(); | 386 | m_text->hide(); |
387 | } | 387 | } |
388 | } | 388 | } |
389 | 389 | ||
390 | void JezzGame::start() | 390 | void JezzGame::start() |
391 | { | 391 | { |
392 | m_running = true; | 392 | m_running = true; |
393 | } | 393 | } |
394 | 394 | ||
395 | void JezzGame::stop() | 395 | void JezzGame::stop() |
396 | { | 396 | { |
397 | m_running = false; | 397 | m_running = false; |
398 | } | 398 | } |
399 | 399 | ||
400 | 400 | ||
401 | void JezzGame::makeBlack() | 401 | void JezzGame::makeBlack() |
402 | { | 402 | { |
403 | // copy current field into buffer | 403 | // copy current field into buffer |
404 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 404 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
405 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 405 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
406 | m_buf[x][y] = m_field->tile( x, y ); | 406 | m_buf[x][y] = m_field->tile( x, y ); |
407 | 407 | ||
408 | // fill areas that contains a ball | 408 | // fill areas that contains a ball |
409 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) | 409 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) |
410 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); | 410 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); |
411 | 411 | ||
412 | // areas still free can be blacked now | 412 | // areas still free can be blacked now |
413 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 413 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
414 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 414 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
415 | { | 415 | { |
416 | if ( m_buf[x][y]==TILE_FREE ) | 416 | if ( m_buf[x][y]==TILE_FREE ) |
417 | m_field->setGameTile( x, y, true ); | 417 | m_field->setGameTile( x, y, true ); |
418 | } | 418 | } |
419 | 419 | ||
420 | m_field->update(); | 420 | m_field->update(); |
421 | m_view->repaint(); | 421 | m_view->repaint(); |
422 | 422 | ||
423 | // count percent value of occupied area | 423 | // count percent value of occupied area |
424 | int p = percent(); | 424 | int p = percent(); |
425 | if ( p!=m_percent ) | 425 | if ( p!=m_percent ) |
426 | { | 426 | { |
427 | m_percent = p; | 427 | m_percent = p; |
428 | emit newPercent( m_percent ); | 428 | emit newPercent( m_percent ); |
429 | } | 429 | } |
430 | } | 430 | } |
431 | 431 | ||
432 | int JezzGame::percent() | 432 | int JezzGame::percent() |
433 | { | 433 | { |
434 | int notFree = 0; | 434 | int notFree = 0; |
435 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) | 435 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) |
436 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) | 436 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) |
437 | { | 437 | { |
438 | if ( m_field->tile(x,y)!=TILE_FREE ) | 438 | if ( m_field->tile(x,y)!=TILE_FREE ) |
439 | notFree++; | 439 | notFree++; |
440 | } | 440 | } |
441 | 441 | ||
442 | return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); | 442 | return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); |
443 | } | 443 | } |
444 | 444 | ||
445 | void JezzGame::fill( int x, int y ) | 445 | void JezzGame::fill( int x, int y ) |
446 | { | 446 | { |
447 | if ( m_buf[x][y]!=TILE_FREE) return; | 447 | if ( m_buf[x][y]!=TILE_FREE) return; |
448 | 448 | ||
449 | // go left | 449 | // go left |
450 | int _x=x; | 450 | int _x=x; |
451 | for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) | 451 | for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) |
452 | m_buf[_x][y] = TILE_BORDER; | 452 | m_buf[_x][y] = TILE_BORDER; |
453 | int stopx = _x; | 453 | int stopx = _x; |
454 | 454 | ||
455 | // fill above | 455 | // fill above |
456 | for ( _x=x; _x>stopx; _x-- ) | 456 | for ( _x=x; _x>stopx; _x-- ) |
457 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); | 457 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |
458 | 458 | ||
459 | // fill below | 459 | // fill below |
460 | for ( _x=x; _x>stopx; _x-- ) | 460 | for ( _x=x; _x>stopx; _x-- ) |
461 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); | 461 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); |
462 | 462 | ||
463 | // go right | 463 | // go right |
464 | for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) | 464 | for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) |
465 | m_buf[_x][y] = TILE_BORDER; | 465 | m_buf[_x][y] = TILE_BORDER; |
466 | stopx = _x; | 466 | stopx = _x; |
467 | 467 | ||
468 | // fill above | 468 | // fill above |
469 | for ( _x=x+1; _x<stopx; _x++ ) | 469 | for ( _x=x+1; _x<stopx; _x++ ) |
470 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); | 470 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |
471 | 471 | ||
472 | // fill below; | 472 | // fill below; |
473 | for ( _x=x+1; _x<stopx; _x++ ) | 473 | for ( _x=x+1; _x<stopx; _x++ ) |
474 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); | 474 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); |
475 | } | 475 | } |
476 | 476 | ||
477 | void JezzGame::ballCollision( Ball*, int, int, int tile ) | 477 | void JezzGame::ballCollision( Ball*, int, int, int tile ) |
478 | { | 478 | { |
479 | if ( tile!=TILE_BORDER && tile>TILE_FREE && tile!=TILE_WALLEND ) | 479 | if ( tile!=TILE_BORDER && tile>TILE_FREE && tile!=TILE_WALLEND ) |
480 | { | 480 | { |
481 | // stop walls | 481 | // stop walls |
482 | if ( (tile==TILE_WALLUP || tile==TILE_WALLLEFT) && m_wall1 ) | 482 | if ( (tile==TILE_WALLUP || tile==TILE_WALLLEFT) && m_wall1 ) |
483 | { | 483 | { |
484 | m_wall1->finish(); | 484 | m_wall1->finish(); |
485 | m_wall1->fill( false ); | 485 | m_wall1->fill( false ); |
486 | delete m_wall1; | 486 | delete m_wall1; |
487 | m_wall1 = 0; | 487 | m_wall1 = 0; |
488 | } | 488 | } |
489 | 489 | ||
490 | if ( (tile==TILE_WALLDOWN || tile==TILE_WALLRIGHT) && m_wall2 ) | 490 | if ( (tile==TILE_WALLDOWN || tile==TILE_WALLRIGHT) && m_wall2 ) |
491 | { | 491 | { |
492 | m_wall2->finish(); | 492 | m_wall2->finish(); |
493 | m_wall2->fill( false ); | 493 | m_wall2->fill( false ); |
494 | delete m_wall2; | 494 | delete m_wall2; |
495 | m_wall2 = 0; | 495 | m_wall2 = 0; |
496 | } | 496 | } |
497 | 497 | ||
498 | // update view | 498 | // update view |
499 | m_field->update(); | 499 | m_field->update(); |
500 | m_view->repaint(); | 500 | m_view->repaint(); |
501 | 501 | ||
502 | // send death msg | 502 | // send death msg |
503 | emit died(); | 503 | emit died(); |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | void JezzGame::buildWall( int x, int y, bool vertical ) | 507 | void JezzGame::buildWall( int x, int y, bool vertical ) |
508 | { | 508 | { |
509 | if ( !m_running ) return; | 509 | if ( !m_running ) return; |
510 | 510 | ||
511 | if ( m_field->tile(x, y)==TILE_FREE ) | 511 | if ( m_field->tile(x, y)==TILE_FREE ) |
512 | { | 512 | { |
513 | // check whether there is a ball at the moment | 513 | // check whether there is a ball at the moment |
514 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); | 514 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); |
515 | if ( cols.count()>0 ) | 515 | if ( cols.count()>0 ) |
516 | { | 516 | { |
517 | //kdDebug() << "Direct collision" << endl; | 517 | //kdDebug() << "Direct collision" << endl; |
518 | emit ballCollision( (Ball*)cols.first(), x, y, TILE_WALLUP ); | 518 | emit ballCollision( (Ball*)cols.first(), x, y, TILE_WALLUP ); |
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | 521 | ||
522 | // start walls | 522 | // start walls |
523 | if ( !m_wall1 ) | 523 | if ( !m_wall1 ) |
524 | { | 524 | { |
525 | m_wall1 = new Wall( m_field, x, y, | 525 | m_wall1 = new Wall( m_field, x, y, |
526 | vertical? Wall::Up : Wall::Left, | 526 | vertical? Wall::Up : Wall::Left, |
527 | vertical? TILE_WALLUP : TILE_WALLLEFT, | 527 | vertical? TILE_WALLUP : TILE_WALLLEFT, |
528 | this, "m_wall1" ); | 528 | this, "m_wall1" ); |
529 | connect( m_wall1, SIGNAL(finished(Wall *, int)), | 529 | connect( m_wall1, SIGNAL(finished(Wall *, int)), |
530 | this, SLOT(wallFinished(Wall *, int)) ); } | 530 | this, SLOT(wallFinished(Wall *, int)) ); } |
531 | 531 | ||
532 | if ( !m_wall2 ) | 532 | if ( !m_wall2 ) |
533 | { | 533 | { |
534 | m_wall2 = new Wall( m_field, x, y, | 534 | m_wall2 = new Wall( m_field, x, y, |
535 | vertical? Wall::Down: Wall::Right, | 535 | vertical? Wall::Down: Wall::Right, |
536 | vertical? TILE_WALLDOWN : TILE_WALLRIGHT, | 536 | vertical? TILE_WALLDOWN : TILE_WALLRIGHT, |
537 | this, "m_wall2" ); | 537 | this, "m_wall2" ); |
538 | connect( m_wall2, SIGNAL(finished(Wall *, int)), | 538 | connect( m_wall2, SIGNAL(finished(Wall *, int)), |
539 | this, SLOT(wallFinished(Wall *, int)) ); | 539 | this, SLOT(wallFinished(Wall *, int)) ); |
540 | } | 540 | } |
541 | } | 541 | } |
542 | } | 542 | } |
543 | 543 | ||
544 | void JezzGame::wallFinished( Wall *wall, int tile ) | 544 | void JezzGame::wallFinished( Wall *wall, int tile ) |
545 | { | 545 | { |
546 | if ( tile==TILE_WALLEND ) | 546 | if ( tile==TILE_WALLEND ) |
547 | { | 547 | { |
548 | if ( m_wall1 ) | 548 | if ( m_wall1 ) |
549 | { | 549 | { |
550 | m_wall1->fill( false ); | 550 | m_wall1->fill( false ); |
551 | delete m_wall1; | 551 | delete m_wall1; |
552 | m_wall1 = 0; | 552 | m_wall1 = 0; |
553 | } | 553 | } |
554 | 554 | ||
555 | if ( m_wall2 ) | 555 | if ( m_wall2 ) |
556 | { | 556 | { |
557 | m_wall2->fill( false ); | 557 | m_wall2->fill( false ); |
558 | delete m_wall2; | 558 | delete m_wall2; |
559 | m_wall2 = 0; | 559 | m_wall2 = 0; |
560 | } | 560 | } |
561 | } else | 561 | } else |
562 | { | 562 | { |
563 | if ( m_wall1==wall && m_wall1 ) | 563 | if ( m_wall1==wall && m_wall1 ) |
564 | { | 564 | { |
565 | m_wall1->fill( true ); | 565 | m_wall1->fill( true ); |
566 | delete m_wall1; | 566 | delete m_wall1; |
567 | m_wall1 = 0; | 567 | m_wall1 = 0; |
568 | } | 568 | } |
569 | 569 | ||
570 | if ( m_wall2==wall && m_wall2 ) | 570 | if ( m_wall2==wall && m_wall2 ) |
571 | { | 571 | { |
572 | m_wall2->fill( true ); | 572 | m_wall2->fill( true ); |
573 | delete m_wall2; | 573 | delete m_wall2; |
574 | m_wall2 = 0; | 574 | m_wall2 = 0; |
575 | } | 575 | } |
576 | } | 576 | } |
577 | 577 | ||
578 | m_field->update(); | 578 | m_field->update(); |
579 | m_view->repaint(); | 579 | m_view->repaint(); |
580 | 580 | ||
581 | makeBlack(); | 581 | makeBlack(); |
582 | } | 582 | } |
583 | 583 | ||
584 | void JezzGame::tick() | 584 | void JezzGame::tick() |
585 | { | 585 | { |
586 | if ( m_running ) | 586 | if ( m_running ) |
587 | { | 587 | { |
588 | if ( m_field ) m_field->advance(); | 588 | if ( m_field ) m_field->advance(); |
589 | if ( m_wall1 ) m_wall1->advance(); | 589 | if ( m_wall1 ) m_wall1->advance(); |
590 | if ( m_wall2 ) m_wall2->advance(); | 590 | if ( m_wall2 ) m_wall2->advance(); |
591 | } else | 591 | } else |
592 | { | 592 | { |
593 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) | 593 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) |
594 | ball->update(); | 594 | ball->update(); |
595 | 595 | ||
596 | if ( m_field ) m_field->update(); | 596 | if ( m_field ) m_field->update(); |
597 | if ( m_wall1 ) m_wall1->update(); | 597 | if ( m_wall1 ) m_wall1->update(); |
598 | if ( m_wall2 ) m_wall2->update(); | 598 | if ( m_wall2 ) m_wall2->update(); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | 601 | ||
602 | void JezzGame::changeCursor() | 602 | void JezzGame::changeCursor() |
603 | { | 603 | { |
604 | arrow->changeDirection(); | 604 | arrow->changeDirection(); |
605 | m_view->changeCursor(); | 605 | m_view->changeCursor(); |
606 | } | 606 | } |
diff --git a/noncore/games/zbounce/game.h b/noncore/games/bounce/game.h index 656fba3..656fba3 100644 --- a/noncore/games/zbounce/game.h +++ b/noncore/games/bounce/game.h | |||
diff --git a/noncore/games/bounce/kbounce.cpp b/noncore/games/bounce/kbounce.cpp index c1c0f70..f703f74 100644 --- a/noncore/games/bounce/kbounce.cpp +++ b/noncore/games/bounce/kbounce.cpp | |||
@@ -1,302 +1,302 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License,Life or (at your option) any later version. | 7 | * version 2 of the License,Life or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 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 | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | #include <qlcdnumber.h> | 21 | #include <qlcdnumber.h> |
22 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
23 | #include <qmainwindow.h> | 23 | #include <qmainwindow.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | 25 | ||
26 | #include "kbounce.h" | 26 | #include "kbounce.h" |
27 | #include "game.h" | 27 | #include "game.h" |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | 29 | ||
30 | KJezzball::KJezzball() : QMainWindow(0), m_gameWidget( 0 ) | 30 | KJezzball::KJezzball() : QMainWindow(0), m_gameWidget( 0 ) |
31 | { | 31 | { |
32 | setCaption(tr("ZBounce")); | 32 | setCaption(tr("Bounce")); |
33 | // setup variables | 33 | // setup variables |
34 | m_game.level = 1; | 34 | m_game.level = 1; |
35 | m_game.score = 0; | 35 | m_game.score = 0; |
36 | m_state = Idle; | 36 | m_state = Idle; |
37 | 37 | ||
38 | 38 | ||
39 | menu = menuBar(); | 39 | menu = menuBar(); |
40 | game = new QPopupMenu; | 40 | game = new QPopupMenu; |
41 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); | 41 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); |
42 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); | 42 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); |
43 | game->insertSeparator(); | 43 | game->insertSeparator(); |
44 | game->insertItem(tr("&About"), this, SLOT(about())); | 44 | game->insertItem(tr("&About"), this, SLOT(about())); |
45 | menu->insertItem( tr("&Game"), game ); | 45 | menu->insertItem( tr("&Game"), game ); |
46 | 46 | ||
47 | // create widgets | 47 | // create widgets |
48 | m_view = new QWidget( this, "m_view" ); | 48 | m_view = new QWidget( this, "m_view" ); |
49 | setCentralWidget( m_view ); | 49 | setCentralWidget( m_view ); |
50 | 50 | ||
51 | m_layout = new QGridLayout( m_view ); | 51 | m_layout = new QGridLayout( m_view ); |
52 | m_layout->setSpacing( 0 ); | 52 | m_layout->setSpacing( 0 ); |
53 | m_layout->setMargin( 0 ); | 53 | m_layout->setMargin( 0 ); |
54 | 54 | ||
55 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); | 55 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); |
56 | ScoreLabel->setText( tr( "Score: 00" ) ); | 56 | ScoreLabel->setText( tr( "Score: 00" ) ); |
57 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); | 57 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); |
58 | 58 | ||
59 | m_layout->addWidget( ScoreLabel, 1, 0 ); | 59 | m_layout->addWidget( ScoreLabel, 1, 0 ); |
60 | 60 | ||
61 | LivesLabel = new QLabel( m_view, "LivesLabel" ); | 61 | LivesLabel = new QLabel( m_view, "LivesLabel" ); |
62 | LivesLabel->setText( tr( "Lives: 0%" ) ); | 62 | LivesLabel->setText( tr( "Lives: 0%" ) ); |
63 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); | 63 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); |
64 | 64 | ||
65 | m_layout->addWidget( LivesLabel, 1, 2 ); | 65 | m_layout->addWidget( LivesLabel, 1, 2 ); |
66 | 66 | ||
67 | FilledLabel = new QLabel( m_view, "FilledLabel" ); | 67 | FilledLabel = new QLabel( m_view, "FilledLabel" ); |
68 | FilledLabel->setText( tr( "Filled: 00%" ) ); | 68 | FilledLabel->setText( tr( "Filled: 00%" ) ); |
69 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); | 69 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); |
70 | 70 | ||
71 | m_layout->addWidget( FilledLabel, 1, 1 ); | 71 | m_layout->addWidget( FilledLabel, 1, 1 ); |
72 | 72 | ||
73 | TimeLabel = new QLabel( m_view, "TimeLabel" ); | 73 | TimeLabel = new QLabel( m_view, "TimeLabel" ); |
74 | TimeLabel->setText( tr( "Time: 00" ) ); | 74 | TimeLabel->setText( tr( "Time: 00" ) ); |
75 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); | 75 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); |
76 | 76 | ||
77 | m_layout->addWidget( TimeLabel, 1, 3 ); | 77 | m_layout->addWidget( TimeLabel, 1, 3 ); |
78 | 78 | ||
79 | // create timers | 79 | // create timers |
80 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); | 80 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); |
81 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); | 81 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); |
82 | 82 | ||
83 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); | 83 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); |
84 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); | 84 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); |
85 | 85 | ||
86 | m_timer = new QTimer( this, "m_timer" ); | 86 | m_timer = new QTimer( this, "m_timer" ); |
87 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); | 87 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); |
88 | 88 | ||
89 | // create demo game | 89 | // create demo game |
90 | createLevel( 1 ); | 90 | createLevel( 1 ); |
91 | } | 91 | } |
92 | 92 | ||
93 | void KJezzball::newGame() | 93 | void KJezzball::newGame() |
94 | { | 94 | { |
95 | // Check for running game | 95 | // Check for running game |
96 | closeGame(); | 96 | closeGame(); |
97 | if ( m_state==Idle ) | 97 | if ( m_state==Idle ) |
98 | { | 98 | { |
99 | // update displays | 99 | // update displays |
100 | m_game.level = 1; | 100 | m_game.level = 1; |
101 | m_game.score = 0; | 101 | m_game.score = 0; |
102 | 102 | ||
103 | setCaption(tr("ZBounce Level %1").arg(m_game.level)); | 103 | setCaption(tr("Bounce Level %1").arg(m_game.level)); |
104 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | 104 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); |
105 | 105 | ||
106 | // start new game | 106 | // start new game |
107 | m_state = Running; | 107 | m_state = Running; |
108 | 108 | ||
109 | createLevel( m_game.level ); | 109 | createLevel( m_game.level ); |
110 | startLevel(); | 110 | startLevel(); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | void KJezzball::about() | 114 | void KJezzball::about() |
115 | { | 115 | { |
116 | QMessageBox::information( this, "About", "Written by: Stefan Schimanski\nPorted by: Martin Imobersteg\n\nThis program is distributed under\nthe terms of the GPL v2." ); | 116 | QMessageBox::information( this, "About", "Written by: Stefan Schimanski\nPorted by: Martin Imobersteg\n\nThis program is distributed under\nthe terms of the GPL v2." ); |
117 | } | 117 | } |
118 | 118 | ||
119 | void KJezzball::closeGame() | 119 | void KJezzball::closeGame() |
120 | { | 120 | { |
121 | if ( m_state!=Idle ) | 121 | if ( m_state!=Idle ) |
122 | { | 122 | { |
123 | stopLevel(); | 123 | stopLevel(); |
124 | m_state = Idle; | 124 | m_state = Idle; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | void KJezzball::pauseGame() | 128 | void KJezzball::pauseGame() |
129 | { | 129 | { |
130 | switch ( m_state ) | 130 | switch ( m_state ) |
131 | { | 131 | { |
132 | case Running: | 132 | case Running: |
133 | m_state = Paused; | 133 | m_state = Paused; |
134 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); | 134 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); |
135 | stopLevel(); | 135 | stopLevel(); |
136 | break; | 136 | break; |
137 | 137 | ||
138 | case Paused: | 138 | case Paused: |
139 | case Suspend: | 139 | case Suspend: |
140 | m_state = Running; | 140 | m_state = Running; |
141 | m_gameWidget->display( QString::null ); | 141 | m_gameWidget->display( QString::null ); |
142 | startLevel(); | 142 | startLevel(); |
143 | break; | 143 | break; |
144 | 144 | ||
145 | case Idle: | 145 | case Idle: |
146 | break; | 146 | break; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | void KJezzball::gameOver() | 150 | void KJezzball::gameOver() |
151 | { | 151 | { |
152 | stopLevel(); | 152 | stopLevel(); |
153 | m_gameOverTimer->start( 100, TRUE ); | 153 | m_gameOverTimer->start( 100, TRUE ); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | void KJezzball::gameOverNow() | 157 | void KJezzball::gameOverNow() |
158 | { | 158 | { |
159 | m_state = Idle; | 159 | m_state = Idle; |
160 | 160 | ||
161 | QString score; | 161 | QString score; |
162 | score.setNum( m_game.score ); | 162 | score.setNum( m_game.score ); |
163 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); | 163 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); |
164 | } | 164 | } |
165 | 165 | ||
166 | void KJezzball::focusOutEvent( QFocusEvent *ev ) | 166 | void KJezzball::focusOutEvent( QFocusEvent *ev ) |
167 | { | 167 | { |
168 | if ( m_state==Running ) | 168 | if ( m_state==Running ) |
169 | { | 169 | { |
170 | stopLevel(); | 170 | stopLevel(); |
171 | m_state = Suspend; | 171 | m_state = Suspend; |
172 | } | 172 | } |
173 | 173 | ||
174 | QMainWindow::focusOutEvent( ev ); | 174 | QMainWindow::focusOutEvent( ev ); |
175 | } | 175 | } |
176 | 176 | ||
177 | void KJezzball::focusInEvent ( QFocusEvent *ev ) | 177 | void KJezzball::focusInEvent ( QFocusEvent *ev ) |
178 | { | 178 | { |
179 | if ( m_state==Suspend ) | 179 | if ( m_state==Suspend ) |
180 | { | 180 | { |
181 | startLevel(); | 181 | startLevel(); |
182 | m_state = Running; | 182 | m_state = Running; |
183 | } | 183 | } |
184 | 184 | ||
185 | QMainWindow::focusInEvent( ev ); | 185 | QMainWindow::focusInEvent( ev ); |
186 | } | 186 | } |
187 | 187 | ||
188 | void KJezzball::second() | 188 | void KJezzball::second() |
189 | { | 189 | { |
190 | m_level.time--; | 190 | m_level.time--; |
191 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | 191 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); |
192 | if ( m_level.time<=0 ) | 192 | if ( m_level.time<=0 ) |
193 | { | 193 | { |
194 | gameOver(); | 194 | gameOver(); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
198 | void KJezzball::died() | 198 | void KJezzball::died() |
199 | { | 199 | { |
200 | m_level.lifes--; | 200 | m_level.lifes--; |
201 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | 201 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); |
202 | if ( m_level.lifes==0 ) gameOver(); | 202 | if ( m_level.lifes==0 ) gameOver(); |
203 | } | 203 | } |
204 | 204 | ||
205 | void KJezzball::newPercent( int percent ) | 205 | void KJezzball::newPercent( int percent ) |
206 | { | 206 | { |
207 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); | 207 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); |
208 | if ( percent>=75 ) | 208 | if ( percent>=75 ) |
209 | { | 209 | { |
210 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); | 210 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); |
211 | nextLevel(); | 211 | nextLevel(); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | void KJezzball::createLevel( int level ) | 215 | void KJezzball::createLevel( int level ) |
216 | { | 216 | { |
217 | // destroy old game | 217 | // destroy old game |
218 | if ( m_gameWidget ) delete m_gameWidget; | 218 | if ( m_gameWidget ) delete m_gameWidget; |
219 | 219 | ||
220 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); | 220 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); |
221 | 221 | ||
222 | m_gameWidget->show(); | 222 | m_gameWidget->show(); |
223 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); | 223 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); |
224 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); | 224 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); |
225 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); | 225 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); |
226 | 226 | ||
227 | // update displays | 227 | // update displays |
228 | m_level.lifes = level+1; | 228 | m_level.lifes = level+1; |
229 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | 229 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); |
230 | FilledLabel->setText( tr( "Filled: 0%" ) ); | 230 | FilledLabel->setText( tr( "Filled: 0%" ) ); |
231 | 231 | ||
232 | m_level.time = (level+2)*30; | 232 | m_level.time = (level+2)*30; |
233 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | 233 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); |
234 | 234 | ||
235 | m_level.score = 0; | 235 | m_level.score = 0; |
236 | } | 236 | } |
237 | 237 | ||
238 | void KJezzball::startLevel() | 238 | void KJezzball::startLevel() |
239 | { | 239 | { |
240 | if ( m_gameWidget ) | 240 | if ( m_gameWidget ) |
241 | { | 241 | { |
242 | m_timer->start( 1000 ); | 242 | m_timer->start( 1000 ); |
243 | m_gameWidget->start(); | 243 | m_gameWidget->start(); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | void KJezzball::stopLevel() | 247 | void KJezzball::stopLevel() |
248 | { | 248 | { |
249 | if ( m_gameWidget ) | 249 | if ( m_gameWidget ) |
250 | { | 250 | { |
251 | m_gameWidget->stop(); | 251 | m_gameWidget->stop(); |
252 | m_timer->stop(); | 252 | m_timer->stop(); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | void KJezzball::nextLevel() | 256 | void KJezzball::nextLevel() |
257 | { | 257 | { |
258 | stopLevel(); | 258 | stopLevel(); |
259 | m_nextLevelTimer->start( 100, TRUE ); | 259 | m_nextLevelTimer->start( 100, TRUE ); |
260 | } | 260 | } |
261 | 261 | ||
262 | void KJezzball::switchLevel() | 262 | void KJezzball::switchLevel() |
263 | { | 263 | { |
264 | m_game.score += m_level.score; | 264 | m_game.score += m_level.score; |
265 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | 265 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); |
266 | 266 | ||
267 | QString score; | 267 | QString score; |
268 | score.setNum( m_level.score ); | 268 | score.setNum( m_level.score ); |
269 | 269 | ||
270 | QString level; | 270 | QString level; |
271 | level.setNum( m_game.level ); | 271 | level.setNum( m_game.level ); |
272 | 272 | ||
273 | QString foo = QString( | 273 | QString foo = QString( |
274 | tr("Successfully cleared more than 75%.\n") + | 274 | tr("Successfully cleared more than 75%.\n") + |
275 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + | 275 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + |
276 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + | 276 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + |
277 | tr("%1 points: Total score\n").arg(score) + | 277 | tr("%1 points: Total score\n").arg(score) + |
278 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); | 278 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); |
279 | 279 | ||
280 | QMessageBox::information( this, "Success", foo ); | 280 | QMessageBox::information( this, "Success", foo ); |
281 | 281 | ||
282 | m_game.level++; | 282 | m_game.level++; |
283 | 283 | ||
284 | createLevel( m_game.level ); | 284 | createLevel( m_game.level ); |
285 | startLevel(); | 285 | startLevel(); |
286 | } | 286 | } |
287 | 287 | ||
288 | void KJezzball::keyPressEvent( QKeyEvent *ev ) | 288 | void KJezzball::keyPressEvent( QKeyEvent *ev ) |
289 | { | 289 | { |
290 | if ( ev->key() == Key_Space || | 290 | if ( ev->key() == Key_Space || |
291 | ev->key() == Key_Up || | 291 | ev->key() == Key_Up || |
292 | ev->key() == Key_Down || | 292 | ev->key() == Key_Down || |
293 | ev->key() == Key_Right || | 293 | ev->key() == Key_Right || |
294 | ev->key() == Key_Left ) | 294 | ev->key() == Key_Left ) |
295 | { | 295 | { |
296 | m_gameWidget->changeCursor(); | 296 | m_gameWidget->changeCursor(); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | { | 299 | { |
300 | ev->ignore(); | 300 | ev->ignore(); |
301 | } | 301 | } |
302 | } | 302 | } |
diff --git a/noncore/games/zbounce/kbounce.h b/noncore/games/bounce/kbounce.h index de41710..de41710 100644 --- a/noncore/games/zbounce/kbounce.h +++ b/noncore/games/bounce/kbounce.h | |||
diff --git a/noncore/games/zbounce/main.cpp b/noncore/games/bounce/main.cpp index a6b7c1a..a6b7c1a 100644 --- a/noncore/games/zbounce/main.cpp +++ b/noncore/games/bounce/main.cpp | |||
diff --git a/noncore/games/bounce/opie-bounce.control b/noncore/games/bounce/opie-bounce.control new file mode 100644 index 0000000..b3d3cf9 --- a/dev/null +++ b/noncore/games/bounce/opie-bounce.control | |||
@@ -0,0 +1,20 @@ | |||
1 | Files: bin/bounce apps/Games/bounce.desktop pics/bounce/bounce.png \ | ||
2 | pics/bounce/arrow0000.png pics/bounce/ball0008.png pics/bounce/ball0018.png \ | ||
3 | pics/bounce/arrow0001.png pics/bounce/ball0009.png pics/bounce/ball0019.png \ | ||
4 | pics/bounce/ball0000.png pics/bounce/ball0010.png pics/bounce/ball0020.png \ | ||
5 | pics/bounce/ball0001.png pics/bounce/ball0011.png pics/bounce/ball0021.png \ | ||
6 | pics/bounce/ball0002.png pics/bounce/ball0012.png pics/bounce/ball0022.png \ | ||
7 | pics/bounce/ball0003.png pics/bounce/ball0013.png pics/bounce/ball0023.png \ | ||
8 | pics/bounce/ball0004.png pics/bounce/ball0014.png pics/bounce/ball0024.png \ | ||
9 | pics/bounce/ball0005.png pics/bounce/ball0015.png pics/bounce/tiles.png \ | ||
10 | pics/bounce/ball0006.png pics/bounce/ball0016.png \ | ||
11 | pics/bounce/ball0007.png pics/bounce/ball0017.png \ | ||
12 | Version: 0.6 | ||
13 | Depends: opie-base ($QPE_VERSION) | ||
14 | Priority: optional | ||
15 | Section: opie/games | ||
16 | Maintainer: Martin Imobersteg <imm@gmx.ch> | ||
17 | Architecture: arm | ||
18 | License: GPL | ||
19 | Description: bounce | ||
20 | A JezzGame like game for Qtopia. | ||
diff --git a/noncore/games/zbounce/kbounce.cpp b/noncore/games/zbounce/kbounce.cpp deleted file mode 100644 index c1c0f70..0000000 --- a/noncore/games/zbounce/kbounce.cpp +++ b/dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2000 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,Life 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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #include <qlayout.h> | ||
20 | #include <qtimer.h> | ||
21 | #include <qlcdnumber.h> | ||
22 | #include <qmessagebox.h> | ||
23 | #include <qmainwindow.h> | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | |||
26 | #include "kbounce.h" | ||
27 | #include "game.h" | ||
28 | #include <qlabel.h> | ||
29 | |||
30 | KJezzball::KJezzball() : QMainWindow(0), m_gameWidget( 0 ) | ||
31 | { | ||
32 | setCaption(tr("ZBounce")); | ||
33 | // setup variables | ||
34 | m_game.level = 1; | ||
35 | m_game.score = 0; | ||
36 | m_state = Idle; | ||
37 | |||
38 | |||
39 | menu = menuBar(); | ||
40 | game = new QPopupMenu; | ||
41 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); | ||
42 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); | ||
43 | game->insertSeparator(); | ||
44 | game->insertItem(tr("&About"), this, SLOT(about())); | ||
45 | menu->insertItem( tr("&Game"), game ); | ||
46 | |||
47 | // create widgets | ||
48 | m_view = new QWidget( this, "m_view" ); | ||
49 | setCentralWidget( m_view ); | ||
50 | |||
51 | m_layout = new QGridLayout( m_view ); | ||
52 | m_layout->setSpacing( 0 ); | ||
53 | m_layout->setMargin( 0 ); | ||
54 | |||
55 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); | ||
56 | ScoreLabel->setText( tr( "Score: 00" ) ); | ||
57 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); | ||
58 | |||
59 | m_layout->addWidget( ScoreLabel, 1, 0 ); | ||
60 | |||
61 | LivesLabel = new QLabel( m_view, "LivesLabel" ); | ||
62 | LivesLabel->setText( tr( "Lives: 0%" ) ); | ||
63 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); | ||
64 | |||
65 | m_layout->addWidget( LivesLabel, 1, 2 ); | ||
66 | |||
67 | FilledLabel = new QLabel( m_view, "FilledLabel" ); | ||
68 | FilledLabel->setText( tr( "Filled: 00%" ) ); | ||
69 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); | ||
70 | |||
71 | m_layout->addWidget( FilledLabel, 1, 1 ); | ||
72 | |||
73 | TimeLabel = new QLabel( m_view, "TimeLabel" ); | ||
74 | TimeLabel->setText( tr( "Time: 00" ) ); | ||
75 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); | ||
76 | |||
77 | m_layout->addWidget( TimeLabel, 1, 3 ); | ||
78 | |||
79 | // create timers | ||
80 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); | ||
81 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); | ||
82 | |||
83 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); | ||
84 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); | ||
85 | |||
86 | m_timer = new QTimer( this, "m_timer" ); | ||
87 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); | ||
88 | |||
89 | // create demo game | ||
90 | createLevel( 1 ); | ||
91 | } | ||
92 | |||
93 | void KJezzball::newGame() | ||
94 | { | ||
95 | // Check for running game | ||
96 | closeGame(); | ||
97 | if ( m_state==Idle ) | ||
98 | { | ||
99 | // update displays | ||
100 | m_game.level = 1; | ||
101 | m_game.score = 0; | ||
102 | |||
103 | setCaption(tr("ZBounce Level %1").arg(m_game.level)); | ||
104 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | ||
105 | |||
106 | // start new game | ||
107 | m_state = Running; | ||
108 | |||
109 | createLevel( m_game.level ); | ||
110 | startLevel(); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | void KJezzball::about() | ||
115 | { | ||
116 | QMessageBox::information( this, "About", "Written by: Stefan Schimanski\nPorted by: Martin Imobersteg\n\nThis program is distributed under\nthe terms of the GPL v2." ); | ||
117 | } | ||
118 | |||
119 | void KJezzball::closeGame() | ||
120 | { | ||
121 | if ( m_state!=Idle ) | ||
122 | { | ||
123 | stopLevel(); | ||
124 | m_state = Idle; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | void KJezzball::pauseGame() | ||
129 | { | ||
130 | switch ( m_state ) | ||
131 | { | ||
132 | case Running: | ||
133 | m_state = Paused; | ||
134 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); | ||
135 | stopLevel(); | ||
136 | break; | ||
137 | |||
138 | case Paused: | ||
139 | case Suspend: | ||
140 | m_state = Running; | ||
141 | m_gameWidget->display( QString::null ); | ||
142 | startLevel(); | ||
143 | break; | ||
144 | |||
145 | case Idle: | ||
146 | break; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | void KJezzball::gameOver() | ||
151 | { | ||
152 | stopLevel(); | ||
153 | m_gameOverTimer->start( 100, TRUE ); | ||
154 | } | ||
155 | |||
156 | |||
157 | void KJezzball::gameOverNow() | ||
158 | { | ||
159 | m_state = Idle; | ||
160 | |||
161 | QString score; | ||
162 | score.setNum( m_game.score ); | ||
163 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); | ||
164 | } | ||
165 | |||
166 | void KJezzball::focusOutEvent( QFocusEvent *ev ) | ||
167 | { | ||
168 | if ( m_state==Running ) | ||
169 | { | ||
170 | stopLevel(); | ||
171 | m_state = Suspend; | ||
172 | } | ||
173 | |||
174 | QMainWindow::focusOutEvent( ev ); | ||
175 | } | ||
176 | |||
177 | void KJezzball::focusInEvent ( QFocusEvent *ev ) | ||
178 | { | ||
179 | if ( m_state==Suspend ) | ||
180 | { | ||
181 | startLevel(); | ||
182 | m_state = Running; | ||
183 | } | ||
184 | |||
185 | QMainWindow::focusInEvent( ev ); | ||
186 | } | ||
187 | |||
188 | void KJezzball::second() | ||
189 | { | ||
190 | m_level.time--; | ||
191 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | ||
192 | if ( m_level.time<=0 ) | ||
193 | { | ||
194 | gameOver(); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | void KJezzball::died() | ||
199 | { | ||
200 | m_level.lifes--; | ||
201 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | ||
202 | if ( m_level.lifes==0 ) gameOver(); | ||
203 | } | ||
204 | |||
205 | void KJezzball::newPercent( int percent ) | ||
206 | { | ||
207 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); | ||
208 | if ( percent>=75 ) | ||
209 | { | ||
210 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); | ||
211 | nextLevel(); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | void KJezzball::createLevel( int level ) | ||
216 | { | ||
217 | // destroy old game | ||
218 | if ( m_gameWidget ) delete m_gameWidget; | ||
219 | |||
220 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); | ||
221 | |||
222 | m_gameWidget->show(); | ||
223 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); | ||
224 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); | ||
225 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); | ||
226 | |||
227 | // update displays | ||
228 | m_level.lifes = level+1; | ||
229 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | ||
230 | FilledLabel->setText( tr( "Filled: 0%" ) ); | ||
231 | |||
232 | m_level.time = (level+2)*30; | ||
233 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | ||
234 | |||
235 | m_level.score = 0; | ||
236 | } | ||
237 | |||
238 | void KJezzball::startLevel() | ||
239 | { | ||
240 | if ( m_gameWidget ) | ||
241 | { | ||
242 | m_timer->start( 1000 ); | ||
243 | m_gameWidget->start(); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | void KJezzball::stopLevel() | ||
248 | { | ||
249 | if ( m_gameWidget ) | ||
250 | { | ||
251 | m_gameWidget->stop(); | ||
252 | m_timer->stop(); | ||
253 | } | ||
254 | } | ||
255 | |||
256 | void KJezzball::nextLevel() | ||
257 | { | ||
258 | stopLevel(); | ||
259 | m_nextLevelTimer->start( 100, TRUE ); | ||
260 | } | ||
261 | |||
262 | void KJezzball::switchLevel() | ||
263 | { | ||
264 | m_game.score += m_level.score; | ||
265 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | ||
266 | |||
267 | QString score; | ||
268 | score.setNum( m_level.score ); | ||
269 | |||
270 | QString level; | ||
271 | level.setNum( m_game.level ); | ||
272 | |||
273 | QString foo = QString( | ||
274 | tr("Successfully cleared more than 75%.\n") + | ||
275 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + | ||
276 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + | ||
277 | tr("%1 points: Total score\n").arg(score) + | ||
278 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); | ||
279 | |||
280 | QMessageBox::information( this, "Success", foo ); | ||
281 | |||
282 | m_game.level++; | ||
283 | |||
284 | createLevel( m_game.level ); | ||
285 | startLevel(); | ||
286 | } | ||
287 | |||
288 | void KJezzball::keyPressEvent( QKeyEvent *ev ) | ||
289 | { | ||
290 | if ( ev->key() == Key_Space || | ||
291 | ev->key() == Key_Up || | ||
292 | ev->key() == Key_Down || | ||
293 | ev->key() == Key_Right || | ||
294 | ev->key() == Key_Left ) | ||
295 | { | ||
296 | m_gameWidget->changeCursor(); | ||
297 | } | ||
298 | else | ||
299 | { | ||
300 | ev->ignore(); | ||
301 | } | ||
302 | } | ||
diff --git a/noncore/games/zbounce/opie-zbounce.control b/noncore/games/zbounce/opie-zbounce.control deleted file mode 100644 index d419eaf..0000000 --- a/noncore/games/zbounce/opie-zbounce.control +++ b/dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | Files: bin/zbounce apps/Games/zbounce.desktop pics/zbounce/zbounce.png \ | ||
2 | pics/zbounce/arrow0000.png pics/zbounce/ball0008.png pics/zbounce/ball0018.png \ | ||
3 | pics/zbounce/arrow0001.png pics/zbounce/ball0009.png pics/zbounce/ball0019.png \ | ||
4 | pics/zbounce/ball0000.png pics/zbounce/ball0010.png pics/zbounce/ball0020.png \ | ||
5 | pics/zbounce/ball0001.png pics/zbounce/ball0011.png pics/zbounce/ball0021.png \ | ||
6 | pics/zbounce/ball0002.png pics/zbounce/ball0012.png pics/zbounce/ball0022.png \ | ||
7 | pics/zbounce/ball0003.png pics/zbounce/ball0013.png pics/zbounce/ball0023.png \ | ||
8 | pics/zbounce/ball0004.png pics/zbounce/ball0014.png pics/zbounce/ball0024.png \ | ||
9 | pics/zbounce/ball0005.png pics/zbounce/ball0015.png pics/zbounce/tiles.png \ | ||
10 | pics/zbounce/ball0006.png pics/zbounce/ball0016.png \ | ||
11 | pics/zbounce/ball0007.png pics/zbounce/ball0017.png \ | ||
12 | Version: 0.6 | ||
13 | Depends: opie-base ($QPE_VERSION) | ||
14 | Priority: optional | ||
15 | Section: opie/games | ||
16 | Maintainer: Martin Imobersteg <imm@gmx.ch> | ||
17 | Architecture: arm | ||
18 | License: GPL | ||
19 | Description: ZBounce | ||
20 | A JezzGame like game for Qtopia. | ||
diff --git a/noncore/games/zbounce/zbounce.pro b/noncore/games/zbounce/zbounce.pro deleted file mode 100644 index 9852f04..0000000 --- a/noncore/games/zbounce/zbounce.pro +++ b/dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | TEMPLATE= app | ||
2 | #CONFIG = qt warn_on debug | ||
3 | CONFIG = qt warn_on release | ||
4 | HEADERS = game.h kbounce.h | ||
5 | SOURCES = game.cpp kbounce.cpp main.cpp | ||
6 | INCLUDEPATH+= $(OPIEDIR)/include | ||
7 | DEPENDPATH+= $(OPIEDIR)/include | ||
8 | LIBS += -lqpe | ||
9 | DESTDIR = $(OPIEDIR)/bin | ||
10 | TARGET = zbounce | ||
11 | |||
12 | TRANSLATIONS = ../../../i18n/de/zbounce.ts \ | ||
13 | ../../../i18n/en/zbounce.ts \ | ||
14 | ../../../i18n/es/zbounce.ts \ | ||
15 | ../../../i18n/fr/zbounce.ts \ | ||
16 | ../../../i18n/hu/zbounce.ts \ | ||
17 | ../../../i18n/ja/zbounce.ts \ | ||
18 | ../../../i18n/ko/zbounce.ts \ | ||
19 | ../../../i18n/no/zbounce.ts \ | ||
20 | ../../../i18n/pl/zbounce.ts \ | ||
21 | ../../../i18n/pt/zbounce.ts \ | ||
22 | ../../../i18n/pt_BR/zbounce.ts \ | ||
23 | ../../../i18n/sl/zbounce.ts \ | ||
24 | ../../../i18n/zh_CN/zbounce.ts \ | ||
25 | ../../../i18n/zh_TW/zbounce.ts \ | ||
26 | ../../../i18n/it/zbounce.ts | ||