summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Application.cpp
blob: 8ebea3fc32ef48665c77272154e34b02f3a11d86 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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);
}