Can now add lines to ui and draw.
This commit is contained in:
parent
41db31e121
commit
3df203c588
7
game.c
7
game.c
@ -4,6 +4,7 @@
|
||||
#include "grid.h"
|
||||
#include "vect.h"
|
||||
#include "log.h"
|
||||
#include "ui.h"
|
||||
|
||||
static Grid* grid = 0;
|
||||
|
||||
@ -48,6 +49,9 @@ void initGame()
|
||||
// stdscr is screen created by initscr()
|
||||
getmaxyx(stdscr, height, width);
|
||||
|
||||
addLinei("x:", &cursor.x);
|
||||
addLinei("y:", &cursor.y);
|
||||
|
||||
grid = initGrid(width, height);
|
||||
//randomizeGrid(grid);
|
||||
cursor.x = width/2; cursor.y = height/2;
|
||||
@ -143,9 +147,6 @@ void drawLastPressed(char ch)
|
||||
|
||||
void drawCurPos()
|
||||
{
|
||||
attron(COLOR_PAIR(2));
|
||||
mvprintw(1, 0, "curpos: %i, %i", cursor.x, cursor.y);
|
||||
attroff(COLOR_PAIR(2));
|
||||
attron(COLOR_PAIR(3));
|
||||
mvaddch(cursor.y, cursor.x, ' ');
|
||||
attroff(COLOR_PAIR(3));
|
||||
|
7
main.c
7
main.c
@ -8,6 +8,7 @@
|
||||
// game
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
int main()
|
||||
@ -15,8 +16,8 @@ int main()
|
||||
// framerate of the game
|
||||
const int FRAME_RATE = 30;
|
||||
const float FRAME_TIME = 1.f/(float)FRAME_RATE;
|
||||
startLog("log.txt");
|
||||
|
||||
startLog("log.txt");
|
||||
initGame();
|
||||
|
||||
float t = 0;
|
||||
@ -27,8 +28,9 @@ int main()
|
||||
handleInput(ch);
|
||||
|
||||
drawGame();
|
||||
drawLastPressed(ch);
|
||||
//drawLastPressed(ch);
|
||||
drawCurPos();
|
||||
drawUI();
|
||||
|
||||
refresh();
|
||||
|
||||
@ -38,6 +40,7 @@ int main()
|
||||
t = (float) (clock()-start_t) / (float) CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
endUI();
|
||||
endGame();
|
||||
endLog();
|
||||
return 0;
|
||||
|
25
ui.c
25
ui.c
@ -1,5 +1,6 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <ncurses.h>
|
||||
#include "ui.h"
|
||||
|
||||
typedef struct {
|
||||
@ -11,20 +12,32 @@ static unsigned int ln_count = 0;
|
||||
|
||||
static Linei* lines = NULL;
|
||||
|
||||
void initUI()
|
||||
{
|
||||
lines = (Linei*)malloc(sizeof(Linei) * ++ln_count);
|
||||
}
|
||||
static void startUI();
|
||||
|
||||
void addLinei(char* msg, int* var)
|
||||
{
|
||||
if (!lines) return;
|
||||
if (ln_count >1) lines = realloc(lines, sizeof(Linei) * ++ln_count);
|
||||
if (!lines) startUI();
|
||||
else lines = realloc(lines, sizeof(Linei) * ++ln_count);
|
||||
Linei line = { msg, var };
|
||||
lines[ln_count-1] = line;
|
||||
}
|
||||
|
||||
void drawUI()
|
||||
{
|
||||
if (!lines) return;
|
||||
attron(COLOR_PAIR(2));
|
||||
for (int i = 0; i < ln_count; i++) {
|
||||
mvprintw(i, 0, "%s %i", lines[i].msg, *lines[i].var);
|
||||
}
|
||||
attroff(COLOR_PAIR(2));
|
||||
}
|
||||
|
||||
void endUI()
|
||||
{
|
||||
free(lines);
|
||||
}
|
||||
|
||||
static void startUI()
|
||||
{
|
||||
lines = (Linei*)malloc(sizeof(Linei) * ++ln_count);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user