diff --git a/.gitignore b/.gitignore index 2baf2a6..b2c63b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,12 @@ # Build files -projet/build-fx -projet/build-cg +project/build-fx +project/build-cg # Executables -projet/Odyssee.g1a -projet/Odyssee.g3a +project/Odyssee.g1a +project/Odyssee.g3a # Python bytecode -projet/__pycache__/* -projet/assets-fx/__pycache__/* +project/__pycache__/* +project/assets-fx/__pycache__/* diff --git a/pictures/nouvelles images/tileset.png b/pictures/nouvelles images/tileset.png index 8a02821..2578efa 100644 Binary files a/pictures/nouvelles images/tileset.png and b/pictures/nouvelles images/tileset.png differ diff --git a/project/CMakeLists.txt b/project/CMakeLists.txt index c96cc37..69efc88 100644 --- a/project/CMakeLists.txt +++ b/project/CMakeLists.txt @@ -25,7 +25,7 @@ set(ASSETS_fx assets-fx/bgrounds.png assets-fx/tileset.png assets-fx/player.png - assets-fx/maps/one.csv + assets-fx/map/world.csv # ... ) set(ASSETS_cg diff --git a/project/assets-fx/converters.py b/project/assets-fx/converters.py index ce225a7..315f68a 100644 --- a/project/assets-fx/converters.py +++ b/project/assets-fx/converters.py @@ -2,7 +2,7 @@ import fxconv def convert(input_name, output, params, target): - if params["custom-type"] == "map_t": + if params["custom-type"] == "map": convert_map(input_name, output, params, target) return 0 else: @@ -13,12 +13,19 @@ def convert_map(input_name, output, params, target): # Read informations with open(input_name, "r") as file: csv_data = file.read().splitlines() - + + walkable = [-1, 11, 12, 13, 14, 15, 16, 17, 18, 20, 24, 25, 26, 30, 31, 37, 43, 44, 45, 62, 63, 64] + # Convertion into bytes - data = bytes() + tiles = bytes() + collision = bytes() for line in csv_data: for value in line.split(","): - data += fxconv.u32(int(value)) + value = int(value) + tiles += fxconv.u32(value) + collision += fxconv.u8(int(value in walkable)) + data = fxconv.ObjectData() + data += tiles + collision fxconv.elf(data, output, "_" + params["name"], **target) diff --git a/project/assets-fx/maps/fxconv-metadata.txt b/project/assets-fx/map/fxconv-metadata.txt similarity index 64% rename from project/assets-fx/maps/fxconv-metadata.txt rename to project/assets-fx/map/fxconv-metadata.txt index fc11c64..1212ba0 100644 --- a/project/assets-fx/maps/fxconv-metadata.txt +++ b/project/assets-fx/map/fxconv-metadata.txt @@ -1,3 +1,3 @@ *.csv: - custom-type: map_t + custom-type: map name_regex: (.*)\.csv map_\1 diff --git a/project/assets-fx/map/world.csv b/project/assets-fx/map/world.csv new file mode 100644 index 0000000..b4619a0 --- /dev/null +++ b/project/assets-fx/map/world.csv @@ -0,0 +1,16 @@ +-1,65,66,66,67,-1,50,-1,-1,-1,0,1,1,1,1,2,30,-1,-1,-1,27,28,27,28,29,29,29,29,29,-1,-1,-1 +-1,84,85,84,84,-1,50,-1,22,23,19,30,64,-1,83,21,-1,-1,64,-1,46,47,46,47,44,-1,-1,-1,49,-1,-1,44 +29,84,84,86,85,29,29,-1,41,42,38,-1,-1,11,-1,21,-1,-1,-1,-1,84,85,84,84,-1,-1,24,-1,-1,-1,-1,-1 +-1,33,-1,11,-1,-1,-1,-1,-1,-1,57,58,58,58,-1,21,29,29,29,29,84,84,86,84,83,83,51,-1,49,-1,-1,-1 +-1,-1,-1,-1,11,-1,-1,30,-1,-1,11,-1,-1,-1,-1,40,11,-1,64,-1,-1,-1,44,-1,29,29,29,29,29,-1,-1,-1 +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,58,58,58,59,-1,-1,-1,-1,-1,-1,44,-1,-1,-1,-1,-1,-1,-1,-1,-1 +-1,-1,13,-1,-1,-1,-1,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,-1,44,-1,-1 +-1,-1,-1,-1,-1,-1,64,-1,-1,-1,-1,-1,-1,15,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1 +-1,-1,26,-1,64,-1,-1,-1,-1,-1,26,24,-1,-1,-1,-1,34,35,36,-1,-1,-1,-1,18,-1,-1,18,-1,-1,-1,-1,-1 +-1,-1,-1,-1,-1,-1,64,-1,-1,-1,-1,-1,-1,-1,0,1,53,54,55,2,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,-1 +-1,-1,-1,64,30,-1,-1,0,1,1,1,1,1,1,19,33,-1,-1,44,21,2,18,-1,44,-1,-1,-1,-1,-1,-1,-1,-1 +-1,-1,-1,-1,-1,-1,-1,19,22,23,52,-1,52,62,38,-1,-1,-1,44,40,21,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1 +-1,15,-1,-1,-1,-1,15,19,41,42,-1,-1,-1,-1,57,58,58,58,20,59,21,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1 +-1,-1,-1,-1,-1,-1,-1,38,-1,-1,49,-1,-1,-1,-1,-1,-1,-1,-1,52,21,-1,-1,44,-1,-1,-1,-1,-1,-1,-1,-1 +-1,-1,15,-1,-1,-1,-1,57,58,58,58,58,20,58,58,58,58,58,58,58,59,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 diff --git a/project/assets-fx/maps/one.csv b/project/assets-fx/maps/one.csv deleted file mode 100644 index b385b37..0000000 --- a/project/assets-fx/maps/one.csv +++ /dev/null @@ -1,8 +0,0 @@ -19,-1,0,0,1,1,1,1,1,1,2,1,1,1,2,2 -19,43,19,19,-1,62,3,-1,-1,62,21,-1,-1,-1,21,21 -19,-1,19,19,62,-1,-1,44,43,-1,21,-1,-1,-1,21,21 -19,-1,19,38,-1,-1,64,64,-1,-1,40,-1,-1,-1,21,21 -19,-1,38,57,58,20,58,58,58,58,59,-1,-1,-1,40,21 -19,62,57,58,58,20,58,58,58,58,58,58,20,58,59,21 -38,-1,-1,-1,30,-1,-1,43,-1,83,-1,-1,-1,-1,64,40 -57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59 diff --git a/project/assets-fx/tileset.png b/project/assets-fx/tileset.png index 7f2108c..74c3e4e 100644 Binary files a/project/assets-fx/tileset.png and b/project/assets-fx/tileset.png differ diff --git a/project/assets-fx/water_animation.png b/project/assets-fx/water_animation.png new file mode 100644 index 0000000..53b1768 Binary files /dev/null and b/project/assets-fx/water_animation.png differ diff --git a/project/src/core.c b/project/src/core.c index 8ce518b..1d457a4 100644 --- a/project/src/core.c +++ b/project/src/core.c @@ -9,28 +9,24 @@ void analyze_input(struct game *game, const int last_key) game->total_tick += ENGINE_TICK; switch (last_key) { - case 0: - if (!(game->total_tick % 500)) game->player.animation_frame = (game->player.animation_frame + 1) % 2; - break; - case KEY_UP: + if (is_walkable(*game, UP)) game->world_y -= 1; game->player.direction = UP; - game->player.y -= 2; break; case KEY_RIGHT: + if (is_walkable(*game, RIGHT)) game->world_x += 1; game->player.direction = RIGHT; - game->player.x += 2; break; case KEY_DOWN: + if (is_walkable(*game, DOWN)) game->world_y += 1; game->player.direction = DOWN; - game->player.y += 2; break; case KEY_LEFT: + if (is_walkable(*game, LEFT)) game->world_x -= 1; game->player.direction = LEFT; - game->player.x -= 2; break; } } @@ -51,4 +47,29 @@ int callback_tick(volatile int *tick) { *tick = 1; return TIMER_CONTINUE; +} + + +int is_walkable(const struct game game, const int direction) +{ + switch (direction) + { + case UP: + return game.map.collision[game.world_y + 4][game.world_x + 7]; + break; + + case RIGHT: + return game.map.collision[game.world_y + 5][game.world_x + 8]; + break; + + case DOWN: + return game.map.collision[game.world_y + 6][game.world_x + 7]; + break; + + case LEFT: + return game.map.collision[game.world_y + 5][game.world_x + 6]; + break; + } + return 0; + } \ No newline at end of file diff --git a/project/src/core.h b/project/src/core.h index f71474b..e55178e 100644 --- a/project/src/core.h +++ b/project/src/core.h @@ -8,8 +8,10 @@ #define TILESET_WIDTH 19 #define TILE_SIZE 8 -#define MAP_WIDTH 16 -#define MAP_HEIGHT 8 +#define MAP_WIDTH 32 +#define MAP_HEIGHT 16 +#define SCREEN_WIDTH 16 +#define SCREEN_HEIGHT 8 #define UP 0 #define RIGHT 1 @@ -18,21 +20,21 @@ struct player { - int x, y; - - int direction, animation_frame; + int direction; }; -struct map_t +struct map { int data[MAP_HEIGHT][MAP_WIDTH]; + + uint8_t collision[MAP_HEIGHT][MAP_WIDTH]; }; struct game { // Current map and coord's map in the world - struct map_t map; + struct map map; int world_x, world_y; struct player player; @@ -49,4 +51,6 @@ int rtc_key(void); // callback_tick : timer's function int callback_tick(volatile int *tick); +int is_walkable(const struct game game, const int direction); + #endif /* _CORE_H */ \ No newline at end of file diff --git a/project/src/display_engine.c b/project/src/display_engine.c index 07e0304..43f6849 100644 --- a/project/src/display_engine.c +++ b/project/src/display_engine.c @@ -8,13 +8,13 @@ void draw_map(const struct game game) { extern const bopti_image_t img_tileset; - for (int i = 0; i < MAP_HEIGHT; i ++) + for (int i = 0; i < SCREEN_HEIGHT; i ++) { - for (int j = 0; j < MAP_WIDTH; j++) + for (int j = 0; j < SCREEN_WIDTH; j++) { - if (game.map.data[i][j] != -1) + if (game.map.data[game.world_y + i][game.world_x + j] != -1 && game.world_y + i < (MAP_HEIGHT) && game.world_y + i >= 0 && game.world_x + j < (MAP_WIDTH) && game.world_x + j >= 0) { - int tile_x = (TILE_SIZE + 1) * (game.map.data[i][j] % TILESET_WIDTH), tile_y = (TILE_SIZE + 1) * (game.map.data[i][j] / TILESET_WIDTH); + int tile_x = (TILE_SIZE + 1) * (game.map.data[game.world_y + i][game.world_x + j] % TILESET_WIDTH), tile_y = (TILE_SIZE + 1) * (game.map.data[game.world_y + i][game.world_x + j] / TILESET_WIDTH); dsubimage(j * TILE_SIZE, i * TILE_SIZE, &img_tileset, tile_x, tile_y, 8, 8, DIMAGE_NONE); } } @@ -26,5 +26,5 @@ void draw_player(const struct game game) { extern const bopti_image_t img_player; - dsubimage(game.player.x, game.player.y, &img_player, 9 * game.player.animation_frame, 13 * game.player.direction, 8, 12, DIMAGE_NONE); + dsubimage(56, 35, &img_player, 0, 13 * game.player.direction, 8, 12, DIMAGE_NONE); } diff --git a/project/src/main.c b/project/src/main.c index 92de782..70b01be 100644 --- a/project/src/main.c +++ b/project/src/main.c @@ -88,21 +88,14 @@ void title_screen(void) void main_loop(void) { - extern const struct map_t map_one; + extern const struct map map_world; int key = 0; - static volatile int tick = 0; - int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick)); - if (t >= 0) timer_start(t); - - struct player player = {8, 0, 2, 0}; - struct game game = {map_one, 0, 0, player, 0}; + struct player player = {DOWN}; + struct game game = {map_world, 0, 0, player, 0}; while (key != KEY_EXIT) { - while (!tick) sleep(); - tick = 0; - dclear(C_WHITE); draw_map(game); @@ -110,9 +103,7 @@ void main_loop(void) dupdate(); - key = rtc_key(); + key = getkey().key; analyze_input(&game, key); } - - if (t >= 0) timer_stop(t); } \ No newline at end of file