94 lines
2.6 KiB
C++
94 lines
2.6 KiB
C++
#include <Game.hpp>
|
|
|
|
#include <IAEngine/Input.hpp>
|
|
#include <IAEngine/Rendering/Camera.hpp>
|
|
#include <IAEngine/Rendering/DebugDraw.hpp>
|
|
#include <IAEngine/Components/SpriteRenderer.hpp>
|
|
#include <IAEngine/Components/Physics.hpp>
|
|
|
|
#include <IACore/File.hpp>
|
|
|
|
namespace ia::iae::game
|
|
{
|
|
RefPtr<Scene> scene;
|
|
|
|
RefPtr<Node> g_player;
|
|
PhysicsComponent* g_playerPhysics;
|
|
|
|
VOID Game::Initialize()
|
|
{
|
|
scene = Engine::CreateScene();
|
|
scene->YSortingEnabled() = true;
|
|
|
|
g_player = MakeRefPtr<Node>();
|
|
{
|
|
const auto t = g_player->AddComponent<SpriteRendererComponent>();
|
|
t->AddAnimation({
|
|
.ShouldLoop = true,
|
|
.Keys = {
|
|
SpriteRendererComponent::AnimationKeyFrame {
|
|
.Scale = {0.25f, 0.25f},
|
|
.ColorOverlay = {0.0f, 0.75f, 0.0f, 1.0f}
|
|
}
|
|
},
|
|
});
|
|
t->BakeAnimations();
|
|
}
|
|
g_playerPhysics = g_player->AddComponent<PhysicsComponent>();
|
|
g_playerPhysics->IsDynamic() = true;
|
|
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, 300});
|
|
|
|
const auto obstacle = MakeRefPtr<Node>();
|
|
{
|
|
const auto t = obstacle->AddComponent<SpriteRendererComponent>();
|
|
t->AddAnimation({
|
|
.ShouldLoop = true,
|
|
.Keys = {
|
|
SpriteRendererComponent::AnimationKeyFrame {
|
|
.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});
|
|
|
|
scene->AddNode(g_player);
|
|
scene->AddNode(obstacle);
|
|
|
|
Engine::ChangeScene(scene.get());
|
|
}
|
|
|
|
VOID Game::Terminate()
|
|
{
|
|
}
|
|
|
|
VOID Game::Update()
|
|
{
|
|
const auto d = Input::GetDirectionalInput();
|
|
g_playerPhysics->Move(d);
|
|
}
|
|
} |