示例#1
0
void Player::pickup() {
	if(weaponPickup == -1) {
		currentWeaponIndex = -1;
		nextWeaponIndex = -1;
	}

	displayHealthTimer = 3.0f;

	weaponPickup++;
	healthpacks += 3;

    al_play_sample(pickupSound, 0.8f, 0.0f, 1.0f, ALLEGRO_PLAYMODE_ONCE, NULL);


	if(weaponPickup <= 2) {
		switchWeapon(weaponPickup);
	}
}
示例#2
0
文件: enemy.cpp 项目: TAhub/WPRIN
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);
		}
	}
}
示例#3
0
文件: enemy.cpp 项目: TAhub/WPRIN
void enemy::kingAI(float elapsed)
{
	unsigned int totalBossResource = (unsigned int) ((1 - healthFraction()) / (global_data->getValue(DATA_BOSSDATA, magic, 0) * 0.01f));

	switch(bossPhase)
	{
	case 0:
	case 1:
	case 2:
		if (!global_map->dialogueActive())
		{
			global_map->forceDialogue(global_data->getValue(DATA_BOSSDATA, magic, 1) + bossPhase);
			bossPhase += 1;
			if (bossPhase == 3)
			{
				switchWeapon();
				global_map->forceMusic(BOSSMUSIC);
			}
		}
		break;
	case 3:
		if (!global_map->dialogueActive())
		{
			timer += elapsed;

			if (timer > global_data->getValue(DATA_BOSSDATA, magic, 9) * 0.01f)
			{
				bossTimer = 0;
				bossProb = 0;

				//pick a phase
				if ((unsigned int) bossResource < totalBossResource)
				{
					bossResource += 1;
					bossPhase = 4;
				}
				else
				{
					if (global_map->isMultiplayer())
						bossProb = rand() % 2;
					else
						bossProb = 0;
					if (global_map->getCreature(bossProb)->dead())
						bossProb = 1 - bossProb;
					if (global_map->getCreature(bossProb)->getX() < getX())
						facingX = -1;
					else
						facingX = 1;
					if (rand() % 4 == 1)
						bossPhase = 7;
					else
						bossPhase = 5 + rand() % 2;
				}
			}
		}
		break;
	case 4:
		//summon
		{
			float bTOld = bossTimer;
			bossTimer += elapsed;
			float sPoint = global_data->getValue(DATA_BOSSDATA, magic, 2) * 0.01f;
			if (bossTimer >= sPoint && bTOld < sPoint)
			{
				//summon
				for (unsigned int i = 0; i < 2; i++)
				{
					float sX = global_data->getValue(DATA_BOSSDATA, magic, 4 + i) * 1.0f;
					float sY = global_map->getHeight() - (1 + GENERATOR_BOTTOMBORDER) * TILESIZE;
					unsigned int sTypeA = 0;
					if (bossResource > global_data->getValue(DATA_BOSSDATA, magic, 6))
						sTypeA += 1;
					global_map->summon(sX, sY, global_data->getValue(DATA_BOSSDATA, magic, 7 + sTypeA), true, true); //it's a boss so it doesn't give EXP
				}
			}
			else if (bossTimer > global_data->getValue(DATA_BOSSDATA, magic, 3) * 0.01f)
				bossPhase = 3; //back to pick phase
		}
		break;
	case 5:
		{
			//swing
			if (bossTimer == 0)
			{
				startAttack();
				creature *cr = global_map->getCreature(bossProb);
				if (abs(getX() - cr->getX()) > getMaskWidth() / 2)
					bossProb = facingX;
				else
					bossProb = 0;
				if (cr->getY() < getY())
					jump();
			}
			else if (!attacking())
				bossPhase = 3;
			
			bossTimer += elapsed;

			if (bossProb != 0)
				move(bossProb, elapsed);
		}
		break;
	case 6:
		{
			if (bossTimer == 0)
				global_map->magic(this, global_data->getValue(DATA_BOSSDATA, magic, 10), TYPE_PLAYER);
			else if (bossTimer > global_data->getValue(DATA_BOSSDATA, magic, 11) * 0.01f)
				bossPhase = 3;
			bossTimer += elapsed;
		}
		break;
	case 7:
		{
			if (bossTimer == 0)
				global_map->magic(this, global_data->getValue(DATA_BOSSDATA, magic, 12), TYPE_PLAYER);
			else if (bossTimer > global_data->getValue(DATA_BOSSDATA, magic, 13) * 0.01f)
				bossPhase = 3;
			bossTimer += elapsed;
		}
		break;
	}
}