From 07df795cd368a0d499b6c3151cc85bc893c510fd Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 5 Jun 2014 06:59:10 +0200 Subject: [PATCH] Broken helicopter --- src/GameWorld.cpp | 5 + src/Systems/HelicopterSteeringSystem.cpp | 113 +++++++++++++++++++++++ src/Systems/HelicopterSteeringSystem.h | 54 +++++++++++ 3 files changed, 172 insertions(+) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index f0c9c8f..f00f4a0 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -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([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::JeepSteeringSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::HelicopterSteeringSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); }); @@ -468,6 +472,7 @@ void GameWorld::AddSystems() AddSystem(); AddSystem(); AddSystem(); + AddSystem(); AddSystem(); AddSystem(); AddSystem(); diff --git a/src/Systems/HelicopterSteeringSystem.cpp b/src/Systems/HelicopterSteeringSystem.cpp index 94431c2..63b1b9d 100644 --- a/src/Systems/HelicopterSteeringSystem.cpp +++ b/src/Systems/HelicopterSteeringSystem.cpp @@ -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(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(); + if (!spawnPointComponents) + { + LOG_ERROR("Found no spawn points!"); + return false; + } + + for (auto &component : *spawnPointComponents) + { + auto spawnPoint = component->Entity; + auto spawnPointComponent = std::dynamic_pointer_cast(component); + auto teamComponent = m_World->GetComponent(spawnPoint); + + if (!teamComponent) + { + LOG_ERROR("SpawnPoint has no TeamComponent"); + continue; + } + + if (teamComponent->TeamID != event.PlayerID) + continue; + + Components::Transform absoluteTransform = m_World->GetSystem()->AbsoluteTransform(spawnPoint); + + // Create a tank + EntityID tank = CreateHelicopter(event.PlayerID); + auto tankTransform = m_World->GetComponent(tank); + tankTransform->Position = absoluteTransform.Position + glm::vec3(0, 10, 0); + tankTransform->Orientation = absoluteTransform.Orientation * glm::angleAxis(glm::pi() / 2.f, glm::vec3(0, 1, 0)); + // Set the viewport correctly + Events::SetViewportCamera e; + e.CameraEntity = m_World->GetProperty(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(heli); + transform->Position = glm::vec3(0.f, 3.f, 10.f); + auto physics = m_World->AddComponent(heli); + physics->Mass = 3000; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + auto heliComponent = m_World->AddComponent(heli); + + auto player = m_World->AddComponent(heli); + player->ID = playerID; + m_World->AddComponent(heli); + m_World->AddComponent(heli); + auto health = m_World->AddComponent(heli); + health->Amount = 100.f; + } + + auto model = m_World->CreateEntity(heli); + { + auto transform = m_World->AddComponent(model); + transform->Orientation = glm::quat(glm::vec3(0, -glm::pi() / 2.f, 0.f)); + auto modelComponent = m_World->AddComponent(model); + modelComponent->ModelFile = "Models/Heli/Chassi/Chassi.obj"; + } + m_World->CommitEntity(model); + + auto shape = m_World->CreateEntity(heli); + { + auto transform = m_World->AddComponent(shape); + auto box = m_World->AddComponent(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(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(camera); + cameraComp->FarClip = 2000.f; + + + /*auto follow = m_World->AddComponent(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") diff --git a/src/Systems/HelicopterSteeringSystem.h b/src/Systems/HelicopterSteeringSystem.h index e6261be..056abc0 100644 --- a/src/Systems/HelicopterSteeringSystem.h +++ b/src/Systems/HelicopterSteeringSystem.h @@ -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 m_ESpawnVehicle; + bool OnSpawnVehicle(const Events::SpawnVehicle &e); + EntityID CreateHelicopter(int PlayerID); class HelicopterSteeringInputController; std::unique_ptr m_InputController;