forked from kdx/jtmm2-old
Project organisation
This commit is contained in:
parent
d8e23cd844
commit
872fccdd3e
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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)
|
14
src/main.c
14
src/main.c
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue