From a556b45abf18f1bd509daaf63b66b7d55e9fd291 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 22 Apr 2024 21:56:26 -0400 Subject: add engine version --- engine-ocean/Game/Application.cpp | 101 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 engine-ocean/Game/Application.cpp (limited to 'engine-ocean/Game/Application.cpp') diff --git a/engine-ocean/Game/Application.cpp b/engine-ocean/Game/Application.cpp new file mode 100644 index 0000000..8ebea3f --- /dev/null +++ b/engine-ocean/Game/Application.cpp @@ -0,0 +1,101 @@ +#include "Application.h" +#include "Game/menuscreen.h" + +Application::Application() +{ + game = std::make_shared(m_input_map);//new GameplayScreen(m_input_map); + menu = std::make_shared(m_input_map); + activeScreen = game; + + createKeyInput(GLFW_KEY_M); + createKeyInput(GLFW_KEY_B); + createKeyInput(GLFW_KEY_R); + +} + + + +void Application::createKeyInput(int inputVal){ + Input input; + input.inputVal = inputVal; + m_input_map[inputVal] = input; +} + +void Application::inactivateOtherKeys(int keyVal){ + for (auto &keypair : m_input_map){ + if (keypair.second.inputVal != keyVal){ + m_input_map.at(keypair.first).isActive = false; + } + } +} + + + +void Application::update(double deltaTime){ + activeScreen->update(deltaTime); +} + +void Application::draw(){ + if (m_input_map.at(GLFW_KEY_M).isActive){ + activeScreen = menu; + } else { + activeScreen = game; + } + + activeScreen->draw(); +} + +void Application::keyEvent(int key, int action){ + switch(key){ + case GLFW_KEY_M: + if (action == GLFW_PRESS){ + inactivateOtherKeys(key); + m_input_map.at(key).isActive = true; + } + break; + case GLFW_KEY_B: + if (action == GLFW_PRESS){ + inactivateOtherKeys(key); + m_input_map.at(key).isActive = true; + } + break; + case GLFW_KEY_R: + if (action == GLFW_PRESS){ + inactivateOtherKeys(key); + m_input_map.at(key).isActive = true; + game = std::make_shared(m_input_map);//new GameplayScreen(m_input_map); + menu = std::make_shared(m_input_map); + activeScreen = game; + } + break; + default: + break; + } + + activeScreen->keyEvent(key, action); + +} + +void Application::mousePosEvent(double xpos, double ypos){ + + activeScreen->mousePosEvent(xpos, ypos); + +} + +void Application::mouseButtonEvent(int button, int action){ + activeScreen->mouseButtonEvent(button, action); + +} + +void Application::scrollEvent(double distance){ + activeScreen->scrollEvent(distance); + +} + +void Application::framebufferResizeEvent(int width, int height){ + activeScreen->framebufferResizeEvent(width, height); +} + +void Application::windowResizeEvent(int width, int height){ + activeScreen->windowResizeEvent(width, height); +} -- cgit v1.2.3-70-g09d2