9.22 routine backup

This commit is contained in:
Isuru Samarathunga
2025-09-22 15:19:25 +05:30
parent 6a6debb0db
commit 28ca737c21
25 changed files with 585 additions and 140 deletions

View File

@ -2,6 +2,8 @@
#include <IAEngine/Input.hpp>
#include <IAEngine/Rendering/Camera.hpp>
#include <IAEngine/Components/PhysicsBody2D.hpp>
#include <IAEngine/Components/BoxCollider2D.hpp>
#include <IAEngine/Components/SpriteRenderer.hpp>
#include <IACore/File.hpp>
@ -11,12 +13,12 @@ namespace ia::iae::game
RefPtr<Scene> scene;
RefPtr<Node> g_player;
PhysicsBody2DComponent* g_playerPhysicsBody{};
VOID Game::Initialize()
{
scene = Engine::CreateScene();
scene->YSortingEnabled() = true;
Engine::ChangeScene(scene.get());
g_player = MakeRefPtr<Node>();
{
@ -32,6 +34,19 @@ namespace ia::iae::game
});
t->BakeAnimations();
}
{
g_playerPhysicsBody = g_player->AddComponent<PhysicsBody2DComponent>();
g_playerPhysicsBody->IsDynamic() = true;
const auto collider = g_player->AddComponent<BoxCollider2DComponent>();
collider->Rect() = {
0,
0,
g_player->DrawnSize().x,
g_player->DrawnSize().y/2.0f,
};
collider->IsDebugDrawEnabled() = true;
}
g_player->Tags() = NODE_TAG_PLAYER;
g_player->SetLocalPosition({200, 200});
const auto obstacle = MakeRefPtr<Node>();
@ -41,18 +56,31 @@ namespace ia::iae::game
.ShouldLoop = true,
.Keys = {
SpriteRendererComponent::AnimationKeyFrame {
.Scale = {0.5f, 0.5f},
.Scale = {3.0f, 0.5f},
.ColorOverlay = {0.75f, 0.0f, 0.0f, 1.0f}
}
},
});
t->BakeAnimations();
}
{
obstacle->AddComponent<PhysicsBody2DComponent>();
const auto collider = obstacle->AddComponent<BoxCollider2DComponent>();
collider->Rect() = {
0, 0,
obstacle->DrawnSize().x,
obstacle->DrawnSize().y
};
collider->IsDebugDrawEnabled() = true;
}
obstacle->Tags() = NODE_TAG_GROUND;
obstacle->SetLocalSortIndex(20);
obstacle->SetLocalPosition({150, 100});
obstacle->SetLocalPosition({200, 400});
//scene->AddNode(g_player);
//scene->AddNode(obstacle);
scene->AddNode(g_player);
scene->AddNode(obstacle);
Engine::ChangeScene(scene.get());
}
VOID Game::Terminate()
@ -61,6 +89,8 @@ namespace ia::iae::game
VOID Game::Update()
{
g_player->SetLocalPosition(g_player->GetLocalPosition() + Input::GetDirectionalInput());
if(Input::WasKeyPressed(Input::KEY_SPACE))
g_playerPhysicsBody->Jump(200.0f);
g_playerPhysicsBody->SetVelocityX(Input::GetDirectionalInput().x * 100.0f);
}
}