-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgame.cpp
More file actions
65 lines (53 loc) · 1.81 KB
/
game.cpp
File metadata and controls
65 lines (53 loc) · 1.81 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
59
60
61
62
63
64
65
#include <iostream>
#include "barebones/main.hpp"
const char* const main_t::game_name = "TEMPLATE"; // window titles etc
class main_game_t: public main_t {
public:
main_game_t(void* platform_ptr): main_t(platform_ptr) {}
void init();
bool tick();
// debug just print state
bool on_key_down(short code);
bool on_key_up(short code);
bool on_mouse_down(int x,int y,mouse_button_t button);
bool on_mouse_up(int x,int y,mouse_button_t button);
};
void main_game_t::init() {
// e.g. create shaders, bind uniforms, make static vbos etc
}
bool main_game_t::tick() {
// move game-world forward, draw it
return true; // return false to exit program
}
main_t* main_t::create(void* platform_ptr,int argc,char** args) {
return new main_game_t(platform_ptr);
}
// pure debug code to be chopped out below:
static void print_debug_input_map(const main_t::input_key_map_t& map,const main_t::input_mouse_map_t& mouse) {
for(size_t i=0; i<map.size(); i++)
if(map[i])
std::cout << "key " << i << " down" << std::endl;
for(size_t i=0; i<mouse.size(); i++)
if(mouse[i])
std::cout << "mouse " << i << " down" << std::endl;
}
bool main_game_t::on_key_down(short code) {
std::cout << "KEY " << code << " DOWN" << std::endl;
print_debug_input_map(keys(),mouse());
return false;
}
bool main_game_t::on_key_up(short code) {
std::cout << "KEY " << code << " UP" << std::endl;
print_debug_input_map(keys(),mouse());
return false;
}
bool main_game_t::on_mouse_down(int x,int y,mouse_button_t button) {
std::cout << "MOUSE " << x << ',' << y << ',' << button << " DOWN" << std::endl;
print_debug_input_map(keys(),mouse());
return false;
}
bool main_game_t::on_mouse_up(int x,int y,mouse_button_t button) {
std::cout << "MOUSE " << x << ',' << y << ',' << button << " UP" << std::endl;
print_debug_input_map(keys(),mouse());
return false;
}