-
Notifications
You must be signed in to change notification settings - Fork 0
/
ncurses-game-engine.h
86 lines (64 loc) · 1.97 KB
/
ncurses-game-engine.h
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
#define _XOPEN_SOURCE_EXTENDED 1 // Activate wide char functionality
#include <mutex>
#include <ncurses.h>
#include <string>
#include <list>
#include <thread>
#include <atomic>
#include <condition_variable>
#define COLOR_GRAY 8
enum ColourPairs
{
PAIR_RED_BLACK = 1,
PAIR_YELLOW_BLACK,
PAIR_BLUE_BLACK,
PAIR_GREEN_BLACK,
PAIR_WHITE_BLACK,
PAIR_GRAY_BLACK,
PAIR_CYAN_BLACK,
PAIR_BLACK_WHITE
};
typedef struct _CHAR_INFO {
wchar_t utf8char;
int Attributes;
} CHAR_INFO;
struct InputNode {
int x;
int y;
int len;
std::string str;
};
class ConsoleGameEngine
{
public:
ConsoleGameEngine();
int ConstructConsole(int x, int y, int width, int height, bool border, std::string label);
virtual ~ConsoleGameEngine();
virtual void Draw(int y, int x, wchar_t wc = 0x2588, int color = PAIR_WHITE_BLACK);
void DrawWString(int x, int y, std::wstring str, int color = PAIR_WHITE_BLACK);
void DrawWStringAlpha(int x, int y, std::wstring str, int color = PAIR_WHITE_BLACK);
void print_str(std::string, int x, int y, int color = PAIR_WHITE_BLACK);
void InputString(int x, int y, int len, std::string, int color = PAIR_WHITE_BLACK);
void StartInput();
void ControlInput();
void DisplayFrame();
void Start();
int m_nProgramStatus;
protected:
std::string m_sAppName;
WINDOW *m_pWindow = nullptr;
bool m_bBorder = true;
CHAR_INFO *m_pBufferScreen = nullptr;
int m_nScreenWidth;
int m_nScreenHeight;
int m_nKeyPressed;
static std::atomic<bool> m_bAtomicActive;
static std::condition_variable m_cvGameFinished;
static std::mutex m_muxGame;
virtual bool OnUserCreate() = 0;
virtual bool OnUserUpdate(float fElapsedTime) = 0;
private:
std::list<InputNode*> m_input_list;
std::list<InputNode*>::iterator m_it;
void GameThread();
};