-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
58 lines (50 loc) · 2.01 KB
/
Main.cpp
File metadata and controls
58 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "src/EntityManager/EntityManager.h"
#include "src/Components & Systems/Position/Movement.h"
#include "src/Shader/ShaderLoader.h"
#include "src/Timer/TimerManager.h"
#include "src/Window/Window.h"
#include "src/Components & Systems/Misc/Inventory.h"
#include "src/Components & Systems/SystemManager/SystemManager.h"
#include <print>
#include "src/Components & Systems/Rendering/Render.h"
void ProcessInput(GLFWwindow* window, const EntityManager& em, ComponentManager& cm);
int main()
{
EntityManager em;
ComponentManager cm;
GLFWwindow* window = Window::GetWindowInstance().Init(1920, 1080, "Compulsory2", cm, em);
ShaderLoader shader("ShaderSource/vertex.vert", "ShaderSource/fragment.frag");
SystemManager SM(shader.GetProgramID(),cm,em);
em.AddPlayer(glm::vec2(0.f,0.f),glm::vec2(0.2f,0.2f),glm::vec3(1.f),cm);
cm.RegisterComponent<InventoryComponent>(0);
Window::GetWindowInstance().UpdateTerminal();
while (!glfwWindowShouldClose(window))
{
TimeManager::GetInstance().Update();
glClearColor(0.f,0.5f,0.2f,1.f);
glClear(GL_COLOR_BUFFER_BIT);
ProcessInput(window,em,cm);
shader.Use();
SM.Update(TimeManager::GetInstance().GetDeltaTime());
SM.GetRenderSystem().Update(0,TimeManager::GetInstance().GetDeltaTime());
glfwSwapBuffers(window);
glfwPollEvents();
}
}
void ProcessInput(GLFWwindow* window, const EntityManager& em, ComponentManager& cm)
{
MovementSystem::ResetAllVelocities(cm);
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
glfwSetWindowShouldClose(window, true);
// Move Player 1
if (glfwGetKey(window, GLFW_KEY_D))
MovementSystem::AddVelocity(em.GetActiveEntityID(), glm::vec2(3.f, 0.f), cm);
if (glfwGetKey(window, GLFW_KEY_A))
MovementSystem::AddVelocity(em.GetActiveEntityID(), glm::vec2(-3.f, 0.f), cm);
if (glfwGetKey(window, GLFW_KEY_W))
MovementSystem::AddVelocity(em.GetActiveEntityID(), glm::vec2(0.f, 3.f), cm);
if (glfwGetKey(window, GLFW_KEY_S))
MovementSystem::AddVelocity(em.GetActiveEntityID(), glm::vec2(0.f, -3.f), cm);
}