Godzil %!s(int64=3) %!d(string=hai) anos
pai
achega
db1196c304
Modificáronse 3 ficheiros con 32 adicións e 1 borrados
  1. 6 1
      source/Game.cpp
  2. 23 0
      source/include/Components/RigidBody.h
  3. 3 0
      source/include/ECS.h

+ 6 - 1
source/Game.cpp

@@ -16,6 +16,9 @@
 #include <Logger.h>
 #include <ECS.h>
 
+#include <Components/Transform.h>
+#include <Components/RigidBody.h>
+
 Game::Game()
 {
     this->isRunning = false;
@@ -94,7 +97,9 @@ void Game::Run()
 void Game::Setup()
 {
     Entity tank = this->registry->createEntity();
-    Entity truck = this->registry->createEntity();
+
+    this->registry->addComponent<TransformComponent>(tank, glm::vec2(10, 30), glm::vec2(1, 1), 0);
+    this->registry->addComponent<RigidBodyComponent>(tank, glm::vec2(50, 0));
 }
 
 void Game::Update()

+ 23 - 0
source/include/Components/RigidBody.h

@@ -0,0 +1,23 @@
+/*
+ * 2D Game Engine 
+ * RigidBody.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 12/02/2021.
+ */
+
+#ifndef GAMEENGINE_RIGIDBODY_H
+#define GAMEENGINE_RIGIDBODY_H
+
+#include <glm/glm.hpp>
+
+struct RigidBodyComponent
+{
+    glm::vec2 velocity;
+
+    explicit RigidBodyComponent(glm::vec2 velocity = glm::vec2(0, 0),):velocity(velocity) {};
+};
+
+
+#endif /* GAMEENGINE_RIGIDBODY_H */

+ 3 - 0
source/include/ECS.h

@@ -18,6 +18,7 @@
 #include <typeindex>
 #include <set>
 
+#include <Logger.h>
 #include <Pool.h>
 
 const uint32_t MAX_COMPONENTS = 32;
@@ -146,6 +147,8 @@ template<typename T, typename ...TArgs> void Registry::addComponent(Entity entit
 
     componentPool->set(entityId, newComponent);
     this->entityComponentSignatures[entityId].set(componentId);
+
+    Logger::Debug("Component id#%d was added to entity id#%d", componentId, entityId);
 }
 
 template <typename T> void Registry::removeComponent(Entity entity)