void HuntingMonsterManage::op_dealCollision(ArrowUnit& arrow) //bool 返回,true 表示撞到了,那么对于 arrowManage 可以去掉此 arrow 了。//arrow 的所有效果都在另一侧制造。
{
    //在这里处理 箭与怪物的碰撞
    //炸弹在 与地板碰撞处理,其它的箭也会与地板处理(要消失!)
    //这里的碰撞的难点在于对于穿透箭的处理。
    for (auto iter = _monsters.begin(); iter != _monsters.end(); ) {
        if ((*iter)->isDead() ){
            iter = _monsters.erase(iter);
        } else {
            iter++;
        }
    }

    for (auto mon : _monsters) {
        mon->op_dealWithArrow(arrow);
    }
    for (auto iter = _monsters.begin(); iter != _monsters.end(); ) {
        if ((*iter)->isDead() ){
            iter = _monsters.erase(iter);
        } else {
            iter++;
        }
    }
    if (arrow._leftHitTimes > 0) {
        groundCollision(arrow);//地板测试
    }
}
Exemple #2
0
void CGame::update()
{
	switch (gamestate)
	{
	case GAME:
		handleEvents();
		plane.move();
		plane.setCamera();

		enemyMovement();
		collideShellsWithEnemies();
		collideShellsWithPowerups();
		powerupsCollision();
		handleEnemyShots();

		if (groundCollision(plane.getBox()) || enemyCollision(plane.getBox()) || collidePlaneWithEnemyShells() || (plane.getFuel() == 0))
		{
			plane.removeLife(); resetLevel();
		}
		if (plane.getLives() == 0)
		{
			gameOverHandler();
			gamestate = GAMEOVER;
		}
		break;
	case START:
		handleMenuEvents();
		break;
	case GAMEOVER:
		handleMenuEvents();
		break;
	}
}
void CEnemyObject::UpdateEnemy(CVector2D& gravity, float deltaTics)
{
	if(CSimpleAI::TurnArround(CImageObject::_imagePos))
	{
		CImageObject::_velocity.InvertX();
	}
	if(CSimpleAI::JumpCharacter())
	{
		CImageObject::setVelocityY(-getJumpForce());
	}


	CImageObject::ApplyGravitation(gravity, deltaTics);

	CImageObject::UpdatePosition(deltaTics);
	
	groundCollision();
}
Exemple #4
0
void CGame::enemyMovement()
{
	for (std::list<std::unique_ptr<CEnemy>>::iterator it = enemyList.begin(); it != enemyList.end(); it++)
	{
		if ( (*it)->isAlive() && (*it)->isMoving() && checkCollision(plane.getCamera(), (*it)->getBox()))
		{
			(*it)->move();
			if ((*it)->type != FIGHTER && (*it)->type != MOVING_TANK && groundCollision((*it)->getBox()))
			{
				(*it)->switchDirection();
			}
			if ((*it)->type == FIGHTER)
			{
				if ((*it)->getBox().x >= LEVEL_WIDTH)
					(*it)->box.x = 0;
			}
			if ((*it)->type == MOVING_TANK)
			{
				if ((*it)->getBox().x > 650)
				{
					(*it)->switchDirection();
				}
				if ((*it)->getBox().x < 150)
				{
					(*it)->switchDirection();
				}
				//check collision with collapsing bridge
				if (standingOnCollapsingBridge((*it)->getBox()))
				{
					//kill tank if standing on brigde
					(*it)->kill();
					updateScoreTexture(2000);
				}
				//immobilise tank if bridge is dead
				if (bridgeDead())
				{
					(*it)->switchMovementOn(0);
				}
			}
		}
	}
}