Exemple #1
0
void World_Tests::Entity_Should_Be_Created_on_CreateEntity()
{
  World world;
  IWorldEntity* entity = world.CreateEntity("test");

  CPPUNIT_ASSERT(entity != 0);
}
Exemple #2
0
int main()
{
    World world;
    auto e = world.CreateEntity();
    e.AddComponent<PositionComponent>(100, 100);
    e.AddComponent<VelocityComponent>(10, 10);
    world.GetSystemManager().AddSystem<MoveSystem>();

    for (int i = 0; i < 10; i++) {
        world.Update();
        world.GetSystemManager().GetSystem<MoveSystem>().Update();
        auto &position = e.GetComponent<PositionComponent>();
        std::cout << "x: " << position.x << ", y: " << position.y << std::endl;
    }

    return 0;
}
Entity Create(World& inWorld, MessageBroadcaster& inMsgBroadcaster, GameData* inGameData)
{
	Entity entity = inWorld.CreateEntity();

	IVec2	startingRoomIndex	= inGameData->mDungeonMap.GetPlayerStartingRoomIndex();
	Entity	room				= inGameData->mDungeonMap.GetRoomEntities().Get(startingRoomIndex);
	IVec2	roomPosition		= room.GetComponent<PositionComponent>()->GetPosition();
	
	entity.AddComponent<AnimationComponent>();
	entity.AddComponent<CollisionComponent>();
	entity.AddComponent<HealthComponent>( inGameData->mPlayerData.mMaxHealth );
	entity.AddComponent<PlayerComponent>( &inGameData->mPlayerData );
	entity.AddComponent<OrientationComponent>( EOrientation_FaceDown );
	entity.AddComponent<PositionComponent>( roomPosition + IVec2(10, 10) );
	entity.AddComponent<RenderableComponent>();
	entity.AddComponent<TriggererComponent>();
	
	entity.AddComponent<InputHandlerComponent>()->RegisterHandler
	(
		[] (const Entity& inPlayer, const InputBuffer& inBuffer)
		{
			inPlayer.GetComponent<PlayerComponent>()->HandleInput(inBuffer);
		}
	);

	entity.AddComponent<ProgramComponent>()->RegisterProgram
	(
		[] (const Entity& inPlayer, float inFrameTime)
		{
			inPlayer.GetComponent<PlayerComponent>()->Update(inPlayer, inFrameTime);
		}
	);

	entity.AddComponent<MessageReceiverComponent>()->Register<AttackMsg>
	(
		[entity, &inMsgBroadcaster] (const AttackMsg& inAttackMsg)
		{
			entity.GetComponent<PlayerComponent>()->OnAttacked(entity, inAttackMsg, inMsgBroadcaster);
		}
	);

	return entity;
}
Exemple #4
0
Entity Create(World& inWorld, MessageBroadcaster& inMsgBroadcaster, const IVec2& inPosition)
{
	auto entity = inWorld.CreateEntity();
	
	entity.AddComponent<CollisionComponent>(kCollisionMesh);
	entity.AddComponent<PositionComponent>(inPosition);
	entity.AddComponent<RenderableComponent>(kRenderMesh);
	entity.AddComponent<TriggerBoxComponent>( IRect(1, 0, 5, 1) )->RegisterOnEnterCallback( [&] (const Entity&, const Entity& inTriggerer)
	{
		if (!inTriggerer.HasComponent<PlayerComponent>())
		{
			return;
		}

		inMsgBroadcaster.Broadcast( PlayerWentDownStairs() );
	} );

	return entity;
}
Exemple #5
0
	Console::Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance) :
	m_defaultFont(Nz::Font::GetDefault()),
	m_instance(instance),
	m_size(size),
	m_opened(false),
	m_characterSize(24)
	{
		Nz::MaterialRef backgroundMaterial = Nz::Material::New();
		backgroundMaterial->Enable(Nz::RendererParameter_Blend, true);
		backgroundMaterial->Enable(Nz::RendererParameter_DepthBuffer, false);
		backgroundMaterial->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
		backgroundMaterial->SetSrcBlend(Nz::BlendFunc_SrcAlpha);

		// History bakckground
		m_historyBackgroundSprite = Nz::Sprite::New();
		m_historyBackgroundSprite->SetColor(Nz::Color(80, 80, 160, 128));
		m_historyBackgroundSprite->SetMaterial(backgroundMaterial);

		m_historyBackground = world.CreateEntity();
		m_historyBackground->Enable(m_opened);
		m_historyBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyBackgroundSprite, -1);
		m_historyBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);

		// History
		m_historyDrawer.SetCharacterSize(m_characterSize);
		m_historyDrawer.SetColor(Nz::Color(200, 200, 200));
		m_historyDrawer.SetFont(m_defaultFont);

		m_historyTextSprite = Nz::TextSprite::New();

		m_history = world.CreateEntity();
		m_history->Enable(m_opened);
		m_history->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyTextSprite);

		Ndk::NodeComponent& historyNode = m_history->AddComponent<Ndk::NodeComponent>();
		historyNode.SetParent(this);

		// Input background
		m_inputBackgroundSprite = Nz::Sprite::New();
		m_inputBackgroundSprite->SetColor(Nz::Color(255, 255, 255, 200));
		m_inputBackgroundSprite->SetMaterial(backgroundMaterial);

		m_inputBackground = world.CreateEntity();
		m_inputBackground->Enable(m_opened);
		m_inputBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputBackgroundSprite, -1);
		m_inputBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);

		// Input
		m_inputDrawer.SetColor(Nz::Color::Black);
		m_inputDrawer.SetCharacterSize(m_characterSize);
		m_inputDrawer.SetFont(m_defaultFont);
		m_inputDrawer.SetText(s_inputPrefix);

		m_inputTextSprite = Nz::TextSprite::New();
		m_inputTextSprite->Update(m_inputDrawer);

		m_input = world.CreateEntity();
		m_input->Enable(m_opened);
		m_input->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputTextSprite);

		Ndk::NodeComponent& inputNode = m_input->AddComponent<Ndk::NodeComponent>();
		inputNode.SetParent(this);
		
		Layout();
	}