From 911061899d406b215424296ce68cd4ab95ce97f6 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 24 Sep 2022 11:05:22 +0200 Subject: [PATCH] Optimizada la carga del mapa --- data/map/01.map | 5 +- data/map/02.map | 11 +- data/map/02.tmx | 38 ++++- data/map/03.map | 11 +- data/map/04.map | 7 +- data/map/04.tmx | 54 +++++-- data/map/05.map | 11 +- data/map/05.tmx | 44 +++++- data/map/06.map | 5 +- data/map/06.tmx | 36 ++++- data/map/07.map | 7 +- data/map/08.map | 5 +- data/map/09.map | 5 +- data/map/10.map | 7 +- source/game.cpp | 19 +-- source/map.cpp | 395 +++++++++++++++++++++++------------------------- source/map.h | 18 ++- 17 files changed, 369 insertions(+), 309 deletions(-) diff --git a/data/map/01.map b/data/map/01.map index e02e15b..545a246 100644 --- a/data/map/01.map +++ b/data/map/01.map @@ -1,3 +1,4 @@ +tilemap=01.tmx tileset_img=surface.png enemy_file=01.ene bgColor1=0,171,159 @@ -9,10 +10,6 @@ room_down=0 room_left=04.map room_right=02.map -[tilemap] -01.tmx -[/tilemap] - [actors] [diamond] diff --git a/data/map/02.map b/data/map/02.map index b30d70c..b98e8c1 100644 --- a/data/map/02.map +++ b/data/map/02.map @@ -1,3 +1,4 @@ +tilemap=02.tmx tileset_img=surface.png enemy_file=02.ene bgColor1=0,171,159 @@ -7,12 +8,4 @@ bgScroll=true room_up=0 room_down=03.map room_left=01.map -room_right=05.map - -[tilemap] -02.tmx -[/tilemap] - -[actors] - -[/actors] \ No newline at end of file +room_right=05.map \ No newline at end of file diff --git a/data/map/02.tmx b/data/map/02.tmx index 0472be6..2857269 100644 --- a/data/map/02.tmx +++ b/data/map/02.tmx @@ -1,7 +1,41 @@ - + + + +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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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,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, @@ -22,7 +56,6 @@ 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,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,0,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047,2048,2049,2050,2051,2052,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2106,2107,2108,2109,2110,2111,2112,2113,2114,2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2126,2127,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2181,2182,2183,2184,2185,2186,2187,2188,2189,2190,2191,2192,2193,2194,2195,2196,2197,2198,2199,2200,2201,2202,0, @@ -33,6 +66,7 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2557,2558,2559,2560,2561,2562,2563,2564,2565,2566,2567,2568,2569,2570,2571,2572,2573,2574,2575,2576,2577,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,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 diff --git a/data/map/03.map b/data/map/03.map index 1450eb5..2b6164c 100644 --- a/data/map/03.map +++ b/data/map/03.map @@ -1,3 +1,4 @@ +tilemap=03.tmx tileset_img=surface.png enemy_file=03.ene bgColor1=143,86,59 @@ -6,12 +7,4 @@ bgColor2=69,40,60 room_up=02.map room_down=0 room_left=0 -room_right=06.map - -[tilemap] -03.tmx -[/tilemap] - -[actors] - -[/actors] \ No newline at end of file +room_right=06.map \ No newline at end of file diff --git a/data/map/04.map b/data/map/04.map index 9f2b5d6..43dd3db 100644 --- a/data/map/04.map +++ b/data/map/04.map @@ -1,3 +1,4 @@ +tilemap=04.tmx tileset_img=surface.png bgColor1=255,90,100 bgColor2=255,255,100 @@ -6,8 +7,4 @@ bgScroll=true room_up=0 room_down=04.map room_left=04.map -room_right=01.map - -[tilemap] -04.tmx -[/tilemap] \ No newline at end of file +room_right=01.map \ No newline at end of file diff --git a/data/map/04.tmx b/data/map/04.tmx index a9efc27..ad37899 100644 --- a/data/map/04.tmx +++ b/data/map/04.tmx @@ -1,8 +1,8 @@ - + - + 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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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,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,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,2551,2552,2553,2554,2555,2556,2557,2558,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,2626,2627,2628,2629,2630,2631,2632,2633,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,2701,2702,2703,2704,2705,2706,2707,2708,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,2776,2777,2778,2779,2780,2781,2782,2783,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,2551,2552,2553,2554,2555,2556,2557,2558,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,2626,2627,2628,2629,2630,2631,2632,2633,0,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0,0,0,0,0,0,0,0,0,0,0,0,0, -2108,2109,2110,2111,2112,2113,2114,2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2126,2127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -2183,2184,2185,2186,2187,2188,2189,2190,2191,2192,2193,2194,2195,2196,2197,2198,2199,2200,2201,2202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -2258,2259,2260,2261,2262,2263,2264,2265,2266,2267,2268,2269,2270,2271,2272,2273,2274,2275,2276,2277,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -2333,2334,2335,2336,2337,2338,2339,2340,2341,2342,2343,2344,2345,2346,2347,2348,2349,2350,2351,2352,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -2408,2409,2410,2411,2412,2413,2414,2415,2416,2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -2483,2484,2485,2486,2487,2488,2489,2490,2491,2492,2493,2494,2495,2496,2497,2498,2499,2500,2501,2502,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -2558,2559,2560,2561,2562,2563,2564,2565,2566,2567,2568,2569,2570,2571,2572,2573,2574,2575,2576,2577,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,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, diff --git a/data/map/05.map b/data/map/05.map index be5028b..e14dde5 100644 --- a/data/map/05.map +++ b/data/map/05.map @@ -1,3 +1,4 @@ +tilemap=05.tmx tileset_img=surface.png bgColor1=0,171,159 bgColor2=144,225,231 @@ -6,12 +7,4 @@ bgScroll=true room_up=0 room_down=06.map room_left=02.map -room_right=07.map - -[tilemap] -05.tmx -[/tilemap] - -[actors] - -[/actors] \ No newline at end of file +room_right=07.map \ No newline at end of file diff --git a/data/map/05.tmx b/data/map/05.tmx index f56046a..0d6a158 100644 --- a/data/map/05.tmx +++ b/data/map/05.tmx @@ -1,19 +1,53 @@ - + + + +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,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,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,2176,2177,2178,2179,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,2251,2252,2253,2254,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,2326,2327,2328,2329,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,2401,2402,2403,2404,0,0,0,0,0,0,0, +0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2251,2252,2253,2254,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,2326,2327,2328,2329,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,2401,2402,2403,2404,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,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/data/map/06.map b/data/map/06.map index e4dc50a..243c5c5 100644 --- a/data/map/06.map +++ b/data/map/06.map @@ -1,3 +1,4 @@ +tilemap=06.tmx tileset_img=surface.png bgColor1=143,86,59 bgColor2=69,40,60 @@ -6,7 +7,3 @@ room_up=05.map room_down=0 room_left=03.map room_right=0 - -[tilemap] -06.tmx -[/tilemap] diff --git a/data/map/06.tmx b/data/map/06.tmx index 5451067..395f219 100644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,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,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,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 + + 13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14,13,14, diff --git a/data/map/07.map b/data/map/07.map index 1730f99..18ed391 100644 --- a/data/map/07.map +++ b/data/map/07.map @@ -1,3 +1,4 @@ +tilemap=07.tmx tileset_img=surface.png bgColor1=0,171,159 bgColor2=144,225,231 @@ -5,8 +6,4 @@ bgColor2=144,225,231 room_up=08.map room_down=0 room_left=05.map -room_right=0 - -[tilemap] -07.tmx -[/tilemap] \ No newline at end of file +room_right=0 \ No newline at end of file diff --git a/data/map/08.map b/data/map/08.map index f60fe38..8b4f59c 100644 --- a/data/map/08.map +++ b/data/map/08.map @@ -1,3 +1,4 @@ +tilemap=08.tmx tileset_img=surface.png bgColor1=0,171,159 bgColor2=144,225,231 @@ -6,7 +7,3 @@ room_up=0 room_down=07.map room_left=10.map room_right=09.map - -[tilemap] -08.tmx -[/tilemap] diff --git a/data/map/09.map b/data/map/09.map index 36d597a..466a9a3 100644 --- a/data/map/09.map +++ b/data/map/09.map @@ -1,3 +1,4 @@ +tilemap=09.tmx tileset_img=surface.png bgColor1=0,171,159 bgColor2=144,225,231 @@ -6,7 +7,3 @@ room_up=0 room_down=0 room_left=08.map room_right=0 - -[tilemap] -09.tmx -[/tilemap] diff --git a/data/map/10.map b/data/map/10.map index 62ebbda..ccf0d68 100644 --- a/data/map/10.map +++ b/data/map/10.map @@ -1,3 +1,4 @@ +tilemap=10.tmx tileset_img=surface.png bgColor1=0,171,159 bgColor2=144,225,231 @@ -5,8 +6,4 @@ bgColor2=144,225,231 room_up=0 room_down=05.map room_left=10.map -room_right=08.map - -[tilemap] -10.tmx -[/tilemap] +room_right=08.map \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index ea21986..52a5ca3 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -353,25 +353,12 @@ void Game::checkIfPlayerIsAlive() // Mata al jugador void Game::killPlayer() { - // if (player->getInvincible()) - //{ - // return; - // } - + // Decrementa el marcador de vidas board.lives--; - // Destruye el mapa, el jugador y los enemigos - // delete map; + // Destruye el jugador delete player; - // delete enemyEngine; - // Sonido - // JA_PlaySound(deathSound); - - // setBlackScreen(); - - // Crea el nuevo mapa, el nuevo jugador y nuevos enemigos - // map = new Map(asset->get("01.map"), renderer, asset, itemTracker); + // Crea el nuevo jugador player = new Player(spawnPoint, renderer, asset, input, map, debug, &board.diamonds); - // enemyEngine = new EnemyEngine(renderer, asset, player, map, asset->get(map->getEnemyFile())); } \ No newline at end of file diff --git a/source/map.cpp b/source/map.cpp index f28fc4d..fc66219 100644 --- a/source/map.cpp +++ b/source/map.cpp @@ -18,26 +18,37 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *it this->renderer = renderer; this->itemTracker = itemTracker; - // Crea los objetos - load(file); - texture_tile = new LTexture(renderer, asset->get(tileset_img)); - tileset_width = texture_tile->getWidth() / tile_size; - // Crea las texturas para dibujar el mapa map_layerBG = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); if (map_layerBG == NULL) + { printf("Error: map_layer0 could not be created!\nSDL Error: %s\n", SDL_GetError()); + } + SDL_SetTextureBlendMode(map_layerBG, SDL_BLENDMODE_BLEND); map_layer0 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); if (map_layer0 == NULL) + { printf("Error: map_layer0 could not be created!\nSDL Error: %s\n", SDL_GetError()); + } + SDL_SetTextureBlendMode(map_layer0, SDL_BLENDMODE_BLEND); map_layer1 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); if (map_layer1 == NULL) + { printf("Error: map_layer1 could not be created!\nSDL Error: %s\n", SDL_GetError()); + } + SDL_SetTextureBlendMode(map_layer1, SDL_BLENDMODE_BLEND); + + // Crea los objetos + loadMapFile(file); + texture_tile = new LTexture(renderer, asset->get(tileset_img)); + tileset_width = texture_tile->getWidth() / tile_size; + + loadMapTileFile(asset->get(tileMapFile)); // Pinta el mapa en las texturas - fillMapTexture(); + // fillMapTexture(); } // Destructor @@ -56,8 +67,8 @@ Map::~Map() actors.clear(); } -// Carga las variables desde un fichero -bool Map::load(std::string file_path) +// Carga las variables desde un fichero de mapa +bool Map::loadMapFile(std::string file_path) { // Indicador de éxito en la carga bool success = true; @@ -73,130 +84,8 @@ bool Map::load(std::string file_path) printf("Reading file %s\n\n", filename.c_str()); while (std::getline(file, line)) { - // Si la linea contiene el texto [tilemap] se realiza el proceso de carga del fichero tmx - if (line == "[tilemap]") - { - do - { - std::getline(file, line); - if (line.find(".tmx") != std::string::npos) - { - std::ifstream file2(asset->get(line)); // Abre el fichero tmx - if (file2.good()) - { - bool map_col_read = false; - bool map_BG_read = false; - bool map_l0_read = false; - bool map_l1_read = false; - while (std::getline(file2, line)) // Lee el fichero linea a linea - { - if (!map_BG_read) - { // Lee lineas hasta que encuentre donde empiezan los datos del mapa - int pos = 0; - do - { - std::getline(file2, line); - pos = line.find("data encoding"); - } while (pos == (int)std::string::npos); - - do - { // Se introducen los valores separados por comas en un vector - map_BG_read = true; - std::getline(file2, line); - if (line != "") - { - std::stringstream ss(line); - std::string tmp; - while (getline(ss, tmp, ',')) - { - tilemap_BG.push_back(std::stoi(tmp)); - } - } - } while (line != ""); - } - - if (!map_l0_read) - { // Lee lineas hasta que encuentre donde empiezan los datos del mapa - int pos = 0; - do - { - std::getline(file2, line); - pos = line.find("data encoding"); - } while (pos == (int)std::string::npos); - - do - { // Se introducen los valores separados por comas en un vector - map_l0_read = true; - std::getline(file2, line); - if (line != "") - { - std::stringstream ss(line); - std::string tmp; - while (getline(ss, tmp, ',')) - { - tilemap_l0.push_back(std::stoi(tmp)); - } - } - } while (line != ""); - } - - if (!map_l1_read) - { // Lee lineas hasta que encuentre donde empiezan los datos del mapa - int pos = 0; - do - { - std::getline(file2, line); - pos = line.find("data encoding"); - } while (pos == (int)std::string::npos); - - do - { // Se introducen los valores separados por comas en un vector - map_l1_read = true; - std::getline(file2, line); - if (line != "") - { - std::stringstream ss(line); - std::string tmp; - while (getline(ss, tmp, ',')) - { - tilemap_l1.push_back(std::stoi(tmp)); - } - } - } while (line != ""); - } - - if (!map_col_read) - { // Lee lineas hasta que encuentre donde empiezan los datos del mapa - int pos = 0; - do - { - std::getline(file2, line); - pos = line.find("data encoding"); - } while (pos == (int)std::string::npos); - - do - { // Se introducen los valores separados por comas en un vector - map_col_read = true; - std::getline(file2, line); - if (line != "") - { - std::stringstream ss(line); - std::string tmp; - while (getline(ss, tmp, ',')) - { - collisionmap.push_back(std::stoi(tmp)); - } - } - } while (line != ""); - } - } - } - } - } while (line != "[/tilemap]"); - } - // Si la linea contiene el texto [actor] se realiza el proceso de carga de los actores - else if (line == "[actors]") + if (line == "[actors]") { do { @@ -295,13 +184,136 @@ bool Map::load(std::string file_path) return success; } +// Carga las variables y texturas desde un fichero de mapa de tiles +bool Map::loadMapTileFile(std::string file_path) +{ + std::vector tilemap; + + std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); + std::string line; + std::ifstream file(file_path); + + // El fichero se puede abrir + if (file.good()) + { + // Procesa el fichero linea a linea + printf("Reading file %s\n\n", filename.c_str()); + + while (std::getline(file, line)) + { // Lee el fichero linea a linea + if (line.find("name=\"estatico\"") != std::string::npos) + { + // Salta una linea y lee la siguiente + std::getline(file, line); + std::getline(file, line); + while (line != "") + { // Procesa lineas mientras haya + std::stringstream ss(line); + std::string tmp; + while (getline(ss, tmp, ',')) + { + tilemap.push_back(std::stoi(tmp)); + } + + // Lee la siguiente linea + std::getline(file, line); + } + + fillGradientTexture(*map_layerBG); + fillMapTexture(*map_layerBG, tilemap, false); + tilemap.clear(); + } + + if (line.find("name=\"fondo\"") != std::string::npos) + { + // Salta una linea y lee la siguiente + std::getline(file, line); + std::getline(file, line); + while (line != "") + { // Procesa lineas mientras haya + std::stringstream ss(line); + std::string tmp; + while (getline(ss, tmp, ',')) + { + tilemap.push_back(std::stoi(tmp)); + } + + // Lee la siguiente linea + std::getline(file, line); + } + + fillMapTexture(*map_layer0, tilemap, true); + tilemap.clear(); + } + + if (line.find("name=\"mapa\"") != std::string::npos) + { + // Salta una linea y lee la siguiente + std::getline(file, line); + std::getline(file, line); + while (line != "") + { // Procesa lineas mientras haya + std::stringstream ss(line); + std::string tmp; + while (getline(ss, tmp, ',')) + { + tilemap.push_back(std::stoi(tmp)); + } + + // Lee la siguiente linea + std::getline(file, line); + } + + fillMapTexture(*map_layer1, tilemap, true); + tilemap.clear(); + } + + if (line.find("name=\"colisiones\"") != std::string::npos) + { + // Salta una linea y lee la siguiente + std::getline(file, line); + std::getline(file, line); + while (line != "") + { // Procesa lineas mientras haya + std::stringstream ss(line); + std::string tmp; + while (getline(ss, tmp, ',')) + { + collisionmap.push_back(std::stoi(tmp)); + } + + // Lee la siguiente linea + std::getline(file, line); + } + } + } + + // Cierra el fichero + printf("Closing file %s\n\n", filename.c_str()); + file.close(); + } + // El fichero no se puede abrir + else + { + printf("Warning: Unable to open %s file\n", filename.c_str()); + return false; + } + + return true; +} + // Asigna variables a partir de dos cadenas bool Map::setVars(std::string var, std::string value) { // Indicador de éxito en la asignación bool success = true; - if (var == "tileset_img") + if (var == "tilemap") + { + tileMapFile = value; + } + + else if (var == "tileset_img") { tileset_img = value; } @@ -451,92 +463,58 @@ bool Map::setActor(actor_t *actor, SDL_Point *p1, SDL_Point *p2, std::string var return success; } +// Pinta el degradado en la textura +void Map::fillGradientTexture(SDL_Texture &layer) +{ + // Cambia el puntero del renderizador a la textura + SDL_SetRenderTarget(renderer, &layer); + + // Dibuja el degradado de fondo + const float num_lines = PLAY_AREA_BOTTOM - PLAY_AREA_TOP; + + for (int i = PLAY_AREA_TOP; i < PLAY_AREA_BOTTOM; ++i) + { + float step = ((float)i / num_lines); + int r = bgColor1.r + ((bgColor2.r - bgColor1.r) * step); + int g = bgColor1.g + ((bgColor2.g - bgColor1.g) * step); + int b = bgColor1.b + ((bgColor2.b - bgColor1.b) * step); + SDL_SetRenderDrawColor(renderer, r, g, b, 0xFF); + SDL_RenderDrawLine(renderer, PLAY_AREA_LEFT, i, PLAY_AREA_RIGHT, i); + } + + // Vuelve a colocar el renderizador apuntando a la pantalla + SDL_SetRenderTarget(renderer, nullptr); +} // Crea la textura con el mapeado de la habitación -void Map::fillMapTexture() +void Map::fillMapTexture(SDL_Texture &layer, std::vector tilemap, bool clean) { // Crea variables SDL_Rect clip = {0, 0, tile_size, tile_size}; - // Rellena la capa BG + // Cambia el puntero del renderizador a la textura + SDL_SetRenderTarget(renderer, &layer); + + // Limpia la textura + if (clean) { - SDL_SetRenderTarget(renderer, map_layerBG); - SDL_SetTextureBlendMode(map_layerBG, SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); + SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); SDL_RenderClear(renderer); + } - // Dibuja el degradado de fondo - const float num_lines = PLAY_AREA_BOTTOM - PLAY_AREA_TOP; - - for (int i = PLAY_AREA_TOP; i < PLAY_AREA_BOTTOM; ++i) + // Dibuja el mapeado de tiles + for (int y = 0; y < map_height; ++y) + for (int x = 0; x < map_width; ++x) { - float step = ((float)i / num_lines); - int r = bgColor1.r + ((bgColor2.r - bgColor1.r) * step); - int g = bgColor1.g + ((bgColor2.g - bgColor1.g) * step); - int b = bgColor1.b + ((bgColor2.b - bgColor1.b) * step); - SDL_SetRenderDrawColor(renderer, r, g, b, 0xFF); - SDL_RenderDrawLine(renderer, 0, i, 319, i); + // Resta uno porque Tiled almacena los indices empezando de 1 en vez de 0. + // El problema es que los tiles vacios los pone como 0 y aqui pasan a ser -1 + // con lo que esta pintando desde fuera de la textura + clip.x = ((tilemap[(y * map_width) + x] - 1) % tileset_width) * tile_size; + clip.y = ((tilemap[(y * map_width) + x] - 1) / tileset_width) * tile_size; + texture_tile->render(renderer, x * tile_size, y * tile_size, &clip); } - // Dibuja el mapeado de tiles - for (int y = 0; y < map_height; ++y) - for (int x = 0; x < map_width; ++x) - { - // Resta uno porque Tiled almacena los indices empezando de 1 en vez de 0. - // El problema es que los tiles vacios los pone como 0 y aqui pasan a ser -1 - // con lo que esta pintando desde fuera de la textura - clip.x = ((tilemap_BG[(y * map_width) + x] - 1) % tileset_width) * tile_size; - clip.y = ((tilemap_BG[(y * map_width) + x] - 1) / tileset_width) * tile_size; - texture_tile->render(renderer, x * tile_size, y * tile_size, &clip); - } - tilemap_BG.clear(); - } - - // Rellena la capa 0 - { - SDL_SetRenderTarget(renderer, map_layer0); - SDL_SetTextureBlendMode(map_layer0, SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); - SDL_RenderClear(renderer); - - // Dibuja el mapeado de tiles - for (int y = 0; y < map_height; ++y) - for (int x = 0; x < map_width; ++x) - { - // Resta uno porque Tiled almacena los indices empezando de 1 en vez de 0. - // El problema es que los tiles vacios los pone como 0 y aqui pasan a ser -1 - // con lo que esta pintando desde fuera de la textura - clip.x = ((tilemap_l0[(y * map_width) + x] - 1) % tileset_width) * tile_size; - clip.y = ((tilemap_l0[(y * map_width) + x] - 1) / tileset_width) * tile_size; - texture_tile->render(renderer, x * tile_size, y * tile_size, &clip); - } - - tilemap_l0.clear(); - } - - // Rellena la capa 1 - { - SDL_SetRenderTarget(renderer, map_layer1); - SDL_SetTextureBlendMode(map_layer1, SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); - SDL_RenderClear(renderer); - - // Dibuja el mapeado de tiles - for (int y = 0; y < map_height; ++y) - for (int x = 0; x < map_width; ++x) - { - // Resta uno porque Tiled almacena los indices empezando de 1 en vez de 0. - // El problema es que los tiles vacios los pone como 0 y aqui pasan a ser -1 - // con lo que esta pintando desde fuera de la textura - clip.x = ((tilemap_l1[(y * map_width) + x] - 1) % tileset_width) * tile_size; - clip.y = ((tilemap_l1[(y * map_width) + x] - 1) / tileset_width) * tile_size; - texture_tile->render(renderer, x * tile_size, y * tile_size, &clip); - } - - tilemap_l1.clear(); - } - - // Vuelve a colocar el renderizador + // Vuelve a colocar el renderizador apuntando a la pantalla SDL_SetRenderTarget(renderer, nullptr); } @@ -553,7 +531,6 @@ void Map::render() void Map::renderLayerBG() { // Dibuja la textura con el mapa en pantalla - //SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT}; SDL_RenderCopy(renderer, map_layerBG, nullptr, nullptr); } @@ -575,7 +552,6 @@ void Map::renderLayer0() } else { - // SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT}; SDL_RenderCopy(renderer, map_layer0, nullptr, nullptr); } } @@ -584,7 +560,6 @@ void Map::renderLayer0() void Map::renderLayer1() { // Dibuja la textura con el mapa en pantalla - //SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT}; SDL_RenderCopy(renderer, map_layer1, nullptr, nullptr); } @@ -802,5 +777,5 @@ std::string Map::getEnemyFile() void Map::reLoadTextures() { texture_tile->reLoad(); - fillMapTexture(); + // fillMapTexture(); } \ No newline at end of file diff --git a/source/map.h b/source/map.h index 077b1f3..06710c3 100644 --- a/source/map.h +++ b/source/map.h @@ -44,9 +44,7 @@ private: std::string room_right; // Identificador de la habitación que se encuentra a la derecha std::string enemy_file; // Fichero con los enemigos para la habitación std::string tileset_img; // Imagen con los graficos para la habitación - std::vector tilemap_BG; // Indice de los tiles a dibujar de la capa BG en la habitación - std::vector tilemap_l0; // Indice de los tiles a dibujar de la capa 0 en la habitación - std::vector tilemap_l1; // Indice de los tiles a dibujar de la capa 1 en la habitación + std::string tileMapFile; // Fichero con el mapa de indices de tile std::vector collisionmap; // Indice con los tipos de tile de la habitación LTexture *texture_tile; // Textura con los graficos de los tiles habitación SDL_Texture *map_layerBG; // Textura para dibujar la capa BG del mapa de la habitación @@ -64,8 +62,11 @@ private: int map_height; // Alto del mapa en tiles int tileset_width; // Ancho del tileset en tiles - // Carga las variables desde un fichero - bool load(std::string file); + // Carga las variables desde un fichero de mapa + bool loadMapFile(std::string file); + + // Carga las variables y texturas desde un fichero de mapa de tiles + bool loadMapTileFile(std::string file); // Asigna variables a partir de dos cadenas bool setVars(std::string var, std::string value); @@ -73,8 +74,11 @@ private: // Asigna variables a una estructura actor_t bool setActor(actor_t *actor, SDL_Point *p1, SDL_Point *p2, std::string var, std::string value); - // Pinta el mapa de la habitación en la textura - void fillMapTexture(); + // Pinta el degradado en la textura + void fillGradientTexture(SDL_Texture &layer); + + // Pinta el mapa de tiles en la textura + void fillMapTexture(SDL_Texture &layer, std::vector tilemap, bool clean); public: // Constructor