Project organisation

This commit is contained in:
KikooDX 2020-09-15 12:18:24 +02:00
parent d8e23cd844
commit 872fccdd3e
5 changed files with 161 additions and 7 deletions

View File

@ -5,9 +5,9 @@
typedef struct Level
{
unsigned char tiles[64 * 64]; /* max level size */
unsigned int width; /* in tiles */
unsigned int height; /* in tiles */
int width; /* in tiles */
int height; /* in tiles */
unsigned char *tiles[]; /* points toward the level content */
} Level;
void level_step(Level *level);

View File

@ -4,6 +4,7 @@
#ifndef _DEF_MAIN
#define _DEF_MAIN
int play_level(int level_id);
void step_event(Player *player, Level *level, Camera *camera);
void draw_event(Player *player, Level *level, Camera *camera);

102
levels/0.jtmm2 Normal file
View File

@ -0,0 +1,102 @@
10
51
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

45
levels/generate_c.lua Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env lua
local function read_level(id)
local file = io.open(id..".jtmm2")
if not file then
return nil
else
local content = {width = nil, height = nil, tiles = {}}
local line_nb = 0
for line in file:lines() do
line_nb = line_nb + 1
if line_nb < 3 then
if content.width then
content.height = tonumber(line)
else
content.width = tonumber(line)
end
else
table.insert(content.tiles, line)
end
end
file:close()
return content
end
end
local function create_structure_c(id)
local content = read_level(id)
if content then
-- tiles
io.write("const unsigned char tiles_", id, "[] = {")
for i, v in ipairs(content.tiles) do
io.write(v, ", ")
end
io.write("};\n");
-- structure
io.write("const Level level_", id, " = {\n")
io.write("\t.width = ", content.width, ",\n")
io.write("\t.height = ", content.height, ",\n")
io.write("\t.tiles = &tiles_", id, "\n")
io.write("};\n")
end
end
create_structure_c(0)

View File

@ -14,6 +14,15 @@ int main(void)
{
init(); /* initialize gint */
/* main game loop */
play_level(0);
/* return to menu */
return 1;
}
int play_level(int level_id)
{
/* create player */
Player player = {
.pos = {0, 0}
@ -32,15 +41,12 @@ int main(void)
.speed = 0.0005
};
//vec_cpy(&camera.pos, player.pos);
/* main game loop */
while ((int)camera.pos.x != (int)player.pos.x)
{
step_event(&player, &level, &camera);
draw_event(&player, &level, &camera);
}
/* return to menu */
return 1;
return 0;
}
void step_event(Player *player, Level *level, Camera *camera)