Testing mostly
This commit is contained in:
@ -21,50 +21,32 @@ void testMapInit(map_t *map) {
|
||||
entityPositionSet(npc, 10, 10);
|
||||
|
||||
tile_t tiles[42 * 42];
|
||||
memset(tiles, 0, sizeof(tiles));
|
||||
for(uint32_t i = 0; i < 42 * 42; i++) {
|
||||
tiles[i].id = TILE_ID_GRASS;
|
||||
}
|
||||
|
||||
tiles[0].id = TILE_ID_GRASS;
|
||||
tiles[1].id = TILE_ID_GRASS;
|
||||
tiles[2].id = TILE_ID_GRASS;
|
||||
tiles[3].id = TILE_ID_GRASS;
|
||||
tiles[4].id = TILE_ID_GRASS;
|
||||
tiles[5].id = TILE_ID_GRASS;
|
||||
tiles[6].id = TILE_ID_GRASS;
|
||||
tiles[7].id = TILE_ID_GRASS;
|
||||
tiles[8].id = TILE_ID_GRASS;
|
||||
tiles[9].id = TILE_ID_GRASS;
|
||||
tiles[10].id = TILE_ID_GRASS;
|
||||
tiles[11].id = TILE_ID_WATER;
|
||||
tiles[12].id = TILE_ID_WATER;
|
||||
tiles[13].id = TILE_ID_WATER;
|
||||
tiles[14].id = TILE_ID_WATER;
|
||||
tiles[15].id = TILE_ID_WATER;
|
||||
tiles[16].id = TILE_ID_GRASS;
|
||||
tiles[17].id = TILE_ID_GRASS;
|
||||
tiles[18].id = TILE_ID_GRASS;
|
||||
tiles[19].id = TILE_ID_GRASS;
|
||||
|
||||
tiles[20].id = TILE_ID_GRASS;
|
||||
tiles[21].id = TILE_ID_GRASS;
|
||||
tiles[22].id = TILE_ID_GRASS;
|
||||
tiles[23].id = TILE_ID_GRASS;
|
||||
tiles[24].id = TILE_ID_GRASS;
|
||||
tiles[25].id = TILE_ID_GRASS;
|
||||
tiles[26].id = TILE_ID_GRASS;
|
||||
tiles[27].id = TILE_ID_GRASS;
|
||||
tiles[28].id = TILE_ID_GRASS;
|
||||
tiles[29].id = TILE_ID_GRASS;
|
||||
tiles[30].id = TILE_ID_WATER;
|
||||
tiles[31].id = TILE_ID_WATER;
|
||||
tiles[32].id = TILE_ID_WATER;
|
||||
tiles[33].id = TILE_ID_WATER;
|
||||
tiles[34].id = TILE_ID_WATER;
|
||||
tiles[35].id = TILE_ID_WATER;
|
||||
tiles[36].id = TILE_ID_GRASS;
|
||||
tiles[37].id = TILE_ID_GRASS;
|
||||
tiles[38].id = TILE_ID_GRASS;
|
||||
tiles[39].id = TILE_ID_GRASS;
|
||||
|
||||
tiles[50].id = TILE_ID_WATER;
|
||||
tiles[51].id = TILE_ID_WATER;
|
||||
tiles[52].id = TILE_ID_WATER;
|
||||
tiles[53].id = TILE_ID_WATER;
|
||||
|
||||
tiles[70].id = TILE_ID_WATER;
|
||||
tiles[71].id = TILE_ID_WATER;
|
||||
tiles[72].id = TILE_ID_WATER;
|
||||
tiles[73].id = TILE_ID_WATER;
|
||||
|
||||
|
||||
mapTilesSet(map, tiles, 0);
|
||||
|
@ -100,7 +100,7 @@ void displayUpdate() {
|
||||
mat4_t view, projection, model;
|
||||
|
||||
glm_mat4_identity(projection);
|
||||
glm_ortho(0.0f, (float_t)BACK_BUFFER_WIDTH, (float_t)BACK_BUFFER_HEIGHT, 0.0f, 0.0f, 1.0f, projection);
|
||||
glm_ortho(0.0f, (float_t)FRAME_PIXEL_WIDTH, (float_t)FRAME_PIXEL_HEIGHT, 0.0f, 0.0f, 1.0f, projection);
|
||||
simpleTexturedShaderSetProjection(projection);
|
||||
|
||||
glm_mat4_identity(view);
|
||||
|
@ -10,11 +10,35 @@
|
||||
#include "rpg/world/map.h"
|
||||
#include "game.h"
|
||||
|
||||
#include "ui/textbox.h"
|
||||
|
||||
char_t FRAME_BUFFER[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
uint8_t FRAME_COLOR[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
|
||||
void frameInit() {
|
||||
memset(FRAME_BUFFER, ' ', FRAME_HEIGHT * FRAME_WIDTH);
|
||||
|
||||
// Draw UI top and bottom borders
|
||||
for(uint16_t x = 0; x < FRAME_WIDTH; x++) {
|
||||
char_t c = x == 0 || x == FRAME_WIDTH-1 ? '+' : '-';
|
||||
int32_t i = (FRAME_HEIGHT - 1) * FRAME_WIDTH + x;
|
||||
FRAME_BUFFER[i] = c;
|
||||
FRAME_COLOR[i] = COLOR_WHITE;
|
||||
|
||||
i = (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) * FRAME_WIDTH + x;
|
||||
FRAME_BUFFER[i] = c;
|
||||
FRAME_COLOR[i] = COLOR_WHITE;
|
||||
}
|
||||
|
||||
for(uint16_t y = FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT + 1; y < FRAME_HEIGHT - 1; y++) {
|
||||
int32_t i = y * FRAME_WIDTH;
|
||||
FRAME_BUFFER[i] = '|';
|
||||
FRAME_COLOR[i] = COLOR_WHITE;
|
||||
|
||||
i = y * FRAME_WIDTH + FRAME_WIDTH - 1;
|
||||
FRAME_BUFFER[i] = '|';
|
||||
FRAME_COLOR[i] = COLOR_WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
void frameUpdate() {
|
||||
@ -24,14 +48,11 @@ void frameUpdate() {
|
||||
uint32_t i;
|
||||
|
||||
map_t *map = GAME.currentMap;
|
||||
if(map == NULL) {
|
||||
memset(FRAME_BUFFER, ' ', FRAME_HEIGHT * FRAME_WIDTH);
|
||||
return;
|
||||
}
|
||||
if(map == NULL) return;
|
||||
|
||||
// Update frame buffer. I can definitely optimize this.
|
||||
// Draw the map area.
|
||||
i = 0;
|
||||
for(uint16_t y = 0; y < FRAME_HEIGHT; y++) {
|
||||
for(uint16_t y = 0; y < FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT; y++) {
|
||||
for(uint16_t x = 0; x < FRAME_WIDTH; x++) {
|
||||
if(x >= map->width || y >= map->height) {
|
||||
FRAME_COLOR[i] = COLOR_BLACK;
|
||||
@ -53,4 +74,21 @@ void frameUpdate() {
|
||||
FRAME_BUFFER[i++] = symbolGetCharByTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
// UI Area.
|
||||
if(textboxIsOpen()) {
|
||||
const char_t *text = TEXTBOX.text;
|
||||
for(uint16_t x = 1; x < FRAME_WIDTH - 1; x++) {
|
||||
if(*text == '\0') break;
|
||||
FRAME_BUFFER[(FRAME_HEIGHT - 2) * FRAME_WIDTH + x] = *text++;
|
||||
FRAME_COLOR[(FRAME_HEIGHT - 2) * FRAME_WIDTH + x] = COLOR_WHITE;
|
||||
}
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 4] = ' ';
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 3] = '>';
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 2] = ' ';
|
||||
} else {
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 4] = '-';
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 3] = '-';
|
||||
FRAME_BUFFER[(FRAME_HEIGHT * FRAME_WIDTH) - 2] = '-';
|
||||
}
|
||||
}
|
@ -8,9 +8,13 @@
|
||||
#pragma once
|
||||
#include "display/color.h"
|
||||
|
||||
#define FRAME_WIDTH 640/8
|
||||
#define FRAME_HEIGHT 480/8
|
||||
#define FRAME_CHAR_SIZE 8
|
||||
#define FRAME_PIXEL_WIDTH 320
|
||||
#define FRAME_PIXEL_HEIGHT 240
|
||||
#define FRAME_WIDTH FRAME_PIXEL_WIDTH/FRAME_CHAR_SIZE
|
||||
#define FRAME_HEIGHT FRAME_PIXEL_HEIGHT/FRAME_CHAR_SIZE
|
||||
|
||||
#define FRAME_BOTTOM_UI_HEIGHT 6
|
||||
|
||||
extern char_t FRAME_BUFFER[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
extern uint8_t FRAME_COLOR[FRAME_HEIGHT * FRAME_WIDTH];
|
||||
|
@ -25,11 +25,17 @@ char_t symbolGetCharByEntity(const entity_t *ent) {
|
||||
char_t symbolGetCharByTile(const tile_t tile) {
|
||||
switch(tile.id) {
|
||||
case TILE_ID_GRASS:
|
||||
return '+';
|
||||
return '#';
|
||||
|
||||
case TILE_ID_WATER:
|
||||
// Take remainder
|
||||
return (int32_t)(TIME.time * 2) % 2 == 0 ? '~' : '-';
|
||||
int32_t j = (int32_t)(TIME.time * 2) % 4;
|
||||
switch(j) {
|
||||
case 0: return '/';
|
||||
case 1: return '|';
|
||||
case 2: return '\\';
|
||||
case 3: return '|';
|
||||
}
|
||||
|
||||
default:
|
||||
return ' ';
|
||||
|
Reference in New Issue
Block a user