mirror of
https://github.com/ProgramSnail/rts_game_backend.git
synced 2026-01-25 12:57:08 +00:00
start of draw realisation
This commit is contained in:
parent
9f59ff0230
commit
8553878b4a
3 changed files with 105 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -8,4 +8,5 @@ cmake_install.cmake
|
||||||
install_manifest.txt
|
install_manifest.txt
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
_deps
|
_deps
|
||||||
|
testing
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
#include "draw.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
|
namespace draw {
|
||||||
|
|
||||||
|
enum Color {
|
||||||
|
black = 0,
|
||||||
|
red = 1,
|
||||||
|
green = 2,
|
||||||
|
yellow = 3,
|
||||||
|
blue = 4,
|
||||||
|
magneta = 5,
|
||||||
|
cyan = 6,
|
||||||
|
white = 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
void initColorPairs() {
|
||||||
|
init_pair(ColorScheme::simple, COLOR_BLACK, COLOR_WHITE);
|
||||||
|
init_pair(ColorScheme::active, COLOR_WHITE, COLOR_BLACK);
|
||||||
|
init_pair(ColorScheme::player0, COLOR_BLACK, COLOR_RED);
|
||||||
|
init_pair(ColorScheme::player1, COLOR_BLACK, COLOR_BLUE);
|
||||||
|
init_pair(ColorScheme::player2, COLOR_BLACK, COLOR_MAGENTA);
|
||||||
|
init_pair(ColorScheme::player3, COLOR_BLACK, COLOR_YELLOW);
|
||||||
|
init_pair(ColorScheme::neutral, COLOR_WHITE, COLOR_GREEN);
|
||||||
|
init_pair(ColorScheme::enviroment, COLOR_BLACK, COLOR_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
initscr();
|
||||||
|
noecho();
|
||||||
|
curs_set(false);
|
||||||
|
start_color();
|
||||||
|
initColorPairs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void step() {
|
||||||
|
refresh();
|
||||||
|
usleep(STEP_DELAY_USEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void end() {
|
||||||
|
endwin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearAll() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCh(uint32_t x, uint32_t y,
|
||||||
|
Cell cell, ColorScheme colorScheme) {
|
||||||
|
attron(COLOR_PAIR(colorScheme));
|
||||||
|
mvaddch(y, x, cell);
|
||||||
|
attroff(COLOR_PAIR(colorScheme));
|
||||||
|
}
|
||||||
|
|
||||||
|
void getSize(uint32_t& x, uint32_t& y) {
|
||||||
|
getmaxyx(stdscr, y, x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include <cstdint>
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
|
namespace draw {
|
||||||
|
|
||||||
|
enum ColorScheme {
|
||||||
|
simple,
|
||||||
|
active,
|
||||||
|
player0,
|
||||||
|
player1,
|
||||||
|
player2,
|
||||||
|
player3,
|
||||||
|
neutral,
|
||||||
|
enviroment
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Cell {
|
||||||
|
blank = ' ',
|
||||||
|
menu_h = '-',
|
||||||
|
menu_v = '|',
|
||||||
|
field = '.',
|
||||||
|
mountain = '^',
|
||||||
|
unit = '#'
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t STEP_DELAY_USEC = 30000;
|
||||||
|
|
||||||
|
void begin();
|
||||||
|
|
||||||
|
void step();
|
||||||
|
|
||||||
|
void end();
|
||||||
|
|
||||||
|
void clearAll();
|
||||||
|
|
||||||
|
void drawCh(uint32_t x, uint32_t y,
|
||||||
|
Cell cell, ColorScheme colorScheme = ColorScheme::simple);
|
||||||
|
|
||||||
|
// void setxy(uint32_t x, uint32_t y);
|
||||||
|
|
||||||
|
void getSize(uint32_t& x, uint32_t& y);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue