void CannonField::moveShot() { QRegion region = shotRect(); ++timerCount; QRect shotR = shotRect(); if (shotR.intersects(targetRect())) { autoShootTimer->stop(); emit hit(); emit canShoot(true); } else if (shotR.x() > width() || shotR.y() > height() || shotR.intersects(barrierRect())) { autoShootTimer->stop(); emit missed(); emit canShoot(true); } else { region = region.unite(shotR); } update(region); }
void CannonField::timerEvent( QTimerEvent * ) { erase( shotRect() ); timerCount++; QRect shotR = shotRect(); if ( shotR.x() > width() || shotR.y() > height() ) { stopShooting(); return; } repaint( shotR, FALSE ); }
void CannonField::paintShot(QPainter &painter) { painter.setPen(Qt::NoPen); painter.setBrush(Qt::black); painter.drawRect(shotRect()); return; }
void CannonField::moveShot() { QRegion r( shotRect() ); timerCount++; QRect shotR = shotRect(); if ( shotR.intersects( targetRect() ) ) { autoShootTimer->stop(); emit hit(); emit canShoot( TRUE ); } else if ( shotR.x() > width() || shotR.y() > height() ) { autoShootTimer->stop(); emit missed(); emit canShoot( TRUE ); } else { r = r.unite( QRegion( shotR ) ); } repaint( r ); }
void CannonField::paintEvent( QPaintEvent *e ) { QRect updateR = e->rect(); QPainter p; p.begin( this ); if ( updateR.intersects( cannonRect() ) ) paintCannon( &p ); if ( shooting && updateR.intersects( shotRect() ) ) paintShot( &p ); p.end(); }
void CannonField::paintEvent( QPaintEvent *e ) { QRect updateR = e->rect(); QPainter p( this ); if ( updateR.intersects( cannonRect() ) ) paintCannon( &p ); if ( autoShootTimer->isActive() && updateR.intersects( shotRect() ) ) paintShot( &p ); if ( updateR.intersects( targetRect() ) ) paintTarget( &p ); }
void CannonField::moveShot() { QRegion r( shotRect() ); timerCount++; QRect shotR = shotRect(); if (mode==cheat_mode && timerCount>20) // when the mode equal cheat_mode , then we determine the timerCount bigger than 10 { autoShootTimer->stop(); } else if ( shotR.intersects( targetRect() ) ) { autoShootTimer->stop(); emit hit(); } else if ( shotR.x() > width() || shotR.y() > height() ) { autoShootTimer->stop(); emit missed(); } else { r = r.unite( QRegion( shotR ) ); } repaint( r ); }
void Bullet::moveShot(){ cout << "moveShot" << endl; QRegion region = shotRect(); QRect shotR = shotRect(); /*if (battleField->isHit(shotR)) return; else { region = region.united(shotR); }*/ battleField->isHit(shotR); if (battleField->invaderArmy->isHit(shotR)){ battleField->autoShootTimer->stop(); return; } else if(shotR.y() < 0){ cout << "MISSED" << endl; battleField->autoShootTimer->stop(); } else region = region.united(shotR); update(region); }
void CannonField::paintEvent( QPaintEvent *e ) { QRect updateR = e->rect(); QPainter p( this ); if ( gameEnded ) { p.setPen( black ); p.setFont( QFont( "Courier", 48, QFont::Bold ) ); p.drawText( rect(), AlignCenter, "Game Over" ); } if ( updateR.intersects( cannonRect() ) ) paintCannon( &p ); if ( isShooting() && updateR.intersects( shotRect() ) ) paintShot( &p ); if ( !gameEnded && updateR.intersects( targetRect() ) ) paintTarget( &p ); }
void CannonField::paintShot( QPainter *p ) { p->setBrush( black ); p->setPen( NoPen ); p->drawRect( shotRect() ); }
void Bullet::paintShot(QPainter &painter){ cout << "paintShot" << endl; painter.setPen(Qt::NoPen); painter.setBrush(Qt::yellow); painter.drawRect(shotRect()); }