summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Application.cpp
diff options
context:
space:
mode:
authorjjesswan <jessica_wan@brown.edu>2024-04-22 21:56:26 -0400
committerjjesswan <jessica_wan@brown.edu>2024-04-22 21:56:26 -0400
commita556b45abf18f1bd509daaf63b66b7d55e9fd291 (patch)
treebc9b8a2d184c12aee236e7f9f276a34b84ca552d /engine-ocean/Game/Application.cpp
parentcd7c76017a12bb548036571c1ff13e551369d06d (diff)
add engine version
Diffstat (limited to 'engine-ocean/Game/Application.cpp')
-rw-r--r--engine-ocean/Game/Application.cpp101
1 files changed, 101 insertions, 0 deletions
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<GameplayScreen>(m_input_map);//new GameplayScreen(m_input_map);
+ menu = std::make_shared<MenuScreen>(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<GameplayScreen>(m_input_map);//new GameplayScreen(m_input_map);
+ menu = std::make_shared<MenuScreen>(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);
+}