-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 @@ -55,122 +55,122 @@ Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas) } void Arrow::update() { if ( m_vertical ) setFrame( 0 ); else setFrame( 1 ); } void Arrow::changeDirection() { m_vertical = ! m_vertical; update(); } Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas) : QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 ) { } 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; case Right: m_dx = 1; break; } m_x = m_startX; m_y = m_startY; m_field->setTile( m_x, m_y, m_tile ); } void Wall::finish() { m_active = false; } bool Wall::isFree( int x, int y ) { if ( m_field->tile(x, y)==TILE_FREE ) { // check whether there is a ball at the moment QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); if ( cols.count()==0 ) return true; } @@ -368,97 +368,98 @@ JezzGame::~JezzGame() { m_balls.clear(); delete m_view; delete m_field; delete m_ballPixmaps; } void JezzGame::display( QString text, int size ) { odebug << "This function \"display\" shouldn't be called!!!" << oendl; if ( !text.isEmpty() ) { QFont font( "Helvetica", size, QFont::Bold ); font.setStyleHint( QFont::Helvetica ); m_text->setFont( font ); m_text->setText( text ); QRect size = m_text->boundingRect(); m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); m_text->show(); } else { 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; for ( int y=1; y<FIELD_HEIGHT-1; y++ ) for ( int x=1; x<FIELD_WIDTH-1; x++ ) { if ( m_field->tile(x,y)!=TILE_FREE ) notFree++; } return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); } void JezzGame::fill( int x, int y ) { if ( m_buf[x][y]!=TILE_FREE) return; // go left int _x=x; for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) m_buf[_x][y] = TILE_BORDER; int stopx = _x; // fill above for ( _x=x; _x>stopx; _x-- ) if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |