diff --git a/assets-cg/converters.py b/assets-cg/converters.py
index ff5481d..f726a17 100644
--- a/assets-cg/converters.py
+++ b/assets-cg/converters.py
@@ -9,14 +9,13 @@ def convert(input, output, params, target):
return 1
def convert_map(input, output, params, target):
+ TILE_BRIDGE = -1 #only for bridge detection to avoid solid behind
TILE_AIR = 0
TILE_SOLID = 1
TILE_DOOR_IN = 2
TILE_DOOR_OUT = 3
TILE_TALKABLE = 4
- TILE_BRIDGE = -1 #only for bridge detection to avoid solid behind
-
with open(input, "r") as jsonData:
data = json.load(jsonData)
@@ -34,41 +33,37 @@ def convert_map(input, output, params, target):
tileset.close()
tile_value = {}
-
- #create a dictionnary between tile id-type
+ #create a dictionnary {tile id:type}
for i in data_tileset["tiles"]:
- try:
- id = i["id"]+1
- type = i["type"]
+ id = i["id"]+1
+ type = i["type"]
- if type == "air":
- value = TILE_AIR
- elif type == "solid":
- value = TILE_SOLID
- elif type == "door_in":
- value = TILE_DOOR_IN
- elif type == "door_out":
- value = TILE_DOOR_OUT
- elif type == "talkable":
- value = TILE_TALKABLE
- elif type == "bridge":
- value = TILE_BRIDGE
- else:
- value = TILE_AIR
+ if type == "air":
+ value = TILE_AIR
+ elif type == "solid":
+ value = TILE_SOLID
+ elif type == "door_in":
+ value = TILE_DOOR_IN
+ elif type == "door_out":
+ value = TILE_DOOR_OUT
+ elif type == "talkable":
+ value = TILE_TALKABLE
+ elif type == "bridge":
+ value = TILE_BRIDGE
+ else:
+ value = TILE_AIR
- tile_value[id] = value
- except KeyError:
- pass
+ tile_value[id] = value
- #Extract from the json the width, height and layers of the map
+ #Extract from the json the width, height
w, h = data["width"], data["height"]
indexObjectlayer = None
+ #nbTileLayer is the number of "true" layers (without ObjectsLayer)
nbTilelayer = len(data["layers"])
for i in range(nbTilelayer):
try:
data["layers"][i]["data"]
- #nbTileLayer is the number of "true" layers (without ObjectsLayer)
nbTilelayer = i+1
except KeyError:
indexObjectlayer = i
@@ -117,7 +112,7 @@ def convert_map(input, output, params, target):
info_map += fxconv.u16(maxValue)
maxValue = 0
bridge = False
- structMap += fxconv.ref(info_map)
+ structMap += fxconv.ptr(info_map)
#generate the array of tiles from the layer
for i in range(nbTilelayer):
@@ -126,7 +121,7 @@ def convert_map(input, output, params, target):
for tile in layer["data"]:
layer_data += fxconv.u16(tile)
- structMap += fxconv.ref(layer_data)
+ structMap += fxconv.ptr(layer_data)
#generate !
fxconv.elf(structMap, output, "_" + params["name"], **target)
\ No newline at end of file
diff --git a/assets-cg/maps/inside/interior_1.tmx b/assets-cg/maps/inside/interior_1.tmx
index 599ff4f..d084a18 100644
--- a/assets-cg/maps/inside/interior_1.tmx
+++ b/assets-cg/maps/inside/interior_1.tmx
@@ -50,7 +50,8 @@
diff --git a/include/define.h b/include/define.h
index 1cd65b4..b0ffe0b 100644
--- a/include/define.h
+++ b/include/define.h
@@ -1,4 +1,5 @@
+#pragma once
/*the width of the tileset*/
#define TILESET_WIDTH 29
/*the size of one tile*/
-#define TILE_SIZE 16
+#define TILE_SIZE 16
\ No newline at end of file
diff --git a/include/game.h b/include/game.h
index 9f3f713..e9d7cdb 100644
--- a/include/game.h
+++ b/include/game.h
@@ -12,9 +12,6 @@ struct Game {
int background;
};
-/*get the input with a timeout*/
-int get_inputs(void);
-
enum direction {
DIR_DOWN = 0,
DIR_LEFT = 1,
@@ -23,3 +20,7 @@ enum direction {
ACTION_SHIFT = 4,
ACTION_ALPHA = 5
};
+
+/*get the input with a timeout*/
+int get_inputs(void);
+struct Game init_game(struct Player *player);
\ No newline at end of file
diff --git a/include/map.h b/include/map.h
index 38b2aa8..c72f950 100644
--- a/include/map.h
+++ b/include/map.h
@@ -1,6 +1,5 @@
#pragma once
#include
-#include
#include "engine.h"
struct Map {
diff --git a/include/player.h b/include/player.h
index 33bd046..a24d674 100644
--- a/include/player.h
+++ b/include/player.h
@@ -24,3 +24,4 @@ struct Player {
/*return the info tile value the player is facing to*/
int player_facing(struct Game const *game);
void set_player_xy(struct Player *player, int x, int y);
+struct Player init_player(void);
diff --git a/include/talkable.h b/include/talkable.h
index b833529..451904d 100644
--- a/include/talkable.h
+++ b/include/talkable.h
@@ -1,5 +1,6 @@
#pragma once
#include "map.h"
+
struct Talkable {
/*the position of the tile*/
int x, y;
diff --git a/include/util.h b/include/util.h
index 7e80bc2..dbb22a5 100644
--- a/include/util.h
+++ b/include/util.h
@@ -1,3 +1,4 @@
#pragma once
+/*wait for a specified input key*/
void wait_for_input(int input);
\ No newline at end of file
diff --git a/include/vec2.h b/include/vec2.h
index 7325a71..6e38cc7 100644
--- a/include/vec2.h
+++ b/include/vec2.h
@@ -10,10 +10,8 @@ struct Vec2f {
float y;
};
-#define VEC2(x, y) \
- (struct Vec2) { x, y }
-#define VEC2F(x, y) \
- (struct Vec2f) { x, y }
+#define VEC2(x, y) (struct Vec2) { x, y }
+#define VEC2F(x, y) (struct Vec2f) { x, y }
#define VEC2Z VEC2(0, 0)
#define VEC2FZ VEC2F(0.0, 0.0)
diff --git a/src/animation.c b/src/animation.c
index e8f9073..6a7f5e6 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -1,8 +1,8 @@
#include
#include
+
#include "animation.h"
#include "engine.h"
-#include "game.h"
struct Sheet
{
diff --git a/src/camera.c b/src/camera.c
index a020b07..d17f8fc 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -1,5 +1,4 @@
#include "vec2.h"
-#include "define.h"
#include "camera.h"
struct Camera camera_new(struct Vec2f *target) {
diff --git a/src/engine.c b/src/engine.c
index 0e9a102..99ff590 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -1,5 +1,6 @@
#include
#include
+
#include "engine.h"
#include "game.h"
#include "map.h"
diff --git a/src/game.c b/src/game.c
index 5ab6391..ff16cb3 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,7 +1,22 @@
#include
#include
+
#include "game.h"
#include "player.h"
+#include "map.h"
+
+struct Game init_game(struct Player *player) {
+
+ extern struct Map *maps[];
+
+ struct Game game = {
+ .map = maps[0],
+ .player = player,
+ .camera = camera_new(&player->pos_visual),
+ .background = C_WHITE
+ };
+ return game;
+}
/*get the input with a timeout*/
int get_inputs(void) {
diff --git a/src/main.c b/src/main.c
index a0791e0..7ba8853 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,21 +1,11 @@
#include
#include
-#include "game.h"
-#include "map.h"
-#include "engine.h"
-#include "player.h"
-#include "animation.h"
-#include "camera.h"
-#include "define.h"
-
#include
#include
-extern struct Map map_1;
-
-struct Map *maps[] = {
- &map_1,
-};
+#include "game.h"
+#include "engine.h"
+#include "player.h"
static int callback_tick(volatile int *tick) {
*tick = 1;
@@ -24,25 +14,8 @@ static int callback_tick(volatile int *tick) {
int main(void) {
/*Structure definition*/
- struct Player player = {
- .pos = VEC2(32, 30),
- .pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
- .x_mid = 6,
- .y_mid = 1,
- .show_x = 12,
- .show_y = 7,
- .direction = DIR_DOWN,
- .anim.function = anim_player_idle,
- .anim.dir = DIR_DOWN
- };
- player.idle = !anim_player_idle(&player.anim, 1);
-
- struct Game game = {
- .map = maps[0],
- .player = &player,
- .camera = camera_new(&player.pos_visual),
- .background = C_WHITE
- };
+ struct Player player = init_player();
+ struct Game game = init_game(&player);
/*Timer*/
static volatile int tick = 1;
diff --git a/src/map.c b/src/map.c
index d4635ad..f7cbfe2 100644
--- a/src/map.c
+++ b/src/map.c
@@ -1,9 +1,13 @@
#include "map.h"
-#include "engine.h"
#include "player.h"
-#include "camera.h"
#include "define.h"
+extern struct Map map_1;
+
+struct Map *maps[] = {
+ &map_1,
+};
+
/*check if a tile is walkable*/
int map_walkable(struct Map const *map, int x, int y) {
int tile = map->info_map[x + map->w * y];
@@ -16,8 +20,10 @@ int map_get_player_tile(struct Game const *game) {
return game->map->info_map[game->player->pos.x + game->map->w * game->player->pos.y];
}
+/*generate the interior*/
void generate_interior_map(struct Game *game) {
extern struct Map in_1;
+
game->map = &in_1;
set_player_xy(game->player, 3,3);
game->camera.pos.x = in_1.w/2 * TILE_SIZE + game->player->x_mid;
diff --git a/src/player.c b/src/player.c
index 8d665f3..a0d2757 100644
--- a/src/player.c
+++ b/src/player.c
@@ -1,8 +1,23 @@
#include "player.h"
#include "define.h"
-#include "engine.h"
#include "map.h"
-#include "game.h"
+
+struct Player init_player(void) {
+ struct Player player = {
+ .pos = VEC2(32, 30),
+ .pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
+ .x_mid = 6,
+ .y_mid = 1,
+ .show_x = 12,
+ .show_y = 7,
+ .direction = DIR_DOWN,
+ .anim.function = anim_player_idle,
+ .anim.dir = DIR_DOWN
+ };
+ player.idle = !anim_player_idle(&player.anim, 1);
+
+ return player;
+}
/*
return the info tile value the player is facing to
@@ -23,7 +38,6 @@ int player_facing(struct Game const *game) {
return TILE_SOLID;
}
-/* lol */
void set_player_xy(struct Player *p, int x, int y) {
p->pos.x = x;
p->pos.y = y;
diff --git a/src/talkable.c b/src/talkable.c
index a46dda9..167b622 100644
--- a/src/talkable.c
+++ b/src/talkable.c
@@ -1,9 +1,8 @@
#include
#include
#include
+
#include "talkable.h"
-#include "engine.h"
-#include "map.h"
#include "util.h"
struct Talkable default_value = {
diff --git a/src/util.c b/src/util.c
index 733d16f..1f3c940 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,6 +1,8 @@
#include
+
#include "util.h"
+/*wait for a specified input key*/
void wait_for_input(int input) {
int buffer = 1;
while(1) {
diff --git a/src/vec2.c b/src/vec2.c
index 973371e..6525488 100644
--- a/src/vec2.c
+++ b/src/vec2.c
@@ -1,42 +1,34 @@
#include "vec2.h"
-struct Vec2 vec2_add(struct Vec2 v1, struct Vec2 v2)
-{
+struct Vec2 vec2_add(struct Vec2 v1, struct Vec2 v2) {
return VEC2(v1.x + v2.x, v1.y + v2.y);
}
-struct Vec2f vec2f_add(struct Vec2f v1, struct Vec2f v2)
-{
+struct Vec2f vec2f_add(struct Vec2f v1, struct Vec2f v2) {
return VEC2F(v1.x + v2.x, v1.y + v2.y);
}
-struct Vec2 vec2_sub(struct Vec2 v1, struct Vec2 v2)
-{
+struct Vec2 vec2_sub(struct Vec2 v1, struct Vec2 v2) {
return VEC2(v1.x - v2.x, v1.y - v2.y);
}
-struct Vec2f vec2f_sub(struct Vec2f v1, struct Vec2f v2)
-{
+struct Vec2f vec2f_sub(struct Vec2f v1, struct Vec2f v2) {
return VEC2F(v1.x - v2.x, v1.y - v2.y);
}
-struct Vec2 vec2_mul(struct Vec2 v, int scale)
-{
+struct Vec2 vec2_mul(struct Vec2 v, int scale) {
return VEC2(v.x * scale, v.y * scale);
}
-struct Vec2f vec2f_mul(struct Vec2f v, int scale)
-{
+struct Vec2f vec2f_mul(struct Vec2f v, int scale) {
return VEC2F(v.x * scale, v.y * scale);
}
-struct Vec2 vec2f_vec2(struct Vec2f v)
-{
+struct Vec2 vec2f_vec2(struct Vec2f v) {
return VEC2(v.x, v.y);
}
-struct Vec2f vec2_vec2f(struct Vec2 v)
-{
+struct Vec2f vec2_vec2f(struct Vec2 v) {
return VEC2F(v.x, v.y);
}