-
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.
added basic player movement for Astroids demo
- Loading branch information
Showing
17 changed files
with
320 additions
and
6 deletions.
There are no files selected for viewing
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
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,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Components"> | ||
<UniqueIdentifier>{6B7DD516-5735-1764-C03C-F0BFAC13B254}</UniqueIdentifier> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="src\Components\Component_AstroidInput.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Component_Movement.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Component_PlayerInput.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Component_Renderable.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Component_Transform.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Handler_PlayerInput.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Handler_PlayerMovement.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Handler_Renderable.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
<ClInclude Include="src\Components\Handler_UpdateTransform.h"> | ||
<Filter>Components</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="src\Astroids.cpp" /> | ||
</ItemGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Window][Debug##Default] | ||
Pos=60,60 | ||
Size=400,400 | ||
|
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
8 changes: 8 additions & 0 deletions
8
ExampleProjects/Astroids/src/Components/Component_AstroidInput.h
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,8 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
struct Component_AstroidInput | ||
{ | ||
bool enableStatusComponent = true; | ||
}; |
19 changes: 19 additions & 0 deletions
19
ExampleProjects/Astroids/src/Components/Component_Movement.h
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,19 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
struct Component_Movement | ||
{ | ||
float maxSpeed = 1.0f; | ||
float acceleration = 1.0f; | ||
|
||
float currSpeed = 0.0f; | ||
Duin::Vector2 inputDir; | ||
Duin::Vector2 prevVelocity; | ||
Duin::Vector2 currVelocity; | ||
|
||
Component_Movement() = default; | ||
Component_Movement(float maxSpeed, float acceleration) | ||
: maxSpeed(maxSpeed), acceleration(acceleration) | ||
{} | ||
}; |
8 changes: 8 additions & 0 deletions
8
ExampleProjects/Astroids/src/Components/Component_PlayerInput.h
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,8 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
struct Component_PlayerInput | ||
{ | ||
bool enableStatusComponent = true; | ||
}; |
17 changes: 17 additions & 0 deletions
17
ExampleProjects/Astroids/src/Components/Component_Renderable.h
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,17 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
#include <memory> | ||
|
||
struct Component_Renderable | ||
{ | ||
std::shared_ptr<Duin::TextureResource> texture; | ||
Duin::Vector2 size; | ||
|
||
Component_Renderable(std::shared_ptr<Duin::TextureResource> texture, Duin::Vector2 size) | ||
: texture(texture), size(size) | ||
{ | ||
texture->SetTextureSize(size); | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
ExampleProjects/Astroids/src/Components/Component_Transform.h
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,9 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
struct Component_Transform | ||
{ | ||
Duin::Vector2 prevPosition; | ||
Duin::Vector2 position; | ||
}; |
25 changes: 25 additions & 0 deletions
25
ExampleProjects/Astroids/src/Components/Handler_PlayerInput.h
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,25 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
#include "Component_PlayerInput.h" | ||
#include "Component_Movement.h" | ||
|
||
struct Handler_PlayerInput | ||
{ | ||
Duin::Registry* registry; | ||
|
||
Handler_PlayerInput() = default; | ||
Handler_PlayerInput(Duin::Registry* registry) | ||
: registry(registry) | ||
{} | ||
|
||
void Update(Duin::InputEvent e) | ||
{ | ||
auto view = registry->View<Component_PlayerInput, Component_Movement>(); | ||
for (auto [entity, c_pinput, c_movement] : view.each()) | ||
{ | ||
c_movement.inputDir = e.GetInputVector(Duin::KEY_W, Duin::KEY_S, Duin::KEY_A, Duin::KEY_D); | ||
} | ||
} | ||
}; |
27 changes: 27 additions & 0 deletions
27
ExampleProjects/Astroids/src/Components/Handler_PlayerMovement.h
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,27 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
#include "Component_PlayerInput.h" | ||
#include "Component_Movement.h" | ||
|
||
struct Handler_PlayerMovement | ||
{ | ||
Duin::Registry* registry; | ||
|
||
Handler_PlayerMovement() = default; | ||
Handler_PlayerMovement(Duin::Registry* registry) | ||
: registry(registry) | ||
{} | ||
|
||
void Update() | ||
{ | ||
auto view = registry->View<Component_PlayerInput, Component_Movement>(); | ||
for (auto [entity, c_pinput, c_movement] : view.each()) | ||
{ | ||
c_movement.prevVelocity = c_movement.currVelocity; | ||
c_movement.currVelocity += c_movement.inputDir * c_movement.acceleration; | ||
c_movement.currVelocity.LimitLength(0.0f, c_movement.maxSpeed); | ||
} | ||
} | ||
}; |
25 changes: 25 additions & 0 deletions
25
ExampleProjects/Astroids/src/Components/Handler_Renderable.h
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,25 @@ | ||
#pragma once | ||
|
||
#include <Duin.h> | ||
|
||
#include "Component_Renderable.h" | ||
#include "Component_Transform.h" | ||
|
||
struct Handler_Renderable | ||
{ | ||
Duin::Registry* registry; | ||
|
||
Handler_Renderable() = default; | ||
Handler_Renderable(Duin::Registry* registry) | ||
: registry(registry) | ||
{} | ||
|
||
void Update() | ||
{ | ||
auto view = registry->View<Component_Renderable, Component_Transform>(); | ||
for (auto [entity, c_renderable, c_transform] : view.each()) | ||
{ | ||
c_renderable.texture->Draw(c_transform.position); | ||
} | ||
} | ||
}; |
Oops, something went wrong.