Collision 1/2

This commit is contained in:
Isuru Samarathunga
2025-09-29 03:36:31 +05:30
parent 3380eb993e
commit 5f112f7531
6 changed files with 210 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include <IAEngine/Rendering/Camera.hpp>
#include <IAEngine/Rendering/DebugDraw.hpp>
#include <IAEngine/Components/SpriteRenderer.hpp>
#include <IAEngine/Components/Physics.hpp>
#include <IACore/File.hpp>
@ -12,6 +13,7 @@ namespace ia::iae::game
RefPtr<Scene> scene;
RefPtr<Node> g_player;
PhysicsComponent* g_playerPhysics;
VOID Game::Initialize()
{
@ -32,8 +34,18 @@ namespace ia::iae::game
});
t->BakeAnimations();
}
g_playerPhysics = g_player->AddComponent<PhysicsComponent>();
g_playerPhysics->AddCollider({
.IsTrigger = false,
.Position = {
0.0f, 0.0f,
},
.Size = {
25.0f, 25.0f
}
});
g_player->Tags() = NODE_TAG_PLAYER;
g_player->SetLocalPosition({200, 200});
g_player->SetLocalPosition({200, 300});
const auto obstacle = MakeRefPtr<Node>();
{
@ -42,14 +54,23 @@ namespace ia::iae::game
.ShouldLoop = true,
.Keys = {
SpriteRendererComponent::AnimationKeyFrame {
.Scale = {3.0f, 0.5f},
.Scale = {1.0f, 0.5f},
.ColorOverlay = {0.75f, 0.0f, 0.0f, 1.0f}
}
},
});
t->BakeAnimations();
}
const auto obstaclePhysics = obstacle->AddComponent<PhysicsComponent>();
obstaclePhysics->AddCollider({
.IsTrigger = false,
.Position = {
0.0f, 0.0f,
},
.Size = {
100.0f, 50.0f
}
});
obstacle->Tags() = NODE_TAG_GROUND;
obstacle->SetLocalSortIndex(20);
obstacle->SetLocalPosition({200, 400});
@ -66,5 +87,7 @@ namespace ia::iae::game
VOID Game::Update()
{
const auto d = Input::GetDirectionalInput();
g_playerPhysics->Move(d);
}
}