示例#1
0
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);
}
示例#2
0
void CannonField::timerEvent( QTimerEvent * )
{
    erase( shotRect() );
    timerCount++;

    QRect shotR = shotRect();

    if ( shotR.x() > width() || shotR.y() > height() ) {
	stopShooting();
	return;
    }	
    repaint( shotR, FALSE );
}
示例#3
0
void CannonField::paintShot(QPainter &painter)
{
  painter.setPen(Qt::NoPen);
  painter.setBrush(Qt::black);
  painter.drawRect(shotRect());
  return;
}
示例#4
0
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 );
}
示例#5
0
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();
}
示例#6
0
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 );
}
示例#7
0
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 );
}
示例#8
0
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);
}
示例#9
0
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 );
}
示例#10
0
void CannonField::paintShot( QPainter *p )
{
    p->setBrush( black );
    p->setPen( NoPen );
    p->drawRect( shotRect() );
}
示例#11
0
void Bullet::paintShot(QPainter &painter){
    cout << "paintShot" << endl;
    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::yellow);
    painter.drawRect(shotRect());
}