diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0575c03..97e31ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,8 +16,9 @@ add_custom_command(
COMMENT "Convert tmx map to json"
COMMAND tiled --export-tileset json tileset.tsx tileset.json
COMMAND tiled --export-map json testCarte.tmx testCarte.json
+ COMMAND tiled --export-map json inside/interior_1.tmx inside/interior_1.json
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/
- DEPENDS assets-cg/maps/testCarte.tmx assets-cg/tileset.png assets-cg/maps/tileset.tsx assets-cg/converters.py)
+ DEPENDS assets-cg/maps/testCarte.tmx assets-cg/tileset.png assets-cg/maps/tileset.tsx assets-cg/converters.py assets-cg/maps/inside/interior_1.tmx)
set(SOURCES
src/main.c
@@ -33,6 +34,7 @@ set(SOURCES
set(ASSETS_cg
assets-cg/tileset.png
assets-cg/maps/testCarte.json
+ assets-cg/maps/inside/interior_1.json
assets-cg/spritesheet.png
assets-cg/characters/Tituya.char
assets-cg/characters/Lephenixnoir.char
diff --git a/assets-cg/fxconv-metadata.txt b/assets-cg/fxconv-metadata.txt
index 3144da4..be2bccc 100644
--- a/assets-cg/fxconv-metadata.txt
+++ b/assets-cg/fxconv-metadata.txt
@@ -1,7 +1,7 @@
tileset.png:
type: bopti-image
name: img_tileset
- profile:p8
+ profile:p4
spritesheet.png:
type: bopti-image
diff --git a/assets-cg/maps/inside/fxconv-metadata.txt b/assets-cg/maps/inside/fxconv-metadata.txt
new file mode 100644
index 0000000..00cb15c
--- /dev/null
+++ b/assets-cg/maps/inside/fxconv-metadata.txt
@@ -0,0 +1,3 @@
+interior_1.json:
+ custom-type: map
+ name: in_1
diff --git a/assets-cg/maps/inside/interior_1.tmx b/assets-cg/maps/inside/interior_1.tmx
new file mode 100644
index 0000000..977b53f
--- /dev/null
+++ b/assets-cg/maps/inside/interior_1.tmx
@@ -0,0 +1,35 @@
+
+
diff --git a/assets-cg/maps/inside/tileset.tsx b/assets-cg/maps/inside/tileset.tsx
new file mode 100644
index 0000000..53c4100
--- /dev/null
+++ b/assets-cg/maps/inside/tileset.tsx
@@ -0,0 +1,399 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/assets-cg/maps/testCarte.tmx b/assets-cg/maps/testCarte.tmx
index 85b58e2..f4343a8 100644
--- a/assets-cg/maps/testCarte.tmx
+++ b/assets-cg/maps/testCarte.tmx
@@ -29,21 +29,21 @@
1,1,1,1,1,69,72,99,99,130,130,131,100,0,2,1,1,3,1,36,39,1,2,2,2,175,0,1,1,1,1,1,1,3,6,6,6,1,117,91,120,121,89,89,92,118,119,2,2,3,151,154,182,240,243,301,244,242,180,181,213,182,3,1,3,3,3,3,2,1,1,190,223,191,223,191,191,191,222,194,221,3,6,6,6,6,6,2,2,1,2,219,193,165,162,164,192,3,240,241,
1,1,1,59,61,127,128,128,128,128,128,128,129,2,2,1,3,2,3,3,2,3,3,3,2,204,206,0,0,0,0,0,0,6,6,0,6,6,1,88,121,121,121,92,119,1,1,1,151,152,154,213,182,298,272,301,273,300,180,212,181,182,35,39,2,1,2,3,35,33,32,219,193,191,223,223,194,220,193,192,40,1,2,6,6,6,1,1,1,1,3,1,219,220,220,220,221,240,243,270,
1,1,1,88,63,61,1,1,1,1,38,2,2,2,1,3,0,33,3,3,3,1,1,3,3,3,2,204,205,205,205,178,0,6,6,6,6,6,1,117,91,89,121,90,3,1,2,151,154,212,212,213,155,153,298,299,300,1,180,213,181,182,34,33,2,2,2,6,2,2,1,2,219,220,220,220,221,2,190,192,39,31,3,1,2,1,2,151,153,1,2,1,240,241,241,241,241,243,302,301,
-1,0,60,62,121,90,161,162,162,163,1,59,60,61,2,3,1,0,0,3,0,3,1,2,3,2,1,1,1,3,1,175,0,1,6,6,6,6,6,1,117,91,121,63,61,1,1,209,183,213,212,212,213,155,153,3,151,152,154,181,184,211,1,3,2,2,1,6,6,3,2,1,2,1,1,2,3,1,190,192,34,36,2,2,3,151,152,154,182,3,1,240,243,270,273,299,299,272,270,301,
-59,62,89,121,92,119,190,191,223,192,59,62,89,63,60,61,2,1,3,0,3,2,2,2,1,59,60,60,61,1,2,204,206,0,0,0,0,0,0,1,1,117,118,118,119,3,3,2,209,183,212,181,213,181,155,152,154,213,212,184,211,3,9,1,2,2,6,6,6,6,2,1,2,39,36,37,37,161,164,165,163,3,1,151,152,154,213,184,211,2,240,243,301,273,300,2,3,298,272,270,
-117,118,91,89,90,161,164,223,194,221,117,118,118,91,89,90,3,2,2,3,2,1,59,60,60,62,120,121,90,1,1,1,1,3,2,240,241,242,1,0,0,0,138,138,0,0,0,0,3,209,210,183,212,213,213,181,181,184,210,211,3,2,2,2,2,1,6,6,6,6,1,3,39,32,30,30,109,219,193,194,221,3,2,180,213,212,212,182,2,2,269,301,301,271,3,156,158,1,298,299,
-241,242,117,118,119,190,223,194,221,146,147,147,148,88,121,90,146,148,3,3,2,59,62,121,121,121,120,120,63,61,1,1,0,0,3,298,272,244,241,242,204,205,0,0,204,178,176,150,0,0,2,209,210,210,210,210,210,211,6,6,3,3,1,3,2,6,6,6,6,6,1,1,31,109,2,240,241,242,219,221,39,2,2,209,183,212,212,182,1,240,243,301,273,300,156,159,160,158,3,1,
-301,244,242,5,2,190,223,192,146,149,0,176,177,88,120,90,175,150,148,3,3,88,121,120,121,92,91,121,121,63,61,0,0,0,0,1,269,301,270,244,242,1,156,158,2,204,205,205,178,150,0,2,1,9,3,3,6,6,6,3,2,1,1,2,6,6,6,6,6,6,1,240,241,241,241,243,270,244,241,241,242,109,1,2,209,210,210,211,2,269,270,301,271,3,185,217,218,160,157,157,
-301,270,271,4,1,190,223,192,175,176,207,207,177,88,120,90,204,178,150,148,3,88,120,120,92,119,117,91,121,120,63,60,0,0,1,1,269,270,270,270,271,1,185,187,1,3,2,2,204,178,150,0,0,0,0,2,3,2,146,148,1,3,1,3,6,6,3,1,3,240,241,243,301,270,301,270,270,270,301,301,244,242,3,34,34,2,34,1,240,243,270,270,271,156,159,218,186,186,217,217,
-270,301,271,3,161,164,223,192,175,176,176,208,177,88,120,63,61,204,205,206,2,88,89,120,90,1,2,117,118,91,121,121,121,63,61,1,269,301,301,270,271,1,185,187,1,2,1,1,1,204,205,205,178,208,150,147,147,147,149,177,1,1,3,3,1,1,240,241,241,243,270,301,270,270,270,270,270,270,270,301,270,244,241,241,242,2,40,109,269,301,301,270,271,185,218,218,217,218,217,217,
-301,270,271,4,190,191,194,221,175,176,176,176,177,88,120,121,90,3,2,2,1,88,120,120,90,3,3,2,2,117,91,121,120,121,90,1,269,301,270,270,271,156,159,187,5,39,1,240,241,242,3,3,204,205,205,205,205,205,205,206,3,1,3,240,241,241,243,301,301,301,270,270,302,270,270,270,270,270,270,270,301,270,270,270,244,241,241,241,243,301,301,301,271,214,215,188,186,186,218,186,
-301,273,300,1,190,194,221,146,149,176,176,176,177,88,89,121,63,60,60,60,60,62,89,89,90,2,1,2,3,2,117,91,121,92,119,240,243,270,301,270,271,185,217,187,35,33,240,243,302,244,241,241,242,2,1,3,1,1,2,1,2,240,241,243,270,270,301,301,270,270,270,270,270,270,270,270,273,299,272,270,270,270,273,299,299,272,270,270,301,270,301,301,244,242,36,214,215,188,186,218,
-301,271,4,161,164,192,146,149,208,176,176,176,177,117,91,121,120,121,120,89,120,121,120,89,90,3,3,1,1,2,1,88,89,281,282,282,282,282,282,282,282,283,217,187,40,37,269,301,273,299,272,301,271,3,2,2,1,3,1,240,241,243,270,270,301,270,270,270,270,270,270,270,270,270,273,299,300,32,298,299,299,299,300,1,37,298,299,272,301,301,270,301,270,244,242,1,5,214,188,186,
-299,300,3,190,191,192,175,208,0,176,176,176,150,148,88,89,120,89,120,120,89,120,120,121,90,2,3,3,2,3,3,117,91,310,311,311,311,311,311,311,311,312,218,160,158,240,243,273,300,1,298,272,244,241,241,241,241,241,241,243,270,270,301,270,270,270,270,270,270,270,270,270,270,270,271,2,40,69,70,70,71,38,3,69,70,71,38,298,299,272,301,270,270,301,244,241,242,3,185,217,
-147,148,1,190,222,192,204,178,176,176,176,176,179,206,88,120,121,92,118,118,118,118,118,118,119,1,2,1,1,2,1,1,117,119,298,272,301,301,270,270,271,185,218,189,216,269,270,271,2,2,1,298,272,270,301,270,270,301,301,301,270,270,270,302,270,270,270,270,270,270,270,270,270,270,244,242,109,127,128,101,73,70,70,72,99,73,71,33,35,298,272,270,270,270,301,270,271,3,214,215,
-176,177,161,164,222,165,163,204,178,207,176,179,206,59,62,0,92,119,3,2,2,3,1,3,1,3,2,2,2,3,2,2,3,3,2,298,272,270,301,301,271,185,186,187,240,243,270,244,242,2,0,2,298,272,301,301,301,270,301,270,270,270,270,273,299,299,299,272,270,270,270,270,270,270,270,244,241,242,34,127,128,128,101,99,99,99,73,70,71,30,269,270,270,270,270,270,244,242,30,34,
-176,177,190,222,222,191,165,163,204,205,205,206,59,62,89,89,90,2,1,3,2,3,2,2,1,2,1,0,1,3,0,1,2,0,156,158,298,299,299,299,300,185,217,187,298,299,272,302,271,2,2,3,3,298,272,301,270,270,270,270,270,270,273,300,35,33,33,269,270,270,270,270,270,270,270,270,270,244,241,241,242,4,127,128,101,130,130,99,100,36,269,270,270,270,302,270,270,244,241,242,
-176,177,190,191,223,191,222,165,162,162,162,163,88,89,89,120,63,61,3,1,1,2,3,3,3,2,1,3,2,2,1,1,1,3,185,160,157,157,157,157,157,159,186,160,158,3,298,299,300,1,1,2,1,1,298,272,270,270,270,270,270,270,271,40,2,39,37,269,270,270,270,270,270,270,270,270,270,270,270,270,271,34,38,33,127,128,128,128,129,40,269,270,270,270,270,270,270,270,270,244
+1,0,60,62,121,90,161,162,162,163,1,59,60,61,2,3,1,0,0,3,0,3,1,2,3,2,1,1,1,3,1,175,0,1,6,6,6,6,6,1,117,91,121,63,61,1,1,209,183,213,212,212,213,155,153,3,151,152,154,181,184,211,1,3,2,2,1,6,6,3,2,1,2,1,1,2,3,1,190,192,34,36,2,2,3,151,152,154,182,3,1,240,243,270,266,292,292,265,270,301,
+59,62,89,121,92,119,190,191,223,192,59,62,89,63,60,61,2,1,3,0,3,2,2,2,1,59,60,60,61,1,2,204,206,0,0,0,0,0,0,1,1,117,118,118,119,3,3,2,209,183,212,181,213,181,155,152,154,213,212,184,211,3,9,1,2,2,6,6,6,6,2,1,2,39,36,37,37,161,164,165,163,3,1,151,152,154,213,184,211,2,240,243,301,266,293,186,218,291,265,270,
+117,118,91,89,90,161,164,223,194,221,117,118,118,91,89,90,3,2,2,3,2,1,59,60,60,62,120,121,90,1,1,1,1,3,2,240,241,242,1,0,0,0,138,138,0,0,0,0,3,209,210,183,212,213,213,181,181,184,210,211,3,2,2,2,2,1,6,6,6,6,1,3,39,32,30,30,109,219,193,194,221,3,2,180,213,212,212,182,2,2,269,301,301,264,186,218,218,218,291,265,
+241,242,117,118,119,190,223,194,221,146,147,147,148,88,121,90,146,148,3,3,2,59,62,121,121,121,120,120,63,61,1,1,0,0,3,298,272,244,241,242,204,205,0,0,204,178,176,150,0,0,2,209,210,210,210,210,210,211,6,6,3,3,1,3,2,6,6,6,6,6,1,1,31,109,2,240,241,242,219,221,39,2,2,209,183,212,212,182,1,240,243,301,266,293,217,186,217,218,217,291,
+301,244,242,5,2,190,223,192,146,149,0,176,177,88,120,90,175,150,148,3,3,88,121,120,121,92,91,121,121,63,61,0,0,0,0,1,269,301,270,244,242,1,156,158,2,204,205,205,178,150,0,2,1,9,3,3,6,6,6,3,2,1,1,2,6,6,6,6,6,6,1,240,241,241,241,243,270,244,241,241,242,109,1,2,209,210,210,211,2,269,270,301,264,186,217,217,217,218,186,186,
+301,270,271,4,1,190,223,192,175,176,207,207,177,88,120,90,204,178,150,148,3,88,120,120,92,119,117,91,121,120,63,60,0,0,1,1,269,270,270,270,271,1,185,187,1,3,2,2,204,178,150,0,0,0,0,2,3,2,146,148,1,3,1,3,6,6,3,1,3,240,241,243,301,270,301,270,270,270,301,301,244,242,3,34,34,2,34,1,240,243,270,270,264,186,186,233,235,186,217,217,
+270,301,271,3,161,164,223,192,175,176,176,208,177,88,120,63,61,204,205,206,2,88,89,120,90,1,2,117,118,91,121,121,121,63,61,1,269,301,301,270,271,1,185,187,1,2,1,1,1,204,205,205,178,208,150,147,147,147,149,177,1,1,3,3,1,1,240,241,241,243,270,301,270,270,270,270,270,270,270,301,270,244,241,241,242,2,40,109,269,301,301,270,264,186,218,262,237,235,217,217,
+301,270,271,4,190,191,194,221,175,176,176,176,177,88,120,121,90,3,2,2,1,88,120,120,90,3,3,2,2,117,91,121,120,121,90,1,269,301,270,270,271,156,159,187,5,39,1,240,241,242,3,3,204,205,205,205,205,205,205,206,3,1,3,240,241,241,243,266,292,265,270,270,302,270,270,270,270,270,270,270,301,270,270,270,244,241,241,241,243,301,301,301,264,217,218,262,270,264,218,186,
+301,273,300,1,190,194,221,146,149,176,176,176,177,88,89,121,63,60,60,60,60,62,89,89,90,2,1,2,3,2,117,91,121,92,119,240,243,270,301,270,271,185,217,187,35,33,240,243,302,244,241,241,242,2,1,3,1,1,2,1,2,240,241,243,270,270,266,293,186,291,265,270,270,270,270,270,273,299,272,270,270,270,273,299,299,272,270,270,301,270,301,301,264,186,233,236,266,293,186,218,
+301,271,4,161,164,192,146,149,208,176,176,176,177,117,91,121,120,121,120,89,120,121,120,89,90,3,3,1,1,2,1,88,89,281,282,282,282,282,282,282,282,283,217,187,40,37,269,301,273,299,272,301,271,3,2,2,1,3,1,240,241,243,270,270,301,270,264,217,186,218,262,270,270,270,273,299,300,32,298,299,299,299,300,1,37,298,299,272,301,301,270,301,237,234,236,266,293,186,217,186,
+299,300,3,190,191,192,175,208,0,176,176,176,150,148,88,89,120,89,120,120,89,120,120,121,90,2,3,3,2,3,3,117,91,310,311,311,311,311,311,311,311,312,218,160,158,240,243,273,300,1,298,272,244,241,241,241,241,241,241,243,270,270,301,270,270,270,237,235,218,233,236,270,270,270,271,2,40,69,70,70,71,38,3,69,70,71,38,298,299,272,301,270,270,301,263,264,186,218,186,233,
+147,148,1,190,222,192,204,178,176,176,176,176,179,206,88,120,121,92,118,118,118,118,118,118,119,1,2,1,1,2,1,1,117,119,298,272,301,301,270,270,271,185,218,189,216,269,270,271,2,2,1,298,272,270,301,270,270,301,301,301,270,270,270,302,270,270,270,237,235,262,270,270,270,270,244,242,109,127,128,101,73,70,70,72,99,73,71,33,35,298,272,270,270,270,301,264,186,217,233,236,
+176,177,161,164,222,165,163,204,178,207,176,179,206,59,62,0,92,119,3,2,2,3,1,3,1,3,2,2,2,3,2,2,3,3,2,298,272,270,301,301,271,185,186,187,240,243,270,244,242,2,0,2,298,272,301,301,301,270,301,270,270,270,270,273,299,299,299,272,237,236,270,270,270,270,270,244,241,242,34,127,128,128,101,99,99,99,73,70,71,30,269,270,270,270,270,237,234,234,236,266,
+176,177,190,222,222,191,165,163,204,205,205,206,59,62,89,89,90,2,1,3,2,3,2,2,1,2,1,0,1,3,0,1,2,0,156,158,298,299,299,299,300,185,217,187,298,299,272,302,271,2,2,3,3,298,272,301,270,270,270,270,270,270,273,300,35,33,33,269,270,270,270,270,270,270,270,270,270,244,241,241,242,4,127,128,101,130,130,99,100,36,269,270,270,270,302,270,270,263,266,293,
+176,177,190,191,223,191,222,165,162,162,162,163,88,89,89,120,63,61,3,1,1,2,3,3,3,2,1,3,2,2,1,1,1,3,185,160,157,157,157,157,157,159,186,160,158,3,298,299,300,1,1,2,1,1,298,272,270,270,270,270,270,270,271,40,2,39,37,269,270,270,270,270,270,270,270,270,270,270,270,270,271,34,38,33,127,128,128,128,129,40,269,270,270,270,270,270,270,270,237,234
diff --git a/assets-cg/maps/tileset.tsx b/assets-cg/maps/tileset.tsx
index 6bb32b5..e00d5ac 100644
--- a/assets-cg/maps/tileset.tsx
+++ b/assets-cg/maps/tileset.tsx
@@ -57,9 +57,12 @@
-
-
+
+
+
+
+
@@ -79,8 +82,11 @@
-
-
+
+
+
+
+
@@ -100,8 +106,9 @@
-
-
+
+
+
@@ -360,16 +367,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/assets-cg/tileset.png b/assets-cg/tileset.png
index 59fbd7e..e66d5da 100644
Binary files a/assets-cg/tileset.png and b/assets-cg/tileset.png differ
diff --git a/include/engine.h b/include/engine.h
index aeb56dd..a8eec7b 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -20,7 +20,7 @@ void engine_draw(struct Game const *game);
/*draw the map around the player*/
void engine_draw_map(struct Game const *game);
/*draw the player*/
-void engine_draw_player(struct Player const *player);
+void engine_draw_player(struct Game const *game);
/*move the player to the direction*/
int engine_move(struct Game *game, int direction);
/*update the player animation*/
diff --git a/include/map.h b/include/map.h
index 7149aca..0171932 100644
--- a/include/map.h
+++ b/include/map.h
@@ -25,3 +25,5 @@ enum map_state {
int map_walkable(struct Map const *map, int x, int y);
/*get the tile under the player*/
int map_get_player_tile(struct Game const *game);
+
+void generate_interior_map(struct Game *game);
\ No newline at end of file
diff --git a/include/player.h b/include/player.h
index 1f91275..07bdd85 100644
--- a/include/player.h
+++ b/include/player.h
@@ -21,3 +21,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);
\ No newline at end of file
diff --git a/src/engine.c b/src/engine.c
index af0b117..f3f3749 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -12,82 +12,10 @@
/*draw the current state of the game*/
void engine_draw(struct Game const *game) {
dclear(game->background);
- //engine_draw_map_around_player(game);
engine_draw_map(game);
- engine_draw_player(game->player);
-}
-
-/*draw the map around the player*/
-void engine_draw_map_around_player(struct Game const *game) {
- const int level_width = game->map->w;
- const int taillemap = game->map->w * game->map->h;
- const int posx = game->player->show_x;
- const int posy = game->player->show_y;
-
- const int coo_player_map = game->player->x + game->player->y*level_width; //the index of the player on the map
- int beginmap = coo_player_map - PLAYER_VIEW_X - level_width*PLAYER_VIEW_Y; //compute the theorical top left corner
- int beginline = coo_player_map - PLAYER_VIEW_Y*level_width - coo_player_map%level_width; //index of the tile wich begin the row
-
- //anti begin oob
- if(beginmap < 0) {
- beginmap = game->player->x - PLAYER_VIEW_X;
- if(beginmap < 0) beginmap = 0;
- }
-
- //anti horizontal oob
- if((coo_player_map - PLAYER_VIEW_X)%level_width > coo_player_map%level_width) {
- beginmap = beginline > 0 ? beginline : 0;
- }
-
- int next = game->player->x + PLAYER_VIEW_X + beginmap/level_width * level_width; //index of the top right corner
- int endline = beginmap+level_width-beginmap%level_width-1; //index of the tile wich end the row
-
- if(next > endline) next = endline;
- if(next < 0) next = game->player->x + PLAYER_VIEW_X;
-
- int indypro = game->player->y + PLAYER_VIEW_Y; //y value of the bottom row
- //anti bottom oob
- if(indypro > taillemap/level_width-1) indypro = taillemap/level_width-1;
-
- int endmap = next%level_width + level_width*indypro; //index of the bottom right corner
- int ecart = next - beginmap; //number of column to draw
-
- //player x, y on the compute map
- int xcentre = 0, ycentre = 0;
-
- //calculate the player position in the generated map
- for(int i = beginmap; i < coo_player_map; i++) {
- xcentre++;
-
- if(i == next + ycentre * level_width) {
- ycentre++;
- xcentre=0;
- i = beginmap + ycentre*level_width-1;
- }
- }
-
- int j = 0;
- int x = posx-xcentre;
- for(int i = beginmap; i <= endmap; i++) {
- int y = j + (posy-ycentre);
-
- for(int layer = 0; layer < game->map->nb_layers; layer++) {
- int tile = game->map->layers[layer][i]-1;
- if(tile != -1) {
- int tile_x = tile % TILESET_WIDTH;
- int tile_y = tile / TILESET_WIDTH;
- dsubimage(x * 16 - game->player->anim.dx * 3, y * 16 - game->player->anim.dy * 3,
- game->map->tileset, tile_x * 16, tile_y * 16, 16, 16, DIMAGE_NONE);
- }
- }
-
- x++;
- if(i==beginmap+ecart+j*level_width) {
- j++;
- x=posx-xcentre;
- i = beginmap + j*level_width-1;
- }
- }
+ engine_draw_player(game);
+ dprint(1,15,C_BLACK,"%d:%d",game->camera->x, game->camera->y);
+ dprint(1,30,C_BLACK,"%d:%d",game->map->w, game->map->h);
}
void engine_draw_map(struct Game const *game) {
@@ -99,14 +27,13 @@ void engine_draw_map(struct Game const *game) {
for (int y = -1 ; y <= DHEIGHT / TILE_SIZE + 1; y++) {
for (int x = -1 ; x <= DWIDTH / TILE_SIZE + 1; x++) {
unsigned int tile_id = 0;
- if(game->map->w > x && game->map->h > y) {
- //detect if the map is oob
- int indexY = (y + y_offset / TILE_SIZE);
- int indexX = (x + x_offset / TILE_SIZE);
- if(indexX >= 0 && indexX < game->map->w
- && indexY >= 0 && indexY < game->map->h)
- tile_id = game->map->layers[layer][indexX + indexY * game->map->w];
- }
+ //detect if the map is oob
+ int indexY = (y + y_offset / TILE_SIZE);
+ int indexX = (x + x_offset / TILE_SIZE);
+ if(indexX >= 0 && indexX < game->map->w
+ && indexY >= 0 && indexY < game->map->h)
+ tile_id = game->map->layers[layer][indexX + indexY * game->map->w];
+ //tile_id = game->map->layers[layer][(x + x_offset / TILE_SIZE) + (y + y_offset / TILE_SIZE) * game->map->w];
if (tile_id != 0) {
tile_id--;
@@ -125,9 +52,17 @@ void engine_draw_map(struct Game const *game) {
}
/*draw the player*/
-void engine_draw_player(struct Player const *player) {
- dframe(player->show_x * 16, player->show_y * 16 - 5, player->anim.img); //draw the player 5 pixel up
- dprint(1,1,C_BLACK,"%d:%d",player->x, player->y);
+void engine_draw_player(struct Game const *game) {
+ if(game->map->w > DWIDTH / TILE_SIZE + 1 &&
+ game->map->h > DHEIGHT / TILE_SIZE + 1) {
+ dframe(game->player->show_x * 16, game->player->show_y * 16 - 5, game->player->anim.img); //draw the player 5 pixel up
+ } else {
+ int offset_map_x = (DWIDTH / TILE_SIZE - game->map->w + 1)/2;
+ int offset_map_y = (DHEIGHT / TILE_SIZE - game->map->h + 1)/2;
+ dframe((game->player->x + offset_map_x) * 16,
+ (game->player->y + offset_map_y) * 16 - 5, game->player->anim.img); //draw the player 5 pixel up
+ }
+ dprint(1,1,C_BLACK,"%d:%d",game->player->x, game->player->y);
}
/*move the player to the direction*/
@@ -142,8 +77,11 @@ int engine_move(struct Game *game, int direction) {
game->player->x += dx;
game->player->y += dy;
- game->camera->x += dx*16;
- game->camera->y += dy*16;
+ if(game->map->w > DWIDTH / TILE_SIZE + 1 &&
+ game->map->h > DHEIGHT / TILE_SIZE + 1) {
+ game->camera->x += dx*16;
+ game->camera->y += dy*16;
+ }
game->player->idle = !anim_player_walking(&game->player->anim, 1);
engine_check_position(game);
@@ -160,7 +98,6 @@ int engine_move(struct Game *game, int direction) {
/*update the player animation*/
void engine_tick(struct Game *game, int dt) {
game->player->anim.duration -= dt;
- vec_lerp(game->camera, game->player, 0.05);
if(game->player->anim.duration <= 0) {
game->player->idle = !game->player->anim.function(&game->player->anim, 0);
}
@@ -188,12 +125,8 @@ void engine_check_position(struct Game *game) {
int player_curr_tile = map_get_player_tile(game);
if(player_curr_tile == TILE_DOOR) {
engine_set_background(game, C_BLACK);
+ generate_interior_map(game);
} else {
engine_set_background(game, C_WHITE);
}
-}
-
-void vec_lerp(struct Camera *from, struct Player const *to, float scale) {
- from->x = from->x * (1 - scale) + (to->x*TILE_SIZE + to->x_mid) * scale;
- from->y = from->y * (1 - scale) + (to->y*TILE_SIZE + to->y_mid) * scale;
}
\ No newline at end of file
diff --git a/src/map.c b/src/map.c
index 4a551ca..faa7330 100644
--- a/src/map.c
+++ b/src/map.c
@@ -1,6 +1,8 @@
#include "map.h"
#include "engine.h"
#include "player.h"
+#include "camera.h"
+#include "define.h"
/*check if a tile is walkable*/
int map_walkable(struct Map const *map, int x, int y) {
@@ -15,3 +17,11 @@ int map_get_player_tile(struct Game const *game) {
return game->map->info_map[game->player->x + game->map->w * game->player->y];
return 0;
}
+
+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->x = in_1.w/2 * TILE_SIZE + game->player->x_mid;
+ game->camera->y = in_1.h/2 * TILE_SIZE + game->player->y_mid;
+}
\ No newline at end of file
diff --git a/src/player.c b/src/player.c
index 0ad9d49..78871e8 100644
--- a/src/player.c
+++ b/src/player.c
@@ -21,3 +21,8 @@ int player_facing(struct Game const *game) {
}
return TILE_SOLID;
}
+
+void set_player_xy(struct Player *player, int x, int y) {
+ player->x = x;
+ player->y = y;
+}
\ No newline at end of file