1 Commits

Author SHA1 Message Date
Jace 07df795cd3 Broken helicopter 2014-06-05 06:59:10 +02:00
3 changed files with 172 additions and 0 deletions
+5
View File
@@ -51,7 +51,10 @@ void GameWorld::Initialize()
BindKey(GLFW_KEY_Z, "shoot", 1.f);
BindGamepadAxis(Gamepad::Axis::RightTrigger, "shoot", 1.f);
BindGamepadAxis(Gamepad::Axis::RightTrigger, "jeep_vertical", 1.f);
BindGamepadAxis(Gamepad::Axis::RightTrigger, "normal", 1.f);
BindGamepadAxis(Gamepad::Axis::LeftTrigger, "jeep_vertical", -1.f);
BindGamepadAxis(Gamepad::Axis::LeftTrigger, "normal", -1.f);
BindKey(GLFW_KEY_X, "use", 1.f);
BindGamepadButton(Gamepad::Button::X, "use", 1.f);
@@ -443,6 +446,7 @@ void GameWorld::RegisterSystems()
m_SystemFactory.Register<Systems::FreeSteeringSystem>([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::TankSteeringSystem>([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::JeepSteeringSystem>([this]() { return new Systems::JeepSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::HelicopterSteeringSystem>([this]() { return new Systems::HelicopterSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::WheelPairSystem>([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::PhysicsSystem>([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); });
@@ -468,6 +472,7 @@ void GameWorld::AddSystems()
AddSystem<Systems::FreeSteeringSystem>();
AddSystem<Systems::TankSteeringSystem>();
AddSystem<Systems::JeepSteeringSystem>();
AddSystem<Systems::HelicopterSteeringSystem>();
AddSystem<Systems::WheelPairSystem>();
AddSystem<Systems::SoundSystem>();
AddSystem<Systems::PhysicsSystem>();
+113
View File
@@ -9,6 +9,8 @@ void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
void Systems::HelicopterSteeringSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_ESpawnVehicle, &Systems::HelicopterSteeringSystem::OnSpawnVehicle);
m_InputController = std::unique_ptr<HelicopterSteeringInputController>(new HelicopterSteeringInputController(EventBroker));
}
@@ -37,6 +39,117 @@ void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity,
}
}
bool Systems::HelicopterSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event)
{
if (event.VehicleType != "Helicopter")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
LOG_ERROR("Found no spawn points!");
return false;
}
for (auto &component : *spawnPointComponents)
{
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if (!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
// Create a tank
EntityID tank = CreateHelicopter(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(tank);
tankTransform->Position = absoluteTransform.Position + glm::vec3(0, 10, 0);
tankTransform->Orientation = absoluteTransform.Orientation * glm::angleAxis(glm::pi<float>() / 2.f, glm::vec3(0, 1, 0));
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(tank, "Camera");
if (event.PlayerID == 1)
e.ViewportFrame = "Viewport1";
else if (event.PlayerID == 2)
e.ViewportFrame = "Viewport2";
EventBroker->Publish(e);
}
return true;
}
EntityID Systems::HelicopterSteeringSystem::CreateHelicopter(int playerID)
{
auto heli = m_World->CreateEntity();
{
{
auto transform = m_World->AddComponent<Components::Transform>(heli);
transform->Position = glm::vec3(0.f, 3.f, 10.f);
auto physics = m_World->AddComponent<Components::Physics>(heli);
physics->Mass = 3000;
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
auto heliComponent = m_World->AddComponent<Components::HelicopterSteering>(heli);
auto player = m_World->AddComponent<Components::Player>(heli);
player->ID = playerID;
m_World->AddComponent<Components::Input>(heli);
m_World->AddComponent<Components::Listener>(heli);
auto health = m_World->AddComponent<Components::Health>(heli);
health->Amount = 100.f;
}
auto model = m_World->CreateEntity(heli);
{
auto transform = m_World->AddComponent<Components::Transform>(model);
transform->Orientation = glm::quat(glm::vec3(0, -glm::pi<float>() / 2.f, 0.f));
auto modelComponent = m_World->AddComponent<Components::Model>(model);
modelComponent->ModelFile = "Models/Heli/Chassi/Chassi.obj";
}
m_World->CommitEntity(model);
auto shape = m_World->CreateEntity(heli);
{
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 5.f;
box->Height = 1.8f;
box->Depth = 7.f;
}
m_World->CommitEntity(shape);
auto camera = m_World->CreateEntity(heli);
{
auto transform = m_World->AddComponent<Components::Transform>(camera);
transform->Position.z = 16.f;
transform->Position.y = 4.f;
transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f));
auto cameraComp = m_World->AddComponent<Components::Camera>(camera);
cameraComp->FarClip = 2000.f;
/*auto follow = m_World->AddComponent<Components::Follow>(cameraTower);
follow->Entity = barrel;
follow->Distance = 15.f;
follow->FollowAxis = glm::vec3(1, 1, 1);*/
m_World->SetProperty(heli, "Camera", camera);
}
m_World->CommitEntity(camera);
}
m_World->CommitEntity(heli);
return heli;
}
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnCommand(const Events::InputCommand &event)
{
if (event.Command == "horizontal")
+54
View File
@@ -3,7 +3,58 @@
#include "Components/HelicopterSteering.h"
#include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
#include "Events/SpawnVehicle.h"
#include "InputController.h"
#include "Events/TankSteer.h"
#include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
#include "Events/ApplyPointImpulse.h"
#include "Events/CreateExplosion.h"
#include "Events/Collision.h"
#include "Components/Transform.h"
#include "Components/TankSteering.h"
#include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h"
#include "Components/Physics.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Components/Model.h"
#include "Components/Team.h"
#include "Systems/TransformSystem.h"
#include "Systems/ParticleSystem.h"
#include "InputController.h"
#include "Components/Health.h"
#include "Components/TankShell.h"
#include "Components/SphereShape.h"
#include "Components/Listener.h"
#include "Components/SoundEmitter.h"
#include "Events/EnableCollisions.h"
#include "Events/DisableCollisions.h"
#include "Components/Trigger.h"
#include "Components/TriggerExplosion.h"
#include "Components/FrameTimer.h"
#include "Events/PlaySFX.h"
#include "Events/PlayBGM.h"
#include "Events/Damage.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Events/SpawnVehicle.h"
#include "Components/SpawnPoint.h"
#include "Components/Wheel.h"
#include "Components/MeshShape.h"
#include "Components/Camera.h"
#include "Components/BoxShape.h"
#include "Components/WheelPair.h"
#include "Components/Input.h"
#include "Events/SetViewportCamera.h"
#include "Events/GameOver.h"
namespace Systems
{
@@ -22,6 +73,9 @@ public:
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
EventRelay<HelicopterSteeringSystem, Events::SpawnVehicle> m_ESpawnVehicle;
bool OnSpawnVehicle(const Events::SpawnVehicle &e);
EntityID CreateHelicopter(int PlayerID);
class HelicopterSteeringInputController;
std::unique_ptr<HelicopterSteeringInputController> m_InputController;