-rw-r--r-- | noncore/games/bounce/game.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/noncore/games/bounce/game.cpp b/noncore/games/bounce/game.cpp index bbd3d0b..5ef9f15 100644 --- a/noncore/games/bounce/game.cpp +++ b/noncore/games/bounce/game.cpp | |||
@@ -79,74 +79,74 @@ void Ball::update() | |||
79 | m_animDelay--; | 79 | m_animDelay--; |
80 | if ( m_animDelay<=0 ) | 80 | if ( m_animDelay<=0 ) |
81 | { | 81 | { |
82 | m_animDelay = MS2TICKS(BALL_ANIM_DELAY); | 82 | m_animDelay = MS2TICKS(BALL_ANIM_DELAY); |
83 | int frameNum = frame(); | 83 | int frameNum = frame(); |
84 | frameNum++; | 84 | frameNum++; |
85 | if ( frameNum>=frameCount() ) | 85 | if ( frameNum>=frameCount() ) |
86 | frameNum = 0; | 86 | frameNum = 0; |
87 | setFrame( frameNum ); | 87 | setFrame( frameNum ); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | void Ball::advance(int stage) | 91 | void Ball::advance(int stage) |
92 | { | 92 | { |
93 | bool reflectX = false; | 93 | bool reflectX = false; |
94 | bool reflectY = false; | 94 | bool reflectY = false; |
95 | 95 | ||
96 | // check for collisions | 96 | // check for collisions |
97 | if ( collide(xVelocity(), 0) ) reflectX = true; | 97 | if ( collide(xVelocity(), 0) ) reflectX = true; |
98 | if ( collide(0, yVelocity()) ) reflectY = true; | 98 | if ( collide(0, yVelocity()) ) reflectY = true; |
99 | if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; | 99 | if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; |
100 | 100 | ||
101 | // emit collision | 101 | // emit collision |
102 | QRect r = boundingRect(); | 102 | QRect r = boundingRect(); |
103 | r.moveBy( xVelocity(), yVelocity() ); | 103 | r.moveBy( static_cast<int>(xVelocity()), static_cast<int>( yVelocity() ) ); |
104 | JezzField* field = (JezzField *)canvas(); | 104 | JezzField* field = (JezzField *)canvas(); |
105 | 105 | ||
106 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); | 106 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); |
107 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); | 107 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); |
108 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 108 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
109 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 109 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
110 | 110 | ||
111 | if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else | 111 | if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else |
112 | if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else | 112 | if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else |
113 | if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else | 113 | if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else |
114 | if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); | 114 | if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); |
115 | 115 | ||
116 | // apply reflection | 116 | // apply reflection |
117 | if ( reflectX ) setXVelocity( -xVelocity() ); | 117 | if ( reflectX ) setXVelocity( -xVelocity() ); |
118 | if ( reflectY ) setYVelocity( -yVelocity() ); | 118 | if ( reflectY ) setYVelocity( -yVelocity() ); |
119 | 119 | ||
120 | // update field | 120 | // update field |
121 | update(); | 121 | update(); |
122 | QCanvasSprite::advance( stage ); | 122 | QCanvasSprite::advance( stage ); |
123 | } | 123 | } |
124 | 124 | ||
125 | bool Ball::collide( double dx, double dy ) | 125 | bool Ball::collide( double dx, double dy ) |
126 | { | 126 | { |
127 | QRect r = boundingRect(); | 127 | QRect r = boundingRect(); |
128 | r.moveBy( dx, dy ); | 128 | r.moveBy( static_cast<int>( dx ), static_cast<int>( dy ) ); |
129 | JezzField* field = (JezzField *)canvas(); | 129 | JezzField* field = (JezzField *)canvas(); |
130 | 130 | ||
131 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); | 131 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); |
132 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); | 132 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); |
133 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 133 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
134 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 134 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
135 | 135 | ||
136 | return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); | 136 | return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); |
137 | } | 137 | } |
138 | 138 | ||
139 | /*************************************************************************/ | 139 | /*************************************************************************/ |
140 | 140 | ||
141 | Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) | 141 | Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) |
142 | : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), | 142 | : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), |
143 | m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) | 143 | m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) |
144 | { | 144 | { |
145 | // setup position and direction | 145 | // setup position and direction |
146 | m_dx = 0; | 146 | m_dx = 0; |
147 | m_dy = 0; | 147 | m_dy = 0; |
148 | switch ( m_dir ) | 148 | switch ( m_dir ) |
149 | { | 149 | { |
150 | case Up: m_dy = -1; break; | 150 | case Up: m_dy = -1; break; |
151 | case Down: m_dy = 1; break; | 151 | case Down: m_dy = 1; break; |
152 | case Left: m_dx = -1; break; | 152 | case Left: m_dx = -1; break; |
@@ -392,49 +392,50 @@ void JezzGame::display( QString text, int size ) | |||
392 | m_text->hide(); | 392 | m_text->hide(); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | 395 | ||
396 | void JezzGame::start() | 396 | void JezzGame::start() |
397 | { | 397 | { |
398 | m_running = true; | 398 | m_running = true; |
399 | } | 399 | } |
400 | 400 | ||
401 | void JezzGame::stop() | 401 | void JezzGame::stop() |
402 | { | 402 | { |
403 | m_running = false; | 403 | m_running = false; |
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void JezzGame::makeBlack() | 407 | void JezzGame::makeBlack() |
408 | { | 408 | { |
409 | // copy current field into buffer | 409 | // copy current field into buffer |
410 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 410 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
411 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 411 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
412 | m_buf[x][y] = m_field->tile( x, y ); | 412 | m_buf[x][y] = m_field->tile( x, y ); |
413 | 413 | ||
414 | // fill areas that contains a ball | 414 | // fill areas that contains a ball |
415 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) | 415 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) |
416 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); | 416 | fill( static_cast<int>( ball->x()/TILE_SIZE ), |
417 | static_cast<int>( ball->y()/TILE_SIZE ) ); | ||
417 | 418 | ||
418 | // areas still free can be blacked now | 419 | // areas still free can be blacked now |
419 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 420 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
420 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 421 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
421 | { | 422 | { |
422 | if ( m_buf[x][y]==TILE_FREE ) | 423 | if ( m_buf[x][y]==TILE_FREE ) |
423 | m_field->setGameTile( x, y, true ); | 424 | m_field->setGameTile( x, y, true ); |
424 | } | 425 | } |
425 | 426 | ||
426 | m_field->update(); | 427 | m_field->update(); |
427 | m_view->repaint(); | 428 | m_view->repaint(); |
428 | 429 | ||
429 | // count percent value of occupied area | 430 | // count percent value of occupied area |
430 | int p = percent(); | 431 | int p = percent(); |
431 | if ( p!=m_percent ) | 432 | if ( p!=m_percent ) |
432 | { | 433 | { |
433 | m_percent = p; | 434 | m_percent = p; |
434 | emit newPercent( m_percent ); | 435 | emit newPercent( m_percent ); |
435 | } | 436 | } |
436 | } | 437 | } |
437 | 438 | ||
438 | int JezzGame::percent() | 439 | int JezzGame::percent() |
439 | { | 440 | { |
440 | int notFree = 0; | 441 | int notFree = 0; |