예제 #1
0
파일: Coral.cpp 프로젝트: Fiercy/evoark
void CCoral::Update(float dt)
{
	CEnemy::Update(dt);

	for (unsigned int i = 0; i < modules.size(); i++)
	{
		if (modules[i])
		{
			modules[i]->Update(dt);
			if ((i == laser && target) || (i >= ability && target))
				modules[i]->Activate();
			if (modules[i]->GetType() == (int)EntityType::WarpModule)
			{
				if (target)
				{
					if (dynamic_cast<CWarpModule*>(modules[i])->isActive())
					{
						SGD::Vector dir = target->GetPosition() - position;
						dir.Normalize();
						velocity += dir * 300;
					}
				}
			}
		}
	}
	if (!modules[cockpit])
		SelfDestruct();
}
/*virtual*/ bool RotateTowardsBehavior::Update(float dt, MovingObject* toUpdate, SGD::Point wayPoint)
{


	// Vector from Object to its Waypoint
	SGD::Vector toWaypoint = wayPoint - toUpdate->GetPosition();

	toWaypoint.Normalize();
	if (toWaypoint.ComputeDotProduct(toUpdate->GetDirection()) < 0.999f)
	{
		if (toUpdate->GetDirection().ComputeSteering(toWaypoint) > 0)
			toUpdate->SetRotation(toUpdate->GetRotation() + (SGD::PI * 0.15f * dt)); //Turn left
		

		else if (toUpdate->GetDirection().ComputeSteering(toWaypoint) < 0)
			toUpdate->SetRotation(toUpdate->GetRotation() - (SGD::PI * 0.15f * dt)); //Turn right

		SGD::Vector orientation = { 0, -1 };
		orientation.Rotate(toUpdate->GetRotation());
		toUpdate->SetDirection(orientation);
		return false;
	}

	return true;

}
예제 #3
0
파일: Well.cpp 프로젝트: Fiercy/evoark
void CWell::HandleCollision(IEntity* other)
{	
	SGD::Vector dir;
	if ( tier >= 3 && (duration - timer) < 0.1f)
	{
		dir = other->GetPosition() - position;
		dir.Normalize();
		other->AddGravity(dir * strength * 2);
		EntityType type = (EntityType)other->GetType();
		if (type == EntityType::Asteroid)
		{
			CAsteroid* ast = dynamic_cast<CAsteroid*>(other);
			ast->TakeDamage(int(strength * 0.075f));
		}
		else if (type >= EntityType::Player && type <= EntityType::Coordinator)
		{
			CShip* ship = dynamic_cast<CShip*>(other);
			ship->TakeDamage(int(strength * 0.075f));
		}
		else if (type >= EntityType::BaseModule && type <= EntityType::WarpModule)
		{
			CModule* mod = dynamic_cast<CModule*>(other);
			mod->TakeDamage(int(strength * 0.075f));
		}
		return;
	}
	dir = position - other->GetPosition();
	if (dir.ComputeLength() < 1)
		dir.y += 1;
	dir.Normalize();
	//float mass = other->GetSize().width * other->GetSize().height;
	other->AddGravity(dir * strength);
}
예제 #4
0
void Radicorn::DashTowards()
{
	//TODO: make it keep going rather that stopping once it hits the target location if it hasn't anything yet!
	SGD::Vector toTarget = (Point(targetPosition.x, targetPosition.y)) - m_ptPosition;
	toTarget.Normalize();
	targetPosition = toTarget;
	toTarget *= (float)GetMoveSpeed();
	
	m_vtVelocity += toTarget;
	isMoving = true;
}
예제 #5
0
// Render
//	- draw the entity's image at its position
/*virtual*/ void Entity::Render( void )
{
	// Verify the image
	//assert( m_hImage != SGD::INVALID_HANDLE && "Entity::Render - image was not set!" );
	
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();
	
	// Get the current frame
	int frame = GetSprite()->GetCurrFrame();


	// Find the center of the image
	SGD::Vector center;
	center.x = GetSprite()->GetFrame(frame).GetFrameRect().right - GetSprite()->GetFrame(frame).GetFrameRect().left;
	center.y = GetSprite()->GetFrame(frame).GetFrameRect().bottom - GetSprite()->GetFrame(frame).GetFrameRect().top;
	center.x /= 2;
	center.y /= 2;

	// Calculate the rotation
	SGD::Vector rotate = m_vtVelocity;
	rotate.Normalize();
	float rot = SGD::Vector(0.0f, -1.0f).ComputeSteering(rotate);

	float rotation = 0;
	if(rot > 0)
		rotation = SGD::Vector(0.0f, -1.0f).ComputeAngle(rotate);
	else
		rotation = -SGD::Vector(0.0f, -1.0f).ComputeAngle(rotate);
	
	// Render
	AnimationManager::GetInstance()->Render(m_antsAnimation, m_ptPosition.x - Camera::x, m_ptPosition.y - Camera::y, rotation, center);

	// Why is this here?
	SGD::Rectangle drawRect = GetRect();
	drawRect.left -= Camera::x;
	drawRect.right -= Camera::x;
	drawRect.top -= Camera::y;
	drawRect.bottom -= Camera::y;

	// HACK: Modify the rotation
	//m_fRotation += 0.01f;

	// Draw the image

	// -- Debugging Mode --
	Game* pGame = Game::GetInstance();
	if (pGame->IsShowingRects())
		SGD::GraphicsManager::GetInstance()->DrawRectangle(drawRect, SGD::Color(128, 255, 0, 0));
}
예제 #6
0
파일: Push.cpp 프로젝트: Fiercy/evoark
void CPush::HandleCollision(IEntity* other)
{
	if (other == owner)
		return;
	SGD::Vector forward = {0,-1};
	forward.Rotate(rotation);
	SGD::Vector dir = other->GetPosition() - position;
	dir.Normalize();
	float angleBetween = dir.ComputeAngle(forward);
	if (radius < dir.ComputeAngle(forward))
	{
		return;
	}
	if (radius < SGD::PI * 2)
		dir.Rotate(angleBetween / 2);

	//float mass = other->GetSize().width * other->GetSize().height;
	other->AddGravity(dir * strength);
}
/*virtual*/ bool AlertBehavior::Update(float dt, MovingObject* toUpdate, SGD::Point wayPoint)
{
	// Vector from Object to its Waypoint
	SGD::Vector toWaypoint = wayPoint - toUpdate->GetPosition();

	if (toWaypoint.ComputeLength() < 32)
	{
		return true;
	}
	else
	{
		if (toWaypoint.ComputeLength() < 400.0f)
		{
			if (toUpdate->UpdateAttackTime(dt))
				toUpdate->Attack();
		}
		toWaypoint.Normalize();
		if (toWaypoint.ComputeDotProduct(toUpdate->GetDirection()) < 0.999f)
		{
			if (toUpdate->GetDirection().ComputeSteering(toWaypoint) > 0)
				toUpdate->SetRotation(toUpdate->GetRotation() + (SGD::PI  * dt)); //Turn left
			else if (toUpdate->GetDirection().ComputeSteering(toWaypoint) < 0)
				toUpdate->SetRotation(toUpdate->GetRotation() - (SGD::PI * dt)); //Turn right

			SGD::Vector orientation = { 0, -1 };
			orientation.Rotate(toUpdate->GetRotation());
			toUpdate->SetDirection(orientation);

			SGD::Vector newVelocity = orientation * toUpdate->GetMoveSpeed() * 1.75f;

			toUpdate->SetVelocity(newVelocity);
		}
		return false;
	}




}
예제 #8
0
/*virtual*/ void Bullet::HandleCollision(const IEntity* other) /*override*/
{
	const Character* temp = reinterpret_cast<const Character*>(other);

	if (temp && owner && owner->GetOwner() && (temp->GetIsEnemy() != owner->GetOwner()->GetIsEnemy()))
	{
		// create a hit marker to indicate damage
		SGD::Color enemyColor;
		if (temp->GetIsEnemy())
			enemyColor = SGD::Color::Yellow;
		else
			enemyColor = SGD::Color::Blue;

		// dispatch a hit marker message only if the other object actually has health
		if (temp->GetCurrHealth() > 0.f)
		{
			CreateHitMarkerMsg* msg = new CreateHitMarkerMsg((int)(GetDamage()), m_ptPosition, m_fRotation - Math::to_radians(180.f), enemyColor);
			SGD::MessageManager::GetInstance()->QueueMessage(msg);
		}
	}

	// avoid shooting yourself unless its a deflected bullet
	if ((owner->GetOwner() != temp && !deflectBullet) || (owner->GetOwner() == temp && deflectBullet))
	{

#pragma region Brawler
		const Character* testCharacter = reinterpret_cast<const Character*>(other);
		Character* testNonConstCharacter = const_cast<Character*>(testCharacter);

		// player hit by bullet 
		if (GameplayState::GetInstance()->player && testCharacter->GetLevel() >= 1)
		{
			if (testCharacter && testCharacter->GetClass() == ClassType::Brawler && testCharacter == GameplayState::GetInstance()->player->GetCharacter())
			{
				// damage player Takes
				GameplayState::GetInstance()->fBaseDamageTaken = GetDamage();
				GameplayState::GetInstance()->fPassiveDamageTaken = testNonConstCharacter->GetWeapon()->GetDamage();
			}
		}

		if (owner->GetGunType() == Weapon::GunType::chainsawLauncher && owner->GetOwner()->GetClass() == ClassType::Brawler)
		{
			if (reinterpret_cast<BuzzsawLauncher*>(owner)->GetisBrawlActive())
			{
				if (owner->GetOwner()->GetLevel() >= 21)
					owner->GetOwner()->SetCurrCooldown(owner->GetOwner()->GetCurrCoolDown() - 0.5f);
				
				if (owner->GetOwner()->GetLevel() >= 11)
					owner->GetOwner()->ModifyHealth(owner->GetOwner()->GetStat(StatType::strength)*0.35f);
			}
		}
#pragma endregion

		if (temp && owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Cyborg && owner->GetOwner()->GetLevel() >= 18 && damage >= temp->GetCurrHealth())
		{
			vector<NPC*> hits = GameplayState::GetInstance()->npcs;
			int lightning = 0;
			for (unsigned int x = 0; x < hits.size() && lightning <= 2; x++)
			{
				float length = (hits[x]->getCharacter()->GetPosition() - temp->GetPosition()).ComputeLength();
				if (length < 300.0f && hits[x]->getCharacter()->GetIsEnemy() != owner->GetOwner()->GetIsEnemy() && hits[x]->getCharacter() != temp)
				{
					hits[x]->getCharacter()->ModifyHealth(-owner->GetOwner()->GetStat(StatType::accuracy)*0.5f);
					lightning++;

					if (owner->GetOwner()->GetLevel() >= 24)
					{
						Stun* stun = new Stun(hits[x]->getCharacter());
						stun->SetDuration(1.0f);
						Radiation* rad = new Radiation(hits[x]->getCharacter());
						rad->SetStacks(5);
						hits[x]->getCharacter()->AddStatusAilment(stun);
						hits[x]->getCharacter()->AddStatusAilment(rad);
					}
				}
			}

			if (lightning > 0)
				SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->chain_lightnin);
		}

		const Character* tempEnemy = dynamic_cast<const Character*>(other);
		Character* newEnemy = const_cast<Character*>(tempEnemy);

		if (tempEnemy && owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Gunslinger && owner->GetOwner()->GetLevel() >= 24)
		{
			int theOdds = rand() % 100 + 1;
			// gunslinger passive debug code
			GameplayState::GetInstance()->nRiccochetOdds = theOdds;

			if (theOdds < 45 && tempEnemy->GetIsEnemy() != owner->GetOwner()->GetIsEnemy())
			{
				// adjust angle to aim at another enemy (see chain lightning: cyborg lv 18 - line 120)
				// instead of destroying, redirect to another (and don't destroy)
				// if no other near, destroy this
				Weapon* tempWeapon = newEnemy->GetWeapon();

				// gunslinger debug code
				for (unsigned i = 0; i < GameplayState::GetInstance()->npcs.size(); i++)
				{
					if (GameplayState::GetInstance()->npcs[i]->getCharacter() != tempEnemy)
					{
						SGD::Vector tempDiff = GameplayState::GetInstance()->npcs[i]->getCharacter()->GetPosition() - GetPosition();
						//tempDiff.Normalize();

						float tempDist = tempDiff.ComputeLength();

						if (tempDist < 300)
						{
							// calculate angle to new target
							float toTarget = atan2(tempDiff.y, tempDiff.x);

							SGD::Vector newVelocity = GetVelocity();

							// set the velocity to the newly rotated velocity
							SetVelocity(newVelocity.ComputeRotated(toTarget));
							SetRotation(toTarget);
							SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->trickShot);
							break;
						}
					}
				}
			}
		}
		if (owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Medic && owner->GetOwner()->GetLevel() >= 24 && temp && damage >= temp->GetCurrHealth()*1.2f)
		{
			vector<NPC*> hits = GameplayState::GetInstance()->npcs;
			if ((GameplayState::GetInstance()->player->GetCharacter()->GetPosition() - temp->GetPosition()).ComputeLength() < 300.0f)
			{
				GameplayState::GetInstance()->player->GetCharacter()->ModifyHealth((temp->GetHealth())*0.1f);
				Emitter* heals = GameplayState::GetInstance()->CreateEmitter("heals", (temp != nullptr));
				heals->lifeTime = 0.25f;
			}

			for (unsigned int x = 0; x < hits.size(); x++)
			{
				float length = (hits[x]->getCharacter()->GetPosition() - temp->GetPosition()).ComputeLength();
				if (length < 300.0f && !hits[x]->getCharacter()->GetIsEnemy())
				{
					hits[x]->getCharacter()->ModifyHealth((temp->GetHealth())*0.05f);
					Emitter* heals = GameplayState::GetInstance()->CreateEmitter("heals", (temp != nullptr));
					heals->lifeTime = 0.25f;
					//visual effect
				}
			}
			SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->tranfusion);
		}
		if (GetOwner()->bulType.size() == 0)
		{
			if (tempEnemy && owner && owner->GetOwner() && (tempEnemy->GetIsEnemy() != owner->GetOwner()->GetIsEnemy()))
			{
				if (critPassive)
					SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->crit_shot);

				// allocate a message to destroy this instance
				DestroyEntityMsg* msg = new DestroyEntityMsg(this);

				// dispatch destroy message
				SGD::MessageManager::GetInstance()->QueueMessage(msg);
			}
		}
		// allocate a message to destroy this instance if the bullet is not peircing
		for (unsigned int i = 0; i < GetOwner()->bulType.size(); i++)
		{
			//if its a peircing bullet, don't continue to where you delete the bullet
			if (GetOwner()->bulType[i] == BulletType::fmj || GetOwner()->bulType[i] == BulletType::FMJFTW)
			{
				break;
			}

			if (owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Gunslinger && owner->GetOwner()->GetLevel() >= 24 && GameplayState::GetInstance()->nTheOdds < 45); // do nothing
			else if (!deflectBullet && i == GetOwner()->bulType.size() - 1)
			{
				// allocate a message to destroy this instance if you make it through the entire vector of bullet types and don't find fmj or fmjftw
				DestroyEntityMsg* msg = new DestroyEntityMsg(this);

				// dispatch destroy message
				SGD::MessageManager::GetInstance()->QueueMessage(msg);
			}
		}
		deflectBullet = false;
	}

}