EntityPtr EntityFactory::createAnimatedEntity(const string& path, float width, float height) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); TexturePtr texture(GCC_NEW Texture("")); shared_ptr<TextureDrawable> textureDrawable(GCC_NEW TextureDrawable(texture)); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); AnimationSystemPtr animationSystem = makeShared(mSystemManager->getSystemByType<AnimationSystem>(SystemType::ANIMATION)); AnimationSetPtr animationSet = animationSystem->createAnimationSet(path); AnimationHandlerPtr animationHandler(GCC_NEW AnimationHandler(textureDrawable, animationSet, animationSet->fps)); animationSystem->registerAnimation(entity->id, animationHandler); AnimationComponentPtr animationComponent(GCC_NEW AnimationComponent(entity->id, animationHandler)); InputSystemPtr inputSystem(makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT))); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(animationComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
const Process::Return GameInputProcess::update(const float deltaTime) { InputSystem& inputSystem(InputSystem::instance()); inputSystem.update(); if (inputSystem.hasQuit()) { StateManager& stateManager(StateManager::instance()); stateManager.remove("GameState"); stateManager.remove("MenuState"); return Process::STOP; } return Process::SUCCESS; }