1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /*
- * 2D Game Engine
- * Movement.h:
- * Based on pikuma.com 2D game engine in C++ and Lua course
- * Copyright (c) 2021 986-Studio. All rights reserved.
- *
- * Created by Manoël Trapier on 11/02/2021.
- */
- #ifndef GAMEENGINE_MOVEMENT_H
- #define GAMEENGINE_MOVEMENT_H
- #include <ECS.h>
- #include <Logger.h>
- #include <Components/Transform.h>
- #include <Components/RigidBody.h>
- class MovementSystem: public System
- {
- public:
- MovementSystem()
- {
- this->requireComponent<TransformComponent>();
- this->requireComponent<RigidBodyComponent>();
- }
- void update(double deltaTime)
- {
- for (auto entity: this->getSystemEntities())
- {
- auto &transform = entity.getComponent<TransformComponent>();
- const auto rigidbody = entity.getComponent<RigidBodyComponent>();
- transform.position.x += rigidbody.velocity.x * deltaTime;
- transform.position.y += rigidbody.velocity.y * deltaTime;
- Logger::Debug("Entity id#%d - Position is now (%f, %f)",
- entity.getId(), transform.position.x, transform.position.y);
- }
- }
- };
- #endif /* GAMEENGINE_MOVEMENT_H */
|