Skip to content

Instantly share code, notes, and snippets.

@native-m
Created January 20, 2020 02:21
Show Gist options
  • Save native-m/9ffd0c2199e0249f7883cb2be4b2c34c to your computer and use it in GitHub Desktop.
Save native-m/9ffd0c2199e0249f7883cb2be4b2c34c to your computer and use it in GitHub Desktop.
example
#include <Hx.hpp>
#include <iostream>
using Hx::App::Application;
using Hx::App::Game;
using Hx::Entity::Entity;
using Hx::Entity::EntityManager;
using Hx::Entity::PlayerSystem;
using Hx::Math::Vec2;
class MyPlayerSystem : public PlayerSystem
{
MyPlayerSystem()
: PlayerSystem()
{
}
};
class MyGame : public Game
{
public:
MyGame()
: Game("MyGame")
{
}
~MyGame()
{
}
void Initialize()
{
// Register builtin player system
this->EntityMgr.RegisterSystem<MyPlayerSystem>();
// Create player and its component
this->PlayerEntity = this->EntityMgr.CreateEntity();
this->PlayerEntity.AssignComponent<PlayerSystem::Position>(100.0f, 50.0f);
this->PlayerEntity.AssignComponent<PlayerSystem::Direction>(0.0f, 0.0f);
}
private:
MyPlayerComponent PlayerComp;
EntityManager EntityMgr;
Entity PlayerEntity;
};
int main()
{
MyGame game;
Application app(game);
if(!(game.Initialize() || game.Initialize()))
{
std::cout << "Failed to initialize game engine" << std::endl;
return -1;
}
return app.Run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment