diff --git a/GameDesign/src/layers/WorldLayer.cpp b/GameDesign/src/layers/WorldLayer.cpp index e54ef70..7e2bad3 100644 --- a/GameDesign/src/layers/WorldLayer.cpp +++ b/GameDesign/src/layers/WorldLayer.cpp @@ -6,7 +6,6 @@ #include #include - WorldLayer::WorldLayer(Hazel::Ref& originShip) : Hazel::Layer("World Layer"), m_Camera(new WorldCameraController()) { m_World.reset(new World(m_Camera)); @@ -44,6 +43,22 @@ void WorldLayer::OnUpdate(Hazel::Timestep ts) } m_Camera.ForceUpdate(); + + Ship* ship = m_Ship.get(); + + m_Ship->ForEachPartIfType([ship, ts](EnginePart& part) { + float change = 0.0f; + if (Hazel::Input::IsKeyPressed(HZ_KEY_A)) change -= ts.Seconds() * 5.0f; + if (Hazel::Input::IsKeyPressed(HZ_KEY_D)) change += ts.Seconds() * 5.0f; + + if (change == 0.0f) + { + change = -part.GetGimbal() * 80.0f * ts.Seconds(); + } + part.SetGimbal(part.GetGimbal() + change); + part.SetThrottle(ship->GetThrottle()); + }); + } void WorldLayer::OnEvent(Hazel::Event* event) @@ -173,4 +188,6 @@ void WorldCameraController::Update(Hazel::Timestep ts, Hazel::Camera2D& camera) if (camera.m_Zoom <= 0.00001f) camera.m_Zoom = 0.00001f; + + } diff --git a/GameDesign/src/ship/Parts.cpp b/GameDesign/src/ship/Parts.cpp index 28aa5d2..cafac95 100644 --- a/GameDesign/src/ship/Parts.cpp +++ b/GameDesign/src/ship/Parts.cpp @@ -35,6 +35,7 @@ void Parts::Init() MK1Capsule->Resources.Maxes[ResourceType::FUEL] = 1000; MK1Capsule->Connections.Bottom = true; MK1Capsule->Connections.Left = true; + MK1Capsule->Connections.Top = true; MK1Capsule->Connections.Right = true; MK2Capsule->Resources.Maxes[ResourceType::FUEL] = 200; @@ -44,16 +45,20 @@ void Parts::Init() MK2Capsule->Connections.Right = true; Parts::MK1Engine.reset(new EnginePartDef{ "MK1 Engine", 10.0f, Hazel::AnimationDef2D::Create(RocketComponents, { 16, 0 }, { 14, 7 }), 2.5f, 20.0f }); - MK1Engine->ISP = 305.0f; + MK1Engine->ISP = 105.0f; MK1Engine->MassBurn = 10.0f; MK1Engine->Friction = 0.1f; MK1Engine->Connections.Top = true; + MK1Engine->Connections.Bottom = true; + MK1Engine->GimbalLimit = 7.5f; Parts::MK2Engine.reset(new EnginePartDef{ "MK2 Engine", 10.0f, Hazel::AnimationDef2D::Create(RocketComponents, { 16, 0 }, { 14, 7 }), 5.0f, 20.0f }); - MK2Engine->ISP = 421.0f; + MK2Engine->ISP = 161.0f; MK2Engine->MassBurn = 30.5f; MK2Engine->Friction = 0.1f; MK2Engine->Connections.Top = true; + MK2Engine->Connections.Bottom = true; + MK2Engine->GimbalLimit = 15.0f; Parts::Decoupler1.reset(new DecouplerPartDef{"Decoupler 1", 40, Hazel::AnimationDef2D::Create(RocketComponents, {48, 0}, {16, 3}), 11.0f / 3}); Decoupler1->ReleaseForce = 10.0f; @@ -125,7 +130,7 @@ void EnginePart::Update(Hazel::Timestep ts, World& world, Ship& ship) if (thrust > 0.0f) m_Emitter.SetPPS(m_Throttle * BASE_ENGINE_PPS); else m_Emitter.Stop(); - float rot = GetTotalRotation() + ship.GetRotation(); + float rot = GetTotalRotation() + ship.GetRotation() + glm::radians(m_Gimbal); glm::vec2 force = { 0.0f, thrust }; force = glm::rotate(force, rot); ship.GetPhsicsBody()->ApplyForce(v2b2(force), v2b2(partPosition), true); @@ -151,7 +156,7 @@ void EnginePart::Update(Hazel::Timestep ts, World& world, Ship& ship) void EnginePart::Render(const Hazel::Camera& camera, Ship& ship) { float shipRot = ship.GetRotation(); - float rotation = shipRot + GetTotalRotation(); + float rotation = shipRot + GetTotalRotation() + glm::radians(m_Gimbal); Hazel::Ref& def = GetEditorPart()->Def; Hazel::Renderer2D::Renderable renderable; @@ -178,6 +183,11 @@ float EnginePart::GetThrust(float massLoss) return GetExitVelocity() * massLoss; } +float EnginePart::GetGimbal() const +{ + return m_Gimbal; +} + void EnginePart::SetThrottle(float throttle) { if (throttle == 0.0f || throttle >= GetPartDef()->MinThrottle) diff --git a/GameDesign/src/ship/Parts.h b/GameDesign/src/ship/Parts.h index efca29e..aacd1c0 100644 --- a/GameDesign/src/ship/Parts.h +++ b/GameDesign/src/ship/Parts.h @@ -68,6 +68,7 @@ class EnginePart : public Part { float GetExitVelocity(); float GetThrust(float massLoss); + float GetGimbal() const; void SetThrottle(float throttle); void SetGimbal(float gimbal); @@ -79,6 +80,7 @@ class EnginePart : public Part { float m_Throttle = 0.0f; Hazel::ParticleEmitter m_Emitter; float m_Gimbal = 0.0f; + bool m_IsActive; }; struct DecouplerPartDef; diff --git a/GameDesign/src/world/Planet.cpp b/GameDesign/src/world/Planet.cpp index ce6cc7c..b0a15d8 100644 --- a/GameDesign/src/world/Planet.cpp +++ b/GameDesign/src/world/Planet.cpp @@ -23,7 +23,7 @@ Planet::Planet(World& world, float radius, float surfaceGravity, glm::vec4 groun b2FixtureDef fixtureDef; fixtureDef.density = GetDensity(surfaceGravity); - fixtureDef.friction = 8.0f; + fixtureDef.friction = 2.0f; fixtureDef.restitution = 0.01f; b2CircleShape circle;