-rw-r--r-- | noncore/games/bounce/game.cpp | 17 |
1 files changed, 9 insertions, 8 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 @@ -21,25 +21,25 @@ /* OPIE */ #include <opie2/odebug.h> #include <qpe/qpeapplication.h> using namespace Opie::Core; /* QT */ #include <qtimer.h> /* STD */ #include <stdlib.h> -#define TILE_SIZE 9 +#define TILE_SIZE 9 #define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2)) #define TILE_FREE (TILE_FIRST + 0) #define TILE_BORDER (TILE_FIRST + 1) #define TILE_WALLEND (TILE_FIRST + 2) #define TILE_WALLUP (TILE_FIRST + 3) #define TILE_WALLDOWN (TILE_FIRST + 4) #define TILE_WALLLEFT (TILE_FIRST + 5) #define TILE_WALLRIGHT (TILE_FIRST + 6) #define GAME_DELAY 15 #define BALL_ANIM_DELAY 60 @@ -58,25 +58,25 @@ 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); @@ -91,50 +91,50 @@ void Ball::update() 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 ); } /*************************************************************************/ @@ -290,25 +290,25 @@ void JezzView::changeCursor() else { setCursor( sizeHorCursor ); } } /*************************************************************************/ JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) { - QString path = QPEApplication::qpeDir()+"pics/bounce/"; + QString path = QPEApplication::qpeDir()+"pics/bounce/"; // load gfx m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) m_ballPixmaps->image(n)->setOffset( 0, 0 ); m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) m_arrowPixmaps->image(n)->setOffset( 0, 0 ); QPixmap tiles( path + "tiles.png" ); @@ -338,25 +338,25 @@ JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) // create balls for ( int n=0; n<ballNum; n++ ) { Ball *ball = new Ball( m_ballPixmaps, m_field ); m_balls.append( ball ); ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); ball->setFrame( rand() % 25 ); ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); ball->show(); } - + // create arrow arrow = new Arrow( m_arrowPixmaps, m_field ); arrow->show(); // create text label m_text = new QCanvasText( m_field ); // create game clock m_clock = new QTimer( this ); connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); m_clock->start( GAME_DELAY ); @@ -365,25 +365,25 @@ JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) } 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; + 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(); @@ -404,25 +404,26 @@ void JezzGame::stop() } 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(); |