diff --git a/assets-cg/Tiled/carte.tmx b/assets-cg/Tiled/carte.tmx
index 921e918..22871c5 100644
--- a/assets-cg/Tiled/carte.tmx
+++ b/assets-cg/Tiled/carte.tmx
@@ -3,7 +3,7 @@
-
+
55,55,55,6,55,55,6,6,55,6,59,6,55,6,6,55,55,6,55,6,55,55,6,55,6,
@@ -35,25 +35,25 @@
-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,
+455,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,514,738,739,739,739,739,739,739,739,739,739,739,740,514,0,289,0,0,0,0,0,0,0,
0,0,563,787,736,837,837,837,837,837,837,837,837,737,789,563,0,0,0,0,0,0,0,0,0,
0,0,0,787,789,0,0,0,0,0,0,0,0,787,789,0,0,0,0,0,289,0,0,0,0,
0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,0,0,0,0,0,0,
0,0,563,787,789,0,0,0,0,0,0,0,0,787,789,563,0,0,0,0,0,0,0,0,0,
0,0,0,787,789,0,0,0,0,0,0,0,0,787,789,0,0,0,0,0,0,0,0,0,0,
-0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,291,292,532,0,0,0,
+0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,291,292,532,0,0,472,
0,0,563,787,789,0,0,0,0,0,0,0,0,787,789,563,0,514,0,340,341,532,532,0,0,
0,0,0,787,785,739,739,739,739,739,739,739,739,786,789,0,0,563,313,0,0,0,0,0,0,
0,0,514,836,837,837,837,837,837,837,837,837,837,837,838,514,0,0,0,406,0,359,359,0,0,
-0,0,563,0,0,0,0,0,0,0,0,0,0,0,0,563,0,0,0,0,0,0,0,0,0,
+0,0,563,0,0,0,0,0,0,0,0,0,0,0,0,563,0,0,0,313,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,514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,563,0,0,0,514,0,0,0,0,0,514,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,563,0,0,0,0,0,563,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,514,0,0,0,0,0,0,0,0,0,0,0,909,761,761,910,0,0,0,0,0,0,0,
-0,0,563,0,0,0,0,0,0,0,1023,1020,1020,1020,958,761,761,959,0,0,0,0,0,0,0,
+0,0,514,0,0,0,0,0,0,0,0,0,0,0,909,914,914,910,0,0,0,0,0,0,0,
+0,0,563,0,0,0,0,0,0,0,1023,1020,1020,1020,958,963,963,959,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1024,0,0,1007,960,960,1008,0,0,0,16,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1024,0,0,0,383,0,0,0,60,60,109,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1019,1020,1020,0,33,0,383,20,256,256,305,0,0,0,
diff --git a/assets-cg/maps/world.json b/assets-cg/maps/world.json
index e10770d..b6c108f 100644
--- a/assets-cg/maps/world.json
+++ b/assets-cg/maps/world.json
@@ -15,7 +15,7 @@
"y":0
},
{
- "data":[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, 514, 738, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 740, 514, 0, 289, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 736, 837, 837, 837, 837, 837, 837, 837, 837, 737, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 289, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 291, 292, 532, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 514, 0, 340, 341, 532, 532, 0, 0, 0, 0, 0, 787, 785, 739, 739, 739, 739, 739, 739, 739, 739, 786, 789, 0, 0, 563, 313, 0, 0, 0, 0, 0, 0, 0, 0, 514, 836, 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, 838, 514, 0, 0, 0, 406, 0, 359, 359, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 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, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 514, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 563, 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, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 909, 761, 761, 910, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 1023, 1020, 1020, 1020, 958, 761, 761, 959, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 1007, 960, 960, 1008, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 0, 383, 0, 0, 0, 60, 60, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1019, 1020, 1020, 0, 33, 0, 383, 20, 256, 256, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 934, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 885, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 933, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 985, 0, 0, 0, 0, 0, 0, 0, 0],
+ "data":[455, 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, 514, 738, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 740, 514, 0, 289, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 736, 837, 837, 837, 837, 837, 837, 837, 837, 737, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 289, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 291, 292, 532, 0, 0, 472, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 514, 0, 340, 341, 532, 532, 0, 0, 0, 0, 0, 787, 785, 739, 739, 739, 739, 739, 739, 739, 739, 786, 789, 0, 0, 563, 313, 0, 0, 0, 0, 0, 0, 0, 0, 514, 836, 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, 838, 514, 0, 0, 0, 406, 0, 359, 359, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 313, 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, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 514, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 563, 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, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 909, 914, 914, 910, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 1023, 1020, 1020, 1020, 958, 963, 963, 959, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 1007, 960, 960, 1008, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 0, 383, 0, 0, 0, 60, 60, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1019, 1020, 1020, 0, 33, 0, 383, 20, 256, 256, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 934, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 885, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 933, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 985, 0, 0, 0, 0, 0, 0, 0, 0],
"height":25,
"id":2,
"name":"Calque de Tuiles 2",
@@ -35,7 +35,7 @@
"tilesets":[
{
"firstgid":1,
- "source":"..\/Tiled\/tileset.json"
+ "source":"..\/Tiled\/tileset.tsx"
}],
"tilewidth":16,
"type":"map",
diff --git a/src/display_engine.c b/src/display_engine.c
index ee06e1a..7a872d9 100644
--- a/src/display_engine.c
+++ b/src/display_engine.c
@@ -7,18 +7,19 @@ void display_map(const int x_offset, const int y_offset)
for (int layer = 0 ; layer < map_world.nb_layers; layer++)
{
- for (int y = 0 ; y <= map_world.height; y ++)
+ for (int y = 0 ; y <= SCREEN_HEIGHT; y ++)
{
- for (int x = 0 ; x <= map_world.width; x ++)
+ for (int x = 0 ; x <= SCREEN_WIDTH; x ++)
{
- unsigned int tile_id = map_world.layers[layer][y * map_world.width + x];
+ unsigned int tile_id = map_world.layers[layer][(y + y_offset / TILE_SIZE) * map_world.width + (x + x_offset / TILE_SIZE)];
+
if (tile_id != 0)
{
tile_id --;
unsigned int tile_x = (TILE_SIZE + 1) * (tile_id % TILESET_WIDTH);
unsigned int tile_y = (TILE_SIZE + 1) * (tile_id / TILESET_WIDTH);
- dsubimage(x_offset + x * TILE_SIZE, y_offset + y * TILE_SIZE, &img_tileset, tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE);
+ dsubimage(x * TILE_SIZE - (x_offset % TILE_SIZE), y * TILE_SIZE - (y_offset % TILE_SIZE), &img_tileset, tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE);
}
}
}
diff --git a/src/display_engine.h b/src/display_engine.h
index 8694a63..b258a6a 100644
--- a/src/display_engine.h
+++ b/src/display_engine.h
@@ -2,20 +2,7 @@
#define _DISPLAY_ENGINE_H
#include
-
-#define TILE_SIZE 16
-#define TILESET_WIDTH 49
-
-#define SCREEN_WIDTH 24
-#define SCREEN_HEIGHT 14
-
-struct map
-{
- int width, height, nb_layers;
-
- // to get the (x; y) cell : layers[layer_number][y * map_width + x]
- uint16_t *layers[];
-};
+#include "map.h"
// display_map : show the current map with x, y offsets
void display_map(const int x_offset, const int y_offset);
diff --git a/src/game_engine.c b/src/game_engine.c
index 5466800..fac6357 100644
--- a/src/game_engine.c
+++ b/src/game_engine.c
@@ -2,22 +2,24 @@
void keyboard_manager(const int key, int *x_offset, int *y_offset)
{
+ extern const struct map map_world;
+
switch(key)
{
case KEY_UP:
- *y_offset -= 4;
+ if (*y_offset - 1 >= 0) *y_offset -= 2;
break;
case KEY_RIGHT:
- *x_offset += 4;
+ if (*x_offset + 396 < map_world.width * TILE_SIZE) *x_offset += 2;
break;
case KEY_DOWN:
- *y_offset += 4;
+ if (*y_offset + 224 < map_world.height * TILE_SIZE) *y_offset += 2;
break;
case KEY_LEFT:
- *x_offset -= 4;
+ if (*x_offset - 1 >= 0) *x_offset -= 2;
break;
}
}
\ No newline at end of file
diff --git a/src/game_engine.h b/src/game_engine.h
index bf2dd6f..1588a99 100644
--- a/src/game_engine.h
+++ b/src/game_engine.h
@@ -2,6 +2,7 @@
#define _GAME_ENGINE_H
#include
+#include "map.h"
void keyboard_manager(const int key, int *x_offset, int *y_offset);
diff --git a/src/map.h b/src/map.h
new file mode 100644
index 0000000..69daa0c
--- /dev/null
+++ b/src/map.h
@@ -0,0 +1,21 @@
+#ifndef _MAP_H
+#define _MAP_H
+
+#include
+#include
+
+#define TILE_SIZE 16
+#define TILESET_WIDTH 49
+
+#define SCREEN_WIDTH 24
+#define SCREEN_HEIGHT 14
+
+struct map
+{
+ int width, height, nb_layers;
+
+ // to get the (x; y) cell : layers[layer_number][y * map_width + x]
+ uint16_t *layers[];
+};
+
+#endif /* _MAP_H */