Diffstat (limited to 'noncore/games/bounce/game.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/bounce/game.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/noncore/games/bounce/game.cpp b/noncore/games/bounce/game.cpp index c07f453..1f1f8cd 100644 --- a/noncore/games/bounce/game.cpp +++ b/noncore/games/bounce/game.cpp | |||
@@ -228,199 +228,199 @@ void Wall::fill( bool black ) | |||
228 | } | 228 | } |
229 | 229 | ||
230 | /*************************************************************************/ | 230 | /*************************************************************************/ |
231 | 231 | ||
232 | JezzField::JezzField( QPixmap tiles, QObject* parent, const char* name ) | 232 | JezzField::JezzField( QPixmap tiles, QObject* parent, const char* name ) |
233 | : QCanvas( parent, name ), m_tiles( tiles ) | 233 | : QCanvas( parent, name ), m_tiles( tiles ) |
234 | { | 234 | { |
235 | setPixmaps( tiles ); | 235 | setPixmaps( tiles ); |
236 | } | 236 | } |
237 | 237 | ||
238 | void JezzField::setGameTile( int x, int y, bool black ) | 238 | void JezzField::setGameTile( int x, int y, bool black ) |
239 | { | 239 | { |
240 | setTile( x, y, black ? TILE_BORDER : TILE_FREE ); | 240 | setTile( x, y, black ? TILE_BORDER : TILE_FREE ); |
241 | } | 241 | } |
242 | 242 | ||
243 | void JezzField::setPixmaps( QPixmap tiles ) | 243 | void JezzField::setPixmaps( QPixmap tiles ) |
244 | { | 244 | { |
245 | // create new tiles | 245 | // create new tiles |
246 | QPixmap allTiles( TILE_SIZE*(FIELD_WIDTH-2), TILE_SIZE*(FIELD_HEIGHT-1) ); | 246 | QPixmap allTiles( TILE_SIZE*(FIELD_WIDTH-2), TILE_SIZE*(FIELD_HEIGHT-1) ); |
247 | 247 | ||
248 | // handle default tiles | 248 | // handle default tiles |
249 | bitBlt( &allTiles, 0, TILE_SIZE*(FIELD_HEIGHT-2), | 249 | bitBlt( &allTiles, 0, TILE_SIZE*(FIELD_HEIGHT-2), |
250 | &tiles, 0, 0, tiles.width(), tiles.height() ); | 250 | &tiles, 0, 0, tiles.width(), tiles.height() ); |
251 | 251 | ||
252 | // load tiles into canvas | 252 | // load tiles into canvas |
253 | setTiles( allTiles, FIELD_WIDTH, FIELD_HEIGHT, TILE_SIZE, TILE_SIZE ); | 253 | setTiles( allTiles, FIELD_WIDTH, FIELD_HEIGHT, TILE_SIZE, TILE_SIZE ); |
254 | } | 254 | } |
255 | 255 | ||
256 | /*************************************************************************/ | 256 | /*************************************************************************/ |
257 | 257 | ||
258 | JezzView::JezzView(QCanvas* viewing, QWidget* parent, const char* name, WFlags f) | 258 | JezzView::JezzView(QCanvas* viewing, QWidget* parent, const char* name, WFlags f) |
259 | : QCanvasView( viewing, parent, name, f ), m_vertical( false ) | 259 | : QCanvasView( viewing, parent, name, f ), m_vertical( false ) |
260 | { | 260 | { |
261 | setResizePolicy( AutoOne ); | 261 | setResizePolicy( AutoOne ); |
262 | setHScrollBarMode( AlwaysOff ); | 262 | setHScrollBarMode( AlwaysOff ); |
263 | setVScrollBarMode( AlwaysOff ); | 263 | setVScrollBarMode( AlwaysOff ); |
264 | 264 | ||
265 | setCursor( sizeHorCursor ); | 265 | setCursor( sizeHorCursor ); |
266 | } | 266 | } |
267 | 267 | ||
268 | void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) | 268 | void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) |
269 | { | 269 | { |
270 | if ( ev->button() & LeftButton ) | 270 | if ( ev->button() & LeftButton ) |
271 | { | 271 | { |
272 | emit buildWall( ev->x()/TILE_SIZE, ev->y()/TILE_SIZE, m_vertical ); | 272 | emit buildWall( ev->x()/TILE_SIZE, ev->y()/TILE_SIZE, m_vertical ); |
273 | } | 273 | } |
274 | } | 274 | } |
275 | 275 | ||
276 | void JezzView::changeCursor() | 276 | void JezzView::changeCursor() |
277 | { | 277 | { |
278 | m_vertical = !m_vertical; | 278 | m_vertical = !m_vertical; |
279 | if ( m_vertical ) | 279 | if ( m_vertical ) |
280 | { | 280 | { |
281 | setCursor( sizeVerCursor ); | 281 | setCursor( sizeVerCursor ); |
282 | } | 282 | } |
283 | else | 283 | else |
284 | { | 284 | { |
285 | setCursor( sizeHorCursor ); | 285 | setCursor( sizeHorCursor ); |
286 | } | 286 | } |
287 | } | 287 | } |
288 | 288 | ||
289 | /*************************************************************************/ | 289 | /*************************************************************************/ |
290 | 290 | ||
291 | JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) | 291 | JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) |
292 | : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), | 292 | : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), |
293 | m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) | 293 | m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) |
294 | { | 294 | { |
295 | QString path = QPEApplication::qpeDir()+"pics/bounce/"; | 295 | QString path = QPEApplication::qpeDir()+"pics/bounce/"; |
296 | 296 | ||
297 | // load gfx | 297 | // load gfx |
298 | m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); | 298 | m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); |
299 | for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) | 299 | for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) |
300 | m_ballPixmaps->image(n)->setOffset( 0, 0 ); | 300 | m_ballPixmaps->image(n)->setOffset( 0, 0 ); |
301 | 301 | ||
302 | m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); | 302 | m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); |
303 | for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) | 303 | for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) |
304 | m_arrowPixmaps->image(n)->setOffset( 0, 0 ); | 304 | m_arrowPixmaps->image(n)->setOffset( 0, 0 ); |
305 | 305 | ||
306 | QPixmap tiles( path + "tiles.png" ); | 306 | QPixmap tiles( path + "tiles.png" ); |
307 | 307 | ||
308 | // create field | 308 | // create field |
309 | m_field = new JezzField( tiles, this, "m_field" ); | 309 | m_field = new JezzField( tiles, this, "m_field" ); |
310 | m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); | 310 | m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); |
311 | 311 | ||
312 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 312 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
313 | m_field->setTile( x, 0, TILE_BORDER ); | 313 | m_field->setTile( x, 0, TILE_BORDER ); |
314 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) | 314 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) |
315 | { | 315 | { |
316 | m_field->setTile( 0, y, TILE_BORDER ); | 316 | m_field->setTile( 0, y, TILE_BORDER ); |
317 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) | 317 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) |
318 | m_field->setTile( x, y, TILE_FREE ); | 318 | m_field->setTile( x, y, TILE_FREE ); |
319 | m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); | 319 | m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); |
320 | } | 320 | } |
321 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 321 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
322 | m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); | 322 | m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); |
323 | 323 | ||
324 | connect( m_field, SIGNAL(ballCollision(Ball *, int, int, int)), this, SLOT(ballCollision(Ball *, int, int, int)) ); | 324 | connect( m_field, SIGNAL(ballCollision(Ball*,int,int,int)), this, SLOT(ballCollision(Ball*,int,int,int)) ); |
325 | 325 | ||
326 | // create view | 326 | // create view |
327 | m_view = new JezzView( m_field, this, "m_view" ); | 327 | m_view = new JezzView( m_field, this, "m_view" ); |
328 | m_view->move( 0, 0 ); | 328 | m_view->move( 0, 0 ); |
329 | m_view->adjustSize(); | 329 | m_view->adjustSize(); |
330 | connect( m_view, SIGNAL(buildWall(int, int, bool)), this, SLOT(buildWall(int, int, bool)) ); | 330 | connect( m_view, SIGNAL(buildWall(int,int,bool)), this, SLOT(buildWall(int,int,bool)) ); |
331 | 331 | ||
332 | // create balls | 332 | // create balls |
333 | for ( int n=0; n<ballNum; n++ ) | 333 | for ( int n=0; n<ballNum; n++ ) |
334 | { | 334 | { |
335 | Ball *ball = new Ball( m_ballPixmaps, m_field ); | 335 | Ball *ball = new Ball( m_ballPixmaps, m_field ); |
336 | m_balls.append( ball ); | 336 | m_balls.append( ball ); |
337 | ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); | 337 | ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); |
338 | ball->setFrame( rand() % 25 ); | 338 | ball->setFrame( rand() % 25 ); |
339 | ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), | 339 | ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), |
340 | 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); | 340 | 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); |
341 | ball->show(); | 341 | ball->show(); |
342 | } | 342 | } |
343 | 343 | ||
344 | // create arrow | 344 | // create arrow |
345 | arrow = new Arrow( m_arrowPixmaps, m_field ); | 345 | arrow = new Arrow( m_arrowPixmaps, m_field ); |
346 | arrow->show(); | 346 | arrow->show(); |
347 | 347 | ||
348 | // create text label | 348 | // create text label |
349 | m_text = new QCanvasText( m_field ); | 349 | m_text = new QCanvasText( m_field ); |
350 | 350 | ||
351 | // create game clock | 351 | // create game clock |
352 | m_clock = new QTimer( this ); | 352 | m_clock = new QTimer( this ); |
353 | connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); | 353 | connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); |
354 | m_clock->start( GAME_DELAY ); | 354 | m_clock->start( GAME_DELAY ); |
355 | 355 | ||
356 | // setup geometry | 356 | // setup geometry |
357 | setFixedSize( m_view->size() ); | 357 | setFixedSize( m_view->size() ); |
358 | } | 358 | } |
359 | 359 | ||
360 | JezzGame::~JezzGame() | 360 | JezzGame::~JezzGame() |
361 | { | 361 | { |
362 | m_balls.clear(); | 362 | m_balls.clear(); |
363 | delete m_view; | 363 | delete m_view; |
364 | delete m_field; | 364 | delete m_field; |
365 | delete m_ballPixmaps; | 365 | delete m_ballPixmaps; |
366 | } | 366 | } |
367 | 367 | ||
368 | void JezzGame::display( QString text, int size ) | 368 | void JezzGame::display( QString text, int size ) |
369 | { | 369 | { |
370 | qDebug("This function \"display\" shouldn't be called!!!"); | 370 | qDebug("This function \"display\" shouldn't be called!!!"); |
371 | if ( !text.isEmpty() ) | 371 | if ( !text.isEmpty() ) |
372 | { | 372 | { |
373 | QFont font( "Helvetica", size, QFont::Bold ); | 373 | QFont font( "Helvetica", size, QFont::Bold ); |
374 | font.setStyleHint( QFont::Helvetica ); | 374 | font.setStyleHint( QFont::Helvetica ); |
375 | m_text->setFont( font ); | 375 | m_text->setFont( font ); |
376 | m_text->setText( text ); | 376 | m_text->setText( text ); |
377 | 377 | ||
378 | QRect size = m_text->boundingRect(); | 378 | QRect size = m_text->boundingRect(); |
379 | m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, | 379 | m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, |
380 | ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); | 380 | ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); |
381 | 381 | ||
382 | m_text->show(); | 382 | m_text->show(); |
383 | } else | 383 | } else |
384 | { | 384 | { |
385 | m_text->hide(); | 385 | m_text->hide(); |
386 | } | 386 | } |
387 | } | 387 | } |
388 | 388 | ||
389 | void JezzGame::start() | 389 | void JezzGame::start() |
390 | { | 390 | { |
391 | m_running = true; | 391 | m_running = true; |
392 | } | 392 | } |
393 | 393 | ||
394 | void JezzGame::stop() | 394 | void JezzGame::stop() |
395 | { | 395 | { |
396 | m_running = false; | 396 | m_running = false; |
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
400 | void JezzGame::makeBlack() | 400 | void JezzGame::makeBlack() |
401 | { | 401 | { |
402 | // copy current field into buffer | 402 | // copy current field into buffer |
403 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 403 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
404 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 404 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
405 | m_buf[x][y] = m_field->tile( x, y ); | 405 | m_buf[x][y] = m_field->tile( x, y ); |
406 | 406 | ||
407 | // fill areas that contains a ball | 407 | // fill areas that contains a ball |
408 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) | 408 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) |
409 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); | 409 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); |
410 | 410 | ||
411 | // areas still free can be blacked now | 411 | // areas still free can be blacked now |
412 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 412 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
413 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 413 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
414 | { | 414 | { |
415 | if ( m_buf[x][y]==TILE_FREE ) | 415 | if ( m_buf[x][y]==TILE_FREE ) |
416 | m_field->setGameTile( x, y, true ); | 416 | m_field->setGameTile( x, y, true ); |
417 | } | 417 | } |
418 | 418 | ||
419 | m_field->update(); | 419 | m_field->update(); |
420 | m_view->repaint(); | 420 | m_view->repaint(); |
421 | 421 | ||
422 | // count percent value of occupied area | 422 | // count percent value of occupied area |
423 | int p = percent(); | 423 | int p = percent(); |
424 | if ( p!=m_percent ) | 424 | if ( p!=m_percent ) |
425 | { | 425 | { |
426 | m_percent = p; | 426 | m_percent = p; |
@@ -432,174 +432,174 @@ int JezzGame::percent() | |||
432 | { | 432 | { |
433 | int notFree = 0; | 433 | int notFree = 0; |
434 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) | 434 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) |
435 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) | 435 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) |
436 | { | 436 | { |
437 | if ( m_field->tile(x,y)!=TILE_FREE ) | 437 | if ( m_field->tile(x,y)!=TILE_FREE ) |
438 | notFree++; | 438 | notFree++; |
439 | } | 439 | } |
440 | 440 | ||
441 | return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); | 441 | return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); |
442 | } | 442 | } |
443 | 443 | ||
444 | void JezzGame::fill( int x, int y ) | 444 | void JezzGame::fill( int x, int y ) |
445 | { | 445 | { |
446 | if ( m_buf[x][y]!=TILE_FREE) return; | 446 | if ( m_buf[x][y]!=TILE_FREE) return; |
447 | 447 | ||
448 | // go left | 448 | // go left |
449 | int _x=x; | 449 | int _x=x; |
450 | for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) | 450 | for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) |
451 | m_buf[_x][y] = TILE_BORDER; | 451 | m_buf[_x][y] = TILE_BORDER; |
452 | int stopx = _x; | 452 | int stopx = _x; |
453 | 453 | ||
454 | // fill above | 454 | // fill above |
455 | for ( _x=x; _x>stopx; _x-- ) | 455 | for ( _x=x; _x>stopx; _x-- ) |
456 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); | 456 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |
457 | 457 | ||
458 | // fill below | 458 | // fill below |
459 | for ( _x=x; _x>stopx; _x-- ) | 459 | for ( _x=x; _x>stopx; _x-- ) |
460 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); | 460 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); |
461 | 461 | ||
462 | // go right | 462 | // go right |
463 | for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) | 463 | for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) |
464 | m_buf[_x][y] = TILE_BORDER; | 464 | m_buf[_x][y] = TILE_BORDER; |
465 | stopx = _x; | 465 | stopx = _x; |
466 | 466 | ||
467 | // fill above | 467 | // fill above |
468 | for ( _x=x+1; _x<stopx; _x++ ) | 468 | for ( _x=x+1; _x<stopx; _x++ ) |
469 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); | 469 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |
470 | 470 | ||
471 | // fill below; | 471 | // fill below; |
472 | for ( _x=x+1; _x<stopx; _x++ ) | 472 | for ( _x=x+1; _x<stopx; _x++ ) |
473 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); | 473 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); |
474 | } | 474 | } |
475 | 475 | ||
476 | void JezzGame::ballCollision( Ball*, int, int, int tile ) | 476 | void JezzGame::ballCollision( Ball*, int, int, int tile ) |
477 | { | 477 | { |
478 | if ( tile!=TILE_BORDER && tile>TILE_FREE && tile!=TILE_WALLEND ) | 478 | if ( tile!=TILE_BORDER && tile>TILE_FREE && tile!=TILE_WALLEND ) |
479 | { | 479 | { |
480 | // stop walls | 480 | // stop walls |
481 | if ( (tile==TILE_WALLUP || tile==TILE_WALLLEFT) && m_wall1 ) | 481 | if ( (tile==TILE_WALLUP || tile==TILE_WALLLEFT) && m_wall1 ) |
482 | { | 482 | { |
483 | m_wall1->finish(); | 483 | m_wall1->finish(); |
484 | m_wall1->fill( false ); | 484 | m_wall1->fill( false ); |
485 | delete m_wall1; | 485 | delete m_wall1; |
486 | m_wall1 = 0; | 486 | m_wall1 = 0; |
487 | } | 487 | } |
488 | 488 | ||
489 | if ( (tile==TILE_WALLDOWN || tile==TILE_WALLRIGHT) && m_wall2 ) | 489 | if ( (tile==TILE_WALLDOWN || tile==TILE_WALLRIGHT) && m_wall2 ) |
490 | { | 490 | { |
491 | m_wall2->finish(); | 491 | m_wall2->finish(); |
492 | m_wall2->fill( false ); | 492 | m_wall2->fill( false ); |
493 | delete m_wall2; | 493 | delete m_wall2; |
494 | m_wall2 = 0; | 494 | m_wall2 = 0; |
495 | } | 495 | } |
496 | 496 | ||
497 | // update view | 497 | // update view |
498 | m_field->update(); | 498 | m_field->update(); |
499 | m_view->repaint(); | 499 | m_view->repaint(); |
500 | 500 | ||
501 | // send death msg | 501 | // send death msg |
502 | emit died(); | 502 | emit died(); |
503 | } | 503 | } |
504 | } | 504 | } |
505 | 505 | ||
506 | void JezzGame::buildWall( int x, int y, bool vertical ) | 506 | void JezzGame::buildWall( int x, int y, bool vertical ) |
507 | { | 507 | { |
508 | if ( !m_running ) return; | 508 | if ( !m_running ) return; |
509 | 509 | ||
510 | if ( m_field->tile(x, y)==TILE_FREE ) | 510 | if ( m_field->tile(x, y)==TILE_FREE ) |
511 | { | 511 | { |
512 | // check whether there is a ball at the moment | 512 | // check whether there is a ball at the moment |
513 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); | 513 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); |
514 | if ( cols.count()>0 ) | 514 | if ( cols.count()>0 ) |
515 | { | 515 | { |
516 | //kdDebug() << "Direct collision" << endl; | 516 | //kdDebug() << "Direct collision" << endl; |
517 | emit ballCollision( (Ball*)cols.first(), x, y, TILE_WALLUP ); | 517 | emit ballCollision( (Ball*)cols.first(), x, y, TILE_WALLUP ); |
518 | return; | 518 | return; |
519 | } | 519 | } |
520 | 520 | ||
521 | // start walls | 521 | // start walls |
522 | if ( !m_wall1 ) | 522 | if ( !m_wall1 ) |
523 | { | 523 | { |
524 | m_wall1 = new Wall( m_field, x, y, | 524 | m_wall1 = new Wall( m_field, x, y, |
525 | vertical? Wall::Up : Wall::Left, | 525 | vertical? Wall::Up : Wall::Left, |
526 | vertical? TILE_WALLUP : TILE_WALLLEFT, | 526 | vertical? TILE_WALLUP : TILE_WALLLEFT, |
527 | this, "m_wall1" ); | 527 | this, "m_wall1" ); |
528 | connect( m_wall1, SIGNAL(finished(Wall *, int)), | 528 | connect( m_wall1, SIGNAL(finished(Wall*,int)), |
529 | this, SLOT(wallFinished(Wall *, int)) ); } | 529 | this, SLOT(wallFinished(Wall*,int)) ); } |
530 | 530 | ||
531 | if ( !m_wall2 ) | 531 | if ( !m_wall2 ) |
532 | { | 532 | { |
533 | m_wall2 = new Wall( m_field, x, y, | 533 | m_wall2 = new Wall( m_field, x, y, |
534 | vertical? Wall::Down: Wall::Right, | 534 | vertical? Wall::Down: Wall::Right, |
535 | vertical? TILE_WALLDOWN : TILE_WALLRIGHT, | 535 | vertical? TILE_WALLDOWN : TILE_WALLRIGHT, |
536 | this, "m_wall2" ); | 536 | this, "m_wall2" ); |
537 | connect( m_wall2, SIGNAL(finished(Wall *, int)), | 537 | connect( m_wall2, SIGNAL(finished(Wall*,int)), |
538 | this, SLOT(wallFinished(Wall *, int)) ); | 538 | this, SLOT(wallFinished(Wall*,int)) ); |
539 | } | 539 | } |
540 | } | 540 | } |
541 | } | 541 | } |
542 | 542 | ||
543 | void JezzGame::wallFinished( Wall *wall, int tile ) | 543 | void JezzGame::wallFinished( Wall *wall, int tile ) |
544 | { | 544 | { |
545 | if ( tile==TILE_WALLEND ) | 545 | if ( tile==TILE_WALLEND ) |
546 | { | 546 | { |
547 | if ( m_wall1 ) | 547 | if ( m_wall1 ) |
548 | { | 548 | { |
549 | m_wall1->fill( false ); | 549 | m_wall1->fill( false ); |
550 | delete m_wall1; | 550 | delete m_wall1; |
551 | m_wall1 = 0; | 551 | m_wall1 = 0; |
552 | } | 552 | } |
553 | 553 | ||
554 | if ( m_wall2 ) | 554 | if ( m_wall2 ) |
555 | { | 555 | { |
556 | m_wall2->fill( false ); | 556 | m_wall2->fill( false ); |
557 | delete m_wall2; | 557 | delete m_wall2; |
558 | m_wall2 = 0; | 558 | m_wall2 = 0; |
559 | } | 559 | } |
560 | } else | 560 | } else |
561 | { | 561 | { |
562 | if ( m_wall1==wall && m_wall1 ) | 562 | if ( m_wall1==wall && m_wall1 ) |
563 | { | 563 | { |
564 | m_wall1->fill( true ); | 564 | m_wall1->fill( true ); |
565 | delete m_wall1; | 565 | delete m_wall1; |
566 | m_wall1 = 0; | 566 | m_wall1 = 0; |
567 | } | 567 | } |
568 | 568 | ||
569 | if ( m_wall2==wall && m_wall2 ) | 569 | if ( m_wall2==wall && m_wall2 ) |
570 | { | 570 | { |
571 | m_wall2->fill( true ); | 571 | m_wall2->fill( true ); |
572 | delete m_wall2; | 572 | delete m_wall2; |
573 | m_wall2 = 0; | 573 | m_wall2 = 0; |
574 | } | 574 | } |
575 | } | 575 | } |
576 | 576 | ||
577 | m_field->update(); | 577 | m_field->update(); |
578 | m_view->repaint(); | 578 | m_view->repaint(); |
579 | 579 | ||
580 | makeBlack(); | 580 | makeBlack(); |
581 | } | 581 | } |
582 | 582 | ||
583 | void JezzGame::tick() | 583 | void JezzGame::tick() |
584 | { | 584 | { |
585 | if ( m_running ) | 585 | if ( m_running ) |
586 | { | 586 | { |
587 | if ( m_field ) m_field->advance(); | 587 | if ( m_field ) m_field->advance(); |
588 | if ( m_wall1 ) m_wall1->advance(); | 588 | if ( m_wall1 ) m_wall1->advance(); |
589 | if ( m_wall2 ) m_wall2->advance(); | 589 | if ( m_wall2 ) m_wall2->advance(); |
590 | } else | 590 | } else |
591 | { | 591 | { |
592 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) | 592 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) |
593 | ball->update(); | 593 | ball->update(); |
594 | 594 | ||
595 | if ( m_field ) m_field->update(); | 595 | if ( m_field ) m_field->update(); |
596 | if ( m_wall1 ) m_wall1->update(); | 596 | if ( m_wall1 ) m_wall1->update(); |
597 | if ( m_wall2 ) m_wall2->update(); | 597 | if ( m_wall2 ) m_wall2->update(); |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | void JezzGame::changeCursor() | 601 | void JezzGame::changeCursor() |
602 | { | 602 | { |
603 | arrow->changeDirection(); | 603 | arrow->changeDirection(); |
604 | m_view->changeCursor(); | 604 | m_view->changeCursor(); |
605 | } | 605 | } |