Skip to content

Commit

Permalink
WorldLayer done
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyNeubauer committed Dec 18, 2019
1 parent 0cd797e commit 78224ec
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
19 changes: 18 additions & 1 deletion GameDesign/src/layers/WorldLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <imgui.h>
#include <random>


WorldLayer::WorldLayer(Hazel::Ref<EditorShip>& originShip) : Hazel::Layer("World Layer"), m_Camera(new WorldCameraController())
{
m_World.reset(new World(m_Camera));
Expand Down Expand Up @@ -44,6 +43,22 @@ void WorldLayer::OnUpdate(Hazel::Timestep ts)
}

m_Camera.ForceUpdate();

Ship* ship = m_Ship.get();

m_Ship->ForEachPartIfType<EnginePart>([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)
Expand Down Expand Up @@ -173,4 +188,6 @@ void WorldCameraController::Update(Hazel::Timestep ts, Hazel::Camera2D& camera)

if (camera.m_Zoom <= 0.00001f)
camera.m_Zoom = 0.00001f;


}
18 changes: 14 additions & 4 deletions GameDesign/src/ship/Parts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<PartDef>& def = GetEditorPart()->Def;
Hazel::Renderer2D::Renderable renderable;

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions GameDesign/src/ship/Parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion GameDesign/src/world/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 78224ec

Please sign in to comment.