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