예제 #1
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);
}
예제 #2
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;

}
예제 #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;
	}




}