Пример #1
0
void enemy::manhackAI(float elapsed)
{
	flying = false;

	manhackTargetAcquire();

	if (!weaponMelee() && attacking() && bowDrawn())
		endAttack();

	if (target != NULL)
	{
		startAttack();
		flying = true;

		float myX = getX() + getMaskWidth() / 2;
		float theirX = target->getX() + target->getMaskWidth() / 2;

		if (theirX > myX)
			facingX = 1;
		else
			facingX = -1;

		//find the desired position
		float desiredX = target->getX() + target->getMaskWidth() / 2;
		float desiredY = target->getY() + target->getMaskHeight() / 2;
		desiredX += orbitRange * cos(angle);
		desiredY += orbitRange * sin(angle);

		if (timer >= 0) //orbit the desired position
			angle += elapsed * orbitSpeed;

		if (weaponMelee())
		{
			//handle the timer
			float oldT = timer;
			timer += elapsed * ORBITTIMERSPEED;
			if (oldT < 0 && timer >= 0)
				manhackAIOrbitDetails(); //move back out again
			else if (timer >= 1 && getY() <= target->getY())
			{
				//move in for the strike!
				timer = orbitRange * -ORBITTIMERSPEED / moveSpeed();
				orbitRange = 0;
			}
		}


		//move in that direction
		float xDif = desiredX - x;
		float yDif = desiredY - y;
		float dis = sqrt(xDif * xDif + yDif * yDif);
		if (dis <= moveSpeed() * elapsed)
		{
			x = desiredX;
			y = desiredY;
		}
		else
			flyMove(xDif / dis, yDif / dis, elapsed);
	}
}
Пример #2
0
void enemy::copterAI(float elapsed)
{
	manhackTargetAcquire();
	flying = false;

	if (attacking() && bowDrawn())
		endAttack();

	if (target != NULL)
	{
		flying = true;
		float myX = getX() + getMaskWidth() / 2;
		float theirX = target->getX() + target->getMaskWidth() / 2;
		float myY = getY() + getMaskHeight() / 2;
		float theirY = target->getY() + target->getMaskHeight() / 2;

		float xDif = abs(myX - theirX);
		float yDif = abs(myY - theirY);

		if (myX > theirX)
			facingX = -1;
		else
			facingX = 1;

		float xMove = 0;
		float yMove = 0;
		if (xDif > maxRange)
		{
			if (myX > theirX)
				xMove = -1;
			else
				xMove = 1;
		}
		else if (xDif < maxRange / 2)
		{
			if (myX > theirX)
				xMove = COPTERBACKOFF;
			else
				xMove = -COPTERBACKOFF;
		}

		if (yDif > moveSpeed() * elapsed)
		{
			if (myY > theirY)
				yMove = -1;
			else
				yMove = 1;
		}
		if (yDif < CLOSERANGE)
			startAttack();

		if (xMove != 0 || yMove != 0)
		{
			float dif = sqrt(xMove * xMove + yMove * yMove);
			flyMove(xMove / dif, yMove / dif, elapsed);
		}
	}
}
Пример #3
0
/**
 * @function Hero::Hero
 * @brief Hero constructor
 * @param parent, a pointer to this widget's parent
*/
Hero::Hero(QWidget *parent, GameplayBoard* board) :	//BEGIN field initializer list
QWidget(parent), ui(new Ui::Hero), game(board), x(200.0), y(300.0), angle(-90),
attacking(false),
body(-body_height/2.0,-body_width/2.0,body_height,body_width),
head(-head_height/2 + 1,-head_width/2,head_height,head_width)	//END Field initializer list.
{
	ui->setupUi(this);
	setFocus();	//Does this exist? Yes.
	grabKeyboard();	//For some reason this is an thing. Lets you take in keyboard stuff because it isn't done automatically
	setFocusPolicy(Qt::ClickFocus);	//In case you lose focus for some reason?

	attackTimer = new QTimer(this);	//Set a QTimer who knows about hero (Will be used for attack
	attackTimer->isSingleShot();	//Only timeout once, don't keep doing it
	QObject::connect(attackTimer, SIGNAL(timeout()), this, SLOT(endAttack()));	//Have the timer change the value of "attacking" bool at timeout
}
Пример #4
0
void enemy::archerAI(float elapsed)
{
	//archer AI

	dropMode = false;

	if (target == NULL)
		target = inRange(ACQUIRERANGE);

	forceTarget();

	if (timer > 0)
		timer -= elapsed;

	if (attacking() && !weaponMelee() && bowDrawn())
		endAttack(); //properly finish your ranged attack, even if they get out of the way

	if (target != NULL)
	{
		//switch target if necessary
		creature *iR = inRange(ACQUIRERANGE);
		if (iR != NULL)
			target = iR;

		float myX = getX() + getMaskWidth() / 2;
		float theirX = target->getX() + target->getMaskWidth() / 2;

		if (abs(theirX - myX) > maxRange)
		{
			//get into range
			if (theirX > myX)
				move(1, elapsed);
			else
				move(-1, elapsed);
		}
		else if (abs(target->getY() + target->getMaskHeight() / 2 - getY() - getMaskHeight() / 2) < CLOSERANGE && !attacking())
		{
			if (theirX > myX)
				facingX = 1;
			else
				facingX = -1;

			if (abs(theirX - myX) <= weaponReach() + getMaskWidth() / 2 - 1)
			{
				//switch to a melee weapon and attack them
				if (!weaponMelee())
					switchWeapon();

				startAttack();
			}
			else if (abs(theirX - myX) < MEDIUMRANGE)
			{
				//charge them
				if (theirX > myX)
					move(1, elapsed);
				else
					move(-1, elapsed);
			}
			else
			{
				if (magic != DATA_NONE)
				{
					if (timer <= 0)
					{
						global_map->magic(this, magic, TYPE_PLAYER); //use your magic
						timer = ARCHERFREQUENCY;
					}
				}
				else
				{
					//switch to a ranged weapon, and shoot it
					if (weaponMelee())
						switchWeapon();

					startAttack();
				}
			}
		}
		else if (canJump && target->grounded())
		{
			if (target->getY() > y + CLOSERANGE)
				dropMode = true;
			else if (target->getY() < y - CLOSERANGE)
				jump(BIGJUMP);
		}
	}
}