Debug level display works, fixed mistakes here and there

This commit is contained in:
KikooDX 2020-09-21 12:01:54 +02:00
parent 8c1faba253
commit ac19ece235
10 changed files with 36 additions and 250 deletions

4
.gitignore vendored
View File

@ -2,4 +2,6 @@ build-cg
build-cg/*
build-fx
build-fx/*
JTMM2.g*a
JTMM2.g*a
levels/0.jtmm2
src/gen_levels.c

View File

@ -1 +1 @@
#define DEBUG
//#define DEBUG

View File

@ -7,9 +7,10 @@
typedef struct Level
{
int width; /* in tiles */
int height; /* in tiles */
uint width; /* in tiles */
uint height; /* in tiles */
const uint8_t **layers; /* points toward the level content */
uint layers_count;
} Level;
void level_step(const Level *level);

View File

@ -1,203 +0,0 @@
10
51
100
100
100
100
100
100
100
100
100
100
100
100
100
1
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
n
100
100
100
100
100
100
100
100
100
100
100
100
100
1
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100

17
levels/create_demo.lua Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env luajit
local function create_random_level(width, height, layers)
io.write(width, "\n")
io.write(height, "\n")
for i = 1, layers, 1 do
for r = 1, width * height, 1 do
io.write(math.floor(math.random() * 2)) --random 0 or 1
io.write("\n")
end
if i ~= layers then
io.write("n\n")
end
end
end
create_random_level(50, 20, 1)

View File

@ -59,7 +59,8 @@ local function create_structure_c(id)
io.write("const Level level_", id, " = {\n")
io.write("\t.width = ", content.width, ",\n")
io.write("\t.height = ", content.height, ",\n")
io.write("\t.layers = layers_", id, "\n")
io.write("\t.layers = layers_", id, ",\n")
io.write("\t.layers_count = ", #content.layers, "\n")
io.write("};\n")
end
end

4
make_levels.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd levels
./create_demo.lua > 0.jtmm2
./generate_c.lua > ../src/gen_levels.c

View File

@ -16,12 +16,11 @@ void camera_draw_debug(Camera *camera)
vec_cpy(&draw_pos, camera->pos);
vec_mul(&draw_pos, SCALE);
vec_div(&draw_pos, VEC_PRECISION);
uint8_t color;
#ifdef FX9860G
color = C_BLACK;
const int color = C_BLACK;
#endif /* FX9860G */
#ifdef FXCG50
color = C_RED;
const int color = C_RED;
#endif /* FXCG50 */
dpixel(draw_pos.x, draw_pos.y, color);
}

View File

@ -1,34 +0,0 @@
#include "level.h"
const uint8_t tiles_0_1[] = {
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100,
};
const uint8_t tiles_0_2[] = {
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100,
};
const uint8_t *layers_0[] = {tiles_0_1, tiles_0_2, };
const Level level_0 = {
.width = 10,
.height = 51,
.layers = layers_0
};
void level_set(const Level **level, uint level_id)
{
switch(level_id)
{
case 0: *level = &level_0; break;
}
}

View File

@ -14,18 +14,17 @@ void level_draw(const Level *level, Camera *camera)
void layer_draw(const Level *level, Camera *camera, uint layer_id)
{
return;
const uint8_t *layer = level->layers[layer_id];
for (int y = 0; y < level->width; ++y)
for (uint y = 0; y < level->height; ++y)
{
for (int x = 0; x < level->height; ++x)
for (uint x = 0; x < level->width; ++x)
{
const uint8_t cell = layer[x + y * level->width];
#ifdef FX9860G
dpixel(x, y, (cell == 100) ? C_LIGHT : C_BLACK);
dpixel(x, y, (cell == 1) ? C_LIGHT : C_BLACK);
#endif /* FX9860G */
#ifdef FXCG50
dpixel(x, y, (cell == 100) ? C_RED : C_BLACK);
dpixel(x, y, (cell == 1) ? C_RED : C_BLACK);
#endif /* FXCG50 */
}
}