-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() m_animDelay--; if ( m_animDelay<=0 ) { m_animDelay = MS2TICKS(BALL_ANIM_DELAY); int frameNum = frame(); frameNum++; if ( frameNum>=frameCount() ) frameNum = 0; setFrame( frameNum ); } } void Ball::advance(int stage) { bool reflectX = false; bool reflectY = false; // check for collisions if ( collide(xVelocity(), 0) ) reflectX = true; if ( collide(0, yVelocity()) ) reflectY = true; if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; // emit collision QRect r = boundingRect(); - r.moveBy( xVelocity(), yVelocity() ); + r.moveBy( static_cast<int>(xVelocity()), static_cast<int>( yVelocity() ) ); JezzField* field = (JezzField *)canvas(); int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); // apply reflection if ( reflectX ) setXVelocity( -xVelocity() ); if ( reflectY ) setYVelocity( -yVelocity() ); // update field update(); QCanvasSprite::advance( stage ); } bool Ball::collide( double dx, double dy ) { QRect r = boundingRect(); - r.moveBy( dx, dy ); + r.moveBy( static_cast<int>( dx ), static_cast<int>( dy ) ); JezzField* field = (JezzField *)canvas(); int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); } /*************************************************************************/ Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) { // setup position and direction m_dx = 0; m_dy = 0; switch ( m_dir ) { case Up: m_dy = -1; break; case Down: m_dy = 1; break; case Left: m_dx = -1; break; @@ -392,49 +392,50 @@ void JezzGame::display( QString text, int size ) m_text->hide(); } } void JezzGame::start() { m_running = true; } void JezzGame::stop() { m_running = false; } void JezzGame::makeBlack() { // copy current field into buffer for ( int y=0; y<FIELD_HEIGHT; y++ ) for ( int x=0; x<FIELD_WIDTH; x++ ) m_buf[x][y] = m_field->tile( x, y ); // fill areas that contains a ball for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) - fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); + fill( static_cast<int>( ball->x()/TILE_SIZE ), + static_cast<int>( ball->y()/TILE_SIZE ) ); // areas still free can be blacked now for ( int y=0; y<FIELD_HEIGHT; y++ ) for ( int x=0; x<FIELD_WIDTH; x++ ) { if ( m_buf[x][y]==TILE_FREE ) m_field->setGameTile( x, y, true ); } m_field->update(); m_view->repaint(); // count percent value of occupied area int p = percent(); if ( p!=m_percent ) { m_percent = p; emit newPercent( m_percent ); } } int JezzGame::percent() { int notFree = 0; |