(NDK) Added Velocity component/system
Former-commit-id: 427b7175fbf9723fcd1d54fc279b8b70167745d4
This commit is contained in:
10
SDK/src/NDK/Components/VelocityComponent.cpp
Normal file
10
SDK/src/NDK/Components/VelocityComponent.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex VelocityComponent::componentIndex;
|
||||
}
|
||||
@@ -15,7 +15,9 @@
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
@@ -49,9 +51,11 @@ namespace Ndk
|
||||
// Composants
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
InitializeComponent<VelocityComponent>("NdkVeloc");
|
||||
|
||||
// Systèmes
|
||||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<VelocitySystem>();
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
|
||||
28
SDK/src/NDK/Systems/VelocitySystem.cpp
Normal file
28
SDK/src/NDK/Systems/VelocitySystem.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
VelocitySystem::VelocitySystem()
|
||||
{
|
||||
Requires<NodeComponent, VelocityComponent>();
|
||||
}
|
||||
|
||||
void VelocitySystem::Update(float elapsedTime)
|
||||
{
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
|
||||
|
||||
node.Move(velocity.linearVelocity * elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
SystemIndex VelocitySystem::systemIndex;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
@@ -17,6 +18,7 @@ namespace Ndk
|
||||
void World::AddDefaultSystems()
|
||||
{
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<VelocitySystem>();
|
||||
}
|
||||
|
||||
const EntityHandle& World::CreateEntity()
|
||||
|
||||
Reference in New Issue
Block a user