-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f594551
commit 9804603
Showing
24 changed files
with
685 additions
and
163 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <Hazel.h> | ||
#include "../world/World.h" | ||
|
||
class SandboxLayer : public Hazel::Layer | ||
{ | ||
public: | ||
inline SandboxLayer(World* world) : Hazel::Layer("Sandbox Layer") { m_World.reset(world); } | ||
|
||
virtual void OnAttach() override; | ||
virtual void OnDetach() override; | ||
virtual void OnUpdate() override; | ||
|
||
virtual void OnEvent(Hazel::Event* event) override; | ||
|
||
bool OnMouseMoved(Hazel::MouseMovedEvent* event); | ||
bool OnMousePressed(Hazel::MouseButtonPressedEvent* event); | ||
bool OnMouseReleased(Hazel::MouseButtonReleasedEvent* event); | ||
|
||
virtual void OnImGuiRender() override; | ||
virtual void Render() override; | ||
|
||
virtual ~SandboxLayer() override; | ||
|
||
private: | ||
Hazel::Scope<World> m_World; | ||
Body* m_SelectedBody = nullptr; | ||
Body* m_DraggedBody = nullptr; bool m_MouseDragged = false; | ||
bool m_Paused = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "Ship.h" | ||
#include "world/World.h" | ||
|
||
|
||
Part::Part(World& world, b2Vec2 pos, const Hazel::Ref<PartDef>& partDef) : m_Def(partDef), m_Animation(partDef->Animation) | ||
{ | ||
b2BodyDef def; | ||
def.position = pos; | ||
def.userData = this; | ||
def.type = b2_dynamicBody; | ||
def.active = true; | ||
m_Body = world.GetWorld()->CreateBody(&def); | ||
|
||
|
||
b2PolygonShape shape; | ||
shape.SetAsBox(partDef->Size.x / 2.0f, partDef->Size.y / 2.0f); | ||
|
||
b2FixtureDef fixtureDef; | ||
fixtureDef.shape = &shape; | ||
fixtureDef.density = partDef->Density; | ||
fixtureDef.friction = 0.2f; | ||
fixtureDef.restitution = 0.1f; | ||
b2Fixture* myFixture = m_Body->CreateFixture(&fixtureDef); | ||
} | ||
|
||
void Part::Render(const World& world) | ||
{ | ||
float x = m_Body->GetPosition().x, y = m_Body->GetPosition().y; | ||
Hazel::Renderer2D::DrawQuad( { x, y }, { m_Def->Size.x, m_Def->Size.y }, m_Animation, m_Body->GetAngle()); | ||
} | ||
|
||
void Part::Update(const World& world) | ||
{ | ||
m_Animation.Update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
#include "world/Body.h" | ||
#include "Hazel.h" | ||
|
||
#include <Hazel/Renderer2D/Animation2D.h> | ||
#include <Box2D/Box2D.h> | ||
|
||
struct PartDef { | ||
PartDef(const char* name, float density, float maxGForce, const Hazel::Ref<Hazel::AnimationDef2D> animation, float realWidth) | ||
: Name(name), Density(density), MaxGForce(maxGForce), Animation(animation) | ||
{ | ||
glm::vec2 spriteSize = { animation->m_Frames[0].Bottom - animation->m_Frames[0].Top }; | ||
Size.x = realWidth; | ||
Size.y = realWidth * (spriteSize.y / spriteSize.x); | ||
} | ||
|
||
const char* Name; | ||
float Density; | ||
float MaxGForce; | ||
glm::vec2 Size; | ||
|
||
Hazel::Ref<Hazel::AnimationDef2D> Animation; | ||
}; | ||
|
||
class Part : public Body | ||
{ | ||
public: | ||
Part(World& world, b2Vec2 pos, const Hazel::Ref<PartDef>& partDef); | ||
|
||
virtual void Render(const World& world) override; | ||
virtual void Update(const World& world) override; | ||
|
||
const Hazel::Ref<PartDef>& GetDef() { return m_Def; } | ||
|
||
virtual ~Part() {} | ||
|
||
inline void SetSelected(bool selected) { m_IsSelected = selected; } | ||
inline bool IsSelected() { return m_IsSelected; } | ||
|
||
private: | ||
Hazel::Ref<PartDef> m_Def; | ||
Hazel::Animation2D m_Animation; | ||
bool m_IsSelected = false; | ||
}; | ||
|
||
class Ship | ||
{ | ||
public: | ||
|
||
std::vector<Part>& GetParts() { return m_Parts; } | ||
|
||
private: | ||
std::vector<Part> m_Parts; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.