From 5931470800c43260f600303d1231dbaf586f26fc Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 9 Feb 2021 22:28:27 -0500 Subject: Map changing! Also removed some dependencies on the Renderer. More changes need to be made. Fading to black before the change would be good. And making sure the characters are facing the right direction. Maybe that code shouldn't live in Game, either. Later we also want to combine the tilesets for these two maps (and any others that are on Tanetane). --- res/maps/map1.tmx | 7 +- res/maps/map2.tmx | 712 +++++++++++++++++++++++++++++++++++++++++ res/maps/map2_tiles.png | Bin 0 -> 18049 bytes res/scripts/map1_off_right.lua | 9 + src/animation_system.cpp | 6 +- src/animation_system.h | 3 +- src/camera_system.cpp | 6 +- src/camera_system.h | 4 +- src/game.cpp | 60 ++++ src/game.h | 4 +- src/main.cpp | 43 +-- src/map.cpp | 5 +- src/map.h | 12 +- src/renderer.cpp | 19 +- src/renderer.h | 3 + src/script_system.cpp | 6 + src/sprite.h | 2 +- src/system.h | 2 + src/transform_system.cpp | 8 + src/transform_system.h | 2 + 20 files changed, 846 insertions(+), 67 deletions(-) create mode 100644 res/maps/map2.tmx create mode 100644 res/maps/map2_tiles.png create mode 100644 res/scripts/map1_off_right.lua diff --git a/res/maps/map1.tmx b/res/maps/map1.tmx index 9b1d1b1..282b2ed 100644 --- a/res/maps/map1.tmx +++ b/res/maps/map1.tmx @@ -1,5 +1,5 @@ - + @@ -779,6 +779,11 @@ + + + + + diff --git a/res/maps/map2.tmx b/res/maps/map2.tmx new file mode 100644 index 0000000..5bbe0c6 --- /dev/null +++ b/res/maps/map2.tmx @@ -0,0 +1,712 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,67,68,2147483716,2147483715,69,70,63,63,63,63,63,63,63,63,63, +62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,71,72,2147483720,2147483719,65,66,73,63,63,63,63,63,63,63,63, +62,62,62,62,62,62,62,63,63,63,63,63,63,63,74,75,76,77,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,78,79,80,70,70,63,63,63,63,63,63,63,63,63,63, +62,62,62,62,62,62,62,63,63,63,63,63,63,63,81,81,81,81,63,63,63,63,62,62,62,62,62,81,81,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,82,83,84,64,65,66,73,63,63,63,63,63,63,63,63, +74,75,76,77,62,62,62,81,81,81,81,81,81,81,63,63,63,63,63,63,62,62,62,75,76,85,86,75,76,77,81,62,62,62,62,62,62,87,87,87,63,63,64,65,66,73,64,65,66,88,89,90,70,70,63,65,66,73,64,65,66,73,63,63, +74,75,76,77,62,62,62,2147483739,2147483740,93,94,81,81,81,63,63,63,63,62,62,62,75,76,95,86,75,76,95,86,75,76,77,74,75,76,77,64,65,66,73,87,87,87,87,87,87,63,63,70,70,70,70,64,65,66,73,70,70,87,87,87,87,63,63, +81,81,81,81,62,62,96,93,94,97,98,93,94,99,63,63,63,63,63,75,76,77,92,91,100,91,91,100,2147483740,81,74,75,76,40,86,75,76,73,64,65,66,73,63,63,63,63,64,65,66,73,70,70,70,70,64,65,66,73,63,63,63,63,63,63, +62,62,62,62,96,93,94,97,98,93,94,99,2147483749,63,63,63,63,63,63,81,92,91,101,102,98,93,94,99,2147483749,2147483740,103,104,105,106,87,87,87,107,87,108,109,65,66,63,63,63,63,2147483718,2147483757,2147483756,2147483735,70,70,70,70,70,64,65,66,73,63,63,63,63, +62,62,62,62,63,62,1073741915,1073741915,1073741934,111,102,63,63,63,63,63,63,63,91,100,101,102,102,112,113,114,115,102,3221225573,3221225564,116,1073741941,1073741942,119,69,65,66,73,87,120,121,122,63,63,63,63,63,2147483770,2147483769,2147483768,2147483771,70,70,70,70,119,69,70,70,63,63,63,63,63, +62,62,62,63,63,75,76,77,1073741916,1073741915,1073741925,102,63,63,63,63,63,63,63,102,112,113,102,102,102,111,102,3221225573,3221225564,116,1073741941,1073741942,124,125,87,87,87,87,87,87,64,65,66,73,63,63,63,70,70,70,70,70,70,70,70,70,40,65,66,73,63,63,63,63, +62,62,62,63,63,62,81,103,104,81,1073741916,63,63,63,63,63,63,63,102,126,114,115,102,102,102,102,3221225573,63,63,81,117,63,63,87,87,87,87,87,87,87,87,87,87,63,63,63,63,63,63,70,70,70,70,70,70,70,106,70,70,63,63,63,63,63, +62,62,62,62,63,63,63,81,81,81,81,81,81,63,63,63,63,63,63,102,102,102,102,102,63,3221225573,3221225564,63,63,63,63,63,63,63,63,87,87,87,87,87,87,119,69,87,63,63,63,63,63,63,2147483775,2147483776,2147483775,118,129,70,130,127,127,63,63,63,63,63, +62,62,62,62,62,63,63,63,63,81,81,75,76,81,63,63,63,63,102,114,115,102,102,63,63,63,63,63,63,63,63,63,63,63,63,63,63,87,2147483779,127,132,118,87,63,63,63,63,63,63,63,2147483781,134,2147483783,117,2147483776,63,63,63,63,63,63,63,63,63, +62,62,62,62,62,63,63,63,63,81,81,81,74,75,76,77,98,93,94,99,102,102,102,102,63,63,63,63,63,63,63,63,63,63,63,63,63,132,2147483765,136,137,117,132,132,63,63,63,63,63,75,76,77,103,104,133,75,63,63,63,63,63,63,63,63, +62,62,74,75,76,77,63,63,81,81,74,75,76,85,86,75,76,102,102,102,114,115,102,63,63,63,63,63,63,63,63,63,63,63,63,63,63,81,81,103,104,81,74,75,76,77,63,63,63,134,134,136,137,134,74,75,76,63,63,63,63,63,63,63, +62,62,81,81,81,81,63,63,63,63,104,1073741941,3221225589,103,104,81,81,1073741915,1073741925,138,102,102,102,93,98,93,94,99,102,63,63,63,74,75,76,77,63,63,63,81,81,81,81,81,63,63,63,63,63,75,76,77,2147483785,2147483784,134,134,63,63,63,63,63,63,63,63, +62,62,62,62,62,63,63,63,63,63,1073741941,1073741942,3221225590,3221225589,74,75,76,77,1073741916,1073741925,102,102,98,93,94,139,98,93,94,99,63,63,81,81,81,81,63,63,81,81,81,103,104,81,63,63,63,63,63,63,134,134,134,134,74,75,76,63,63,63,63,63,63,63, +62,62,62,62,62,63,63,63,64,65,66,73,140,3221225590,1073741952,3221225589,135,103,104,1073741916,102,141,142,102,102,138,2147483791,2147483792,2147483792,93,94,99,102,102,63,63,74,75,76,77,81,81,81,75,74,75,76,77,63,75,76,77,2147483748,91,2147483748,2147483739,2147483740,63,63,63,63,63,63,63, +62,62,64,65,66,73,64,65,66,73,140,140,140,140,140,3221225590,1073741952,1073741952,1073741952,63,63,102,102,2147483750,2147483791,2147483792,2147483793,2147483794,147,93,147,93,94,99,63,63,63,81,81,103,104,81,74,75,76,81,81,81,63,63,102,102,102,102,102,102,2147483749,63,74,75,76,77,63,63, +64,65,66,73,64,65,66,73,140,140,140,140,140,63,63,140,140,63,63,63,63,2147483792,144,2147483792,2147483793,147,147,63,63,65,66,73,63,63,63,63,63,63,63,81,81,81,81,81,63,63,63,63,98,93,94,99,111,102,126,102,63,63,81,81,81,81,63,63, +66,73,140,119,69,140,2147483766,2147483776,2147483776,118,124,125,140,65,66,63,63,63,63,63,63,147,147,63,63,147,64,65,66,73,147,63,63,63,63,63,63,63,66,1073741952,3221225589,135,74,75,76,77,63,63,63,63,102,102,114,115,98,93,94,99,63,63,63,63,63,63, +148,65,66,73,2147483766,2147483776,2147483765,103,104,117,118,1073741964,140,63,63,63,63,63,63,63,63,63,63,63,63,63,147,147,147,147,63,63,63,63,63,63,64,65,66,73,3221225590,3221225604,3221225589,116,81,63,63,63,98,93,94,99,138,102,102,102,98,93,94,99,63,63,63,63, +149,150,118,2147483766,2147483765,81,1073741941,3221225600,3221225589,81,117,63,63,140,65,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,87,106,87,124,125,3221225590,1073741952,3221225599,3221225604,63,63,63,63,102,102,102,102,102,141,142,102,98,93,94,99,63,63, +151,152,117,2147483765,81,1073741941,1073741942,2147483788,3221225590,136,137,75,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,87,87,119,69,87,87,87,87,106,87,63,63,63,63,75,76,102,1073741915,1073741915,1073741925,102,102,126,102,3221225573,63,63,63,63, +151,152,81,81,81,140,140,63,63,81,74,75,76,77,63,63,63,63,74,75,76,77,63,63,63,63,63,63,63,63,63,65,66,73,64,65,66,73,87,87,87,87,87,130,119,69,87,63,63,63,63,75,76,77,1073741916,3221225563,3221225572,3221225563,3221225563,75,63,63,63,63, +63,63,63,63,63,63,63,63,63,81,81,81,74,75,76,77,63,63,81,81,81,81,63,63,63,63,63,63,63,63,63,87,40,65,66,73,78,79,80,87,87,87,87,87,87,63,63,63,63,63,63,63,63,134,136,137,134,133,116,134,74,75,63,63, +63,63,63,63,63,63,63,63,63,81,81,81,81,81,81,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,130,106,87,87,87,82,83,84,87,87,87,87,63,63,63,63,63,63,63,63,63,63,63,134,134,116,134,74,75,76,77,63,63, +63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,81,81,63,63,118,130,87,87,87,88,89,90,106,87,65,66,63,63,63,63,63,63,63,63,134,74,75,76,77,136,137,134,134,74,75,63,63, +63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,73,64,65,66,73,74,75,76,77,81,117,118,124,125,87,87,87,87,108,109,87,87,63,63,63,74,75,76,77,74,75,76,77,134,133,134,134,134,133,63,63,63,63, +63,63,74,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,73,40,65,66,73,2147483735,75,76,77,74,75,76,77,117,127,118,87,87,87,123,120,121,63,63,63,63,63,81,81,81,81,63,134,134,136,137,134,1073741977,1073741952,63,63,1073741887,63,63,63, +63,63,74,75,76,77,63,63,63,63,63,63,63,63,63,63,63,87,3221225618,3221225618,106,3221225618,3221225618,2147483766,2147483775,2147483765,81,103,104,81,81,81,133,81,117,118,87,87,87,87,87,87,63,63,63,63,63,63,63,63,63,63,134,134,1073741977,1073741952,1073741955,1073741911,63,63,63,63,63,63, +63,63,81,81,81,81,63,63,63,63,63,63,63,65,66,73,3221225618,3221225618,3221225618,119,69,3221225618,2147483766,2147483765,74,75,76,77,81,81,103,104,81,103,104,104,63,63,63,127,2147483765,63,63,63,63,63,63,63,63,63,63,63,1073741952,1073741956,1073741955,1073741911,64,65,66,73,63,63,63,63, +63,63,63,63,63,63,63,63,63,63,63,63,3221225618,3221225618,64,65,66,73,124,125,3221225618,87,3221225590,3221225589,136,137,81,103,104,81,81,137,81,136,137,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,73,2147483773,2147483772,87,87,87,63,63,63,63,63, +154,154,154,154,63,63,63,63,98,93,94,99,1073741968,3221225616,3221225617,3221225618,3221225618,3221225618,3221225618,3221225618,3221225618,3221225618,3221225618,3221225590,3221225589,2147483785,2147483784,136,137,81,81,81,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,87,87,87,87,87,64,65,66,73,63,63,63,63, +154,154,154,154,63,102,98,93,94,139,98,93,94,99,3221225615,3221225617,3221225618,3221225618,1073741970,1073741970,1073741970,1073741970,1073741970,1073741970,3221225590,136,137,63,63,81,81,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,62,62,62,62,75,66,73,87,87,87,87,63,63,63,63,63,63, +154,154,154,154,98,93,94,99,111,112,113,102,102,102,102,3221225615,3221225617,70,1073741970,1073741970,1073741970,1073741970,1073741970,1073741970,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,62,62,62,62,62,62,66,87,87,87,64,65,66,73,63,63,63,63, +154,154,154,154,63,102,102,114,115,102,102,102,63,63,63,63,63,3221225617,1073741970,1073741970,1073741970,1073741970,64,65,66,73,63,63,63,63,74,75,76,77,63,63,63,63,63,63,63,62,62,62,62,62,62,62,62,62,64,65,66,73,87,87,87,87,63,63,63,63,63,63, +154,154,154,154,63,63,63,102,102,3221225573,1073741915,1073741915,63,63,63,63,63,63,63,2147483757,2147483756,2147483735,1073741970,1073741970,1073741969,93,94,99,63,63,81,81,81,81,63,63,74,75,76,77,74,75,76,77,62,75,76,62,64,65,66,73,87,87,87,108,109,63,63,63,63,63,63,63, +154,154,154,154,63,63,63,1073741915,1073741915,3221225564,133,63,63,63,63,63,63,63,63,2147483769,2147483768,2147483771,1073741970,1073741969,1073741967,102,63,63,63,63,63,63,63,63,63,63,81,81,81,75,76,77,74,75,76,85,86,75,76,153,128,131,87,87,123,120,121,63,63,63,63,63,63,63, +154,154,154,154,63,63,63,133,1073741941,63,63,63,63,63,63,63,63,63,63,2147483735,2147483735,2147483735,1073741969,1073741967,98,93,94,99,102,63,63,63,63,63,63,63,63,63,63,75,62,103,104,81,81,92,100,91,91,91,2147483740,153,128,131,87,87,87,63,63,63,63,63,63,63, +154,154,154,154,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,1073741968,1073741968,1073741968,1073741967,138,102,115,98,93,94,99,102,102,102,102,74,75,76,77,74,75,76,77,81,92,91,101,98,93,94,99,2147483749,91,2147483740,153,2147483801,63,63,63,74,75,76,77,63,63, +154,154,154,154,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,1073741925,138,3221225573,1073741915,75,74,75,76,77,74,75,76,77,74,75,76,77,136,137,92,101,112,113,102,102,102,112,113,102,2147483749,91,91,91,63,63,81,81,81,81,63,63, +154,154,74,75,76,77,63,63,63,70,70,70,70,70,63,63,63,63,63,63,63,63,76,1073741916,1073741915,3221225564,74,75,76,77,74,75,76,77,81,1073741941,1073741952,3221225599,3221225589,81,103,104,1073741916,1073741925,102,102,102,102,102,102,102,102,102,102,102,63,63,63,134,134,63,63,63,63, +154,154,154,154,63,63,63,63,70,70,70,70,70,63,63,63,63,63,63,63,74,75,76,77,81,2147483785,2147483784,1073741941,3221225599,1073741952,3221225599,3221225589,103,104,1073741941,1073741942,70,70,3221225590,1073741952,3221225625,81,81,1073741916,1073741925,102,102,102,102,102,102,102,102,102,63,63,63,75,76,77,63,63,63,63, +63,63,63,63,154,154,63,63,63,70,70,63,63,63,63,63,63,63,63,63,63,103,104,2147483785,2147483784,81,1073741941,1073741942,70,70,70,3221225590,1073741952,3221225599,1073741942,70,70,70,70,2147483766,2147483801,81,81,63,63,102,98,93,94,99,102,102,102,102,74,75,76,155,134,63,63,63,63,63, +63,63,63,63,63,63,63,63,70,70,2147483717,2147483767,70,63,63,63,64,65,66,73,3221225599,3221225599,3221225589,103,104,81,117,118,70,106,70,70,70,108,109,70,70,63,63,2147483765,81,63,63,63,63,63,63,63,63,63,63,102,98,93,94,99,134,63,63,63,63,63,63,63, +63,63,63,63,63,63,64,65,66,73,70,63,63,63,64,65,66,73,64,65,66,73,3221225590,3221225589,136,137,81,63,63,130,124,125,123,120,121,122,63,63,63,63,63,63,63,63,63,63,74,75,76,63,63,1073741915,3221225563,3221225564,76,75,76,75,63,63,63,63,63,63, +63,63,63,63,63,63,63,70,64,65,66,73,70,63,63,70,70,130,70,70,70,70,2147483766,2147483801,81,81,81,75,63,63,63,70,70,124,125,70,63,63,63,63,63,63,63,63,63,63,63,63,63,75,76,85,86,75,76,77,134,134,63,63,63,63,63,63, +63,63,63,63,63,70,70,70,70,70,70,63,63,63,70,63,63,70,70,70,2147483766,127,2147483765,103,104,81,81,63,63,63,63,63,63,70,70,63,63,63,63,63,63,63,63,63,63,63,63,63,63,134,1073741952,1073741952,3221225589,103,104,1073741941,1073741952,1073741951,63,63,63,63,63,63, +74,75,76,77,63,63,63,70,70,70,70,70,70,63,63,63,63,63,63,127,2147483765,81,136,137,103,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,73,64,65,66,73,3221225590,1073741952,1073741952,1073741942,64,65,66,73,63,63,63,63, +81,81,81,81,63,63,64,65,66,73,64,65,66,73,63,63,63,63,81,63,63,81,103,63,63,81,63,63,63,63,63,63,63,63,63,63,63,63,74,75,76,77,134,75,76,70,64,65,66,130,130,130,63,70,70,2147483766,63,63,63,63,63,63,63,63, +63,63,63,63,64,65,66,73,70,70,124,125,70,63,63,63,63,75,76,77,81,63,63,81,74,75,76,77,63,63,63,63,64,65,66,73,74,75,76,77,74,75,76,77,127,127,127,118,124,125,130,63,63,63,63,63,63,63,63,63,63,63,63,63, +63,63,63,63,63,70,70,70,70,70,70,70,70,70,63,63,63,85,86,81,74,75,76,77,103,104,74,75,76,77,64,65,66,73,2147483766,75,76,134,134,134,134,134,74,75,76,77,135,117,118,124,125,63,63,63,63,63,63,63,63,63,63,63,63,63, +63,63,63,63,81,70,156,157,70,124,125,70,70,63,63,63,1073741951,1073741941,1073741951,1073741951,1073741951,1073741951,1073741951,1073741951,1073741941,1073741951,1073741951,3221225589,64,65,66,73,130,2147483766,2147483765,134,74,75,76,77,74,75,76,77,134,103,104,134,117,118,70,63,63,63,63,63,63,63,63,70,70,70,70,70, +63,63,63,63,63,158,159,160,161,70,64,65,66,73,63,63,63,70,162,163,164,165,166,167,168,169,64,65,66,73,70,70,2147483766,2147483765,74,75,76,77,74,75,76,77,134,134,136,137,134,1073741941,1073741951,1073741951,127,134,134,63,63,63,70,70,70,70,70,70,70,70, +63,63,63,63,81,81,117,128,118,2147483718,70,70,64,65,63,73,70,70,130,70,170,171,172,173,70,70,70,70,63,125,2147483766,127,2147483765,136,137,1073741941,3221225589,134,136,137,134,134,103,137,134,134,1073741941,1073741942,64,65,66,73,134,63,63,63,64,65,66,73,64,65,66,73, +63,63,63,63,63,63,81,81,117,2147483775,128,118,70,70,63,65,66,73,70,70,70,70,70,70,70,70,70,70,63,2147483766,2147483765,103,104,103,104,1073741942,3221225590,134,74,75,76,77,134,63,63,134,70,70,156,157,70,63,63,63,64,65,66,73,64,65,66,73,70,70, +74,75,76,77,63,63,63,81,81,174,135,117,2147483775,118,63,70,70,70,70,70,70,70,70,70,70,70,63,63,63,2147483765,103,104,74,75,76,70,70,75,76,77,74,75,76,63,63,63,63,70,159,160,70,63,63,63,70,70,130,124,125,70,70,70,70,70, +81,81,81,81,63,63,81,81,81,81,81,81,81,63,63,70,70,70,70,2147483766,127,127,63,63,63,63,63,63,63,134,134,75,76,77,74,75,76,77,134,134,134,134,134,63,63,63,63,70,70,63,63,63,63,70,124,125,70,70,70,70,70,70,64,65, +63,63,63,63,63,63,63,63,63,81,81,63,63,63,63,63,63,128,127,2147483765,134,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,70,70,70,70,124,125,70,70,70,70,70,70, +63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,103,104,103,104,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,70,70,70,124,125,70,70,70,70,70,70,70, +63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,134,134,63,63,63,63,63,63,63,63,63,74,75,76,77,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,70,70,70,70,162,163,164,165,166,167,168,169, +63,63,63,63,63,63,74,75,76,77,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,81,81,81,81,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,70,70,124,125,70,70,170,171,172,173,119,69, +63,63,63,63,63,63,81,81,81,81,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,70,70,70,70,70,70,70,70,124,125,70,70,70 + + + + + + + + + +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,5,6,7,7,8,9,3,4,1,2,3,4,1,2,3,4, +3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,7,7,15,13,1,2,3,4,1,2,3,4,1,2, +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,5,6,7,7,8,9,3,4,1,2,3,4,1,2,3,4, +3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,16,17,18,1,2,3,4,5,11,12,13,5,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,14,7,7,19,13,1,2,3,4,10,11,12,13,1,2, +10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,5,11,20,21,22,23,3,24,25,26,12,13,5,11,12,27,28,11,12,27,1,2,3,14,8,9,3,4,5,6,7,7,25,26,12,13,1,2,3,14,8,9,3,4, +3,14,8,9,3,4,10,11,12,13,10,11,12,13,1,2,3,4,5,11,20,21,7,7,19,13,5,29,7,7,25,26,20,21,22,9,3,14,25,26,12,13,1,16,17,18,5,11,20,21,7,7,7,7,25,26,12,13,1,16,17,18,1,2, +1,16,17,18,1,2,3,24,25,26,20,21,22,9,3,4,1,2,3,24,7,7,7,7,25,26,20,21,7,7,7,7,7,7,19,27,28,6,7,7,22,23,3,4,1,2,3,14,7,7,7,7,7,7,7,7,8,9,3,4,1,2,3,4, +3,4,1,2,3,4,10,29,7,7,30,31,32,4,1,2,3,4,5,29,7,7,7,7,7,7,7,7,7,7,7,7,7,7,25,26,20,33,7,34,19,13,1,2,3,4,5,6,7,2147483682,7,7,7,7,7,7,35,13,1,2,3,4,1,2, +1,2,3,4,10,11,20,21,7,7,19,13,1,2,3,4,1,2,3,14,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,36,25,26,12,13,1,2,3,14,7,7,7,7,7,7,7,7,25,26,12,13,1,2,3,4, +3,4,1,2,3,24,7,7,7,7,22,9,3,4,1,2,3,4,28,29,7,7,30,31,37,38,30,31,37,38,30,31,37,38,7,7,7,7,7,7,7,7,22,23,3,4,1,39,37,38,7,7,7,7,7,7,40,7,8,9,3,4,1,2, +1,2,3,4,1,39,37,38,7,7,19,13,1,2,3,4,1,2,3,14,7,7,19,13,1,39,32,4,1,39,32,4,1,39,37,38,7,7,7,7,7,7,19,13,1,2,3,13,1,39,37,38,7,7,7,7,30,31,17,4,1,2,3,4, +3,4,1,2,3,4,1,39,37,38,22,9,3,4,1,2,3,4,28,29,7,7,8,9,3,4,1,2,3,4,1,2,3,4,1,39,37,38,7,7,7,7,22,9,3,4,1,2,3,4,5,6,7,7,7,41,32,4,1,2,3,4,1,2, +1,2,3,4,1,2,3,4,10,42,35,13,10,11,12,13,28,11,20,21,7,7,19,13,1,2,3,4,1,2,3,4,1,2,3,4,10,6,7,7,7,7,19,13,1,2,3,4,5,11,20,21,7,7,43,44,1,2,3,4,1,2,3,4, +3,4,1,11,12,13,1,2,3,45,25,26,20,21,22,9,3,14,7,7,7,7,22,9,3,4,1,2,3,4,1,2,3,4,1,2,3,14,7,7,7,7,25,26,12,13,1,2,3,14,7,7,7,7,8,9,3,4,1,2,3,4,1,2, +1,2,3,14,8,9,3,4,1,16,37,38,7,7,19,13,28,29,7,7,7,7,19,13,28,11,12,27,1,2,3,4,10,11,12,13,1,39,37,38,7,7,7,7,25,9,3,4,1,39,37,38,7,7,19,13,1,2,3,4,1,2,3,4, +3,4,1,16,17,18,1,2,3,4,10,29,7,7,25,26,20,21,7,7,7,7,25,26,20,21,46,26,12,27,1,2,3,14,8,9,3,4,10,6,7,7,30,31,3,4,1,2,3,4,1,6,7,7,25,26,12,13,1,2,3,4,1,2, +1,2,3,4,1,2,3,4,28,11,20,21,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,22,23,3,4,1,16,17,18,10,11,20,14,7,7,19,13,10,11,12,13,1,2,3,14,7,7,7,7,22,23,3,4,1,2,3,4, +3,4,10,11,12,13,10,11,20,21,7,7,7,7,7,7,7,7,30,31,37,38,7,7,7,7,30,31,3,4,1,2,3,4,1,2,3,14,7,7,7,7,22,9,3,14,8,9,3,4,5,6,7,7,30,31,32,4,10,11,12,13,1,2, +1,2,3,14,25,26,20,21,7,7,7,7,30,31,37,38,30,31,17,4,28,29,7,7,7,7,19,13,28,11,12,13,1,2,3,4,1,39,37,38,7,7,19,13,1,16,17,18,1,2,3,14,7,7,19,13,1,2,3,14,8,9,3,4, +12,13,10,29,7,7,7,7,7,7,7,7,19,13,1,16,17,4,1,2,3,14,30,31,37,38,8,9,3,14,8,9,3,4,1,2,3,4,10,29,7,7,25,26,12,44,1,2,3,4,10,6,7,7,25,26,12,13,1,16,17,18,1,2, +25,26,20,21,7,7,7,7,7,7,7,7,8,9,3,4,1,2,3,4,1,16,17,4,1,16,17,4,1,16,17,18,1,2,3,4,10,11,20,21,7,7,7,7,22,23,3,4,1,2,3,14,7,7,7,7,25,26,12,13,1,2,3,4, +7,7,7,7,7,7,7,7,7,7,30,31,17,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,40,7,7,7,7,7,19,44,1,2,3,4,1,39,37,38,7,7,7,7,22,23,3,4,1,2, +7,7,7,7,7,7,7,7,7,7,19,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,28,29,7,7,7,7,7,40,8,9,3,4,1,2,3,4,10,6,7,7,7,7,19,13,1,2,3,4, +37,38,30,31,37,38,30,31,37,38,25,26,12,27,1,2,3,4,10,11,12,13,1,2,3,4,1,2,3,4,28,11,12,27,28,11,20,21,7,7,7,7,7,7,19,44,1,2,3,4,1,2,3,14,7,7,7,7,8,9,3,4,1,2, +1,16,17,4,1,16,17,4,10,29,7,7,25,26,12,27,1,2,3,14,8,9,3,4,1,2,3,4,1,2,3,14,25,26,20,21,7,7,7,7,30,31,37,38,8,9,3,4,1,2,3,4,1,16,37,38,7,7,19,13,1,2,3,4, +3,4,1,2,3,4,1,2,3,14,30,31,37,38,22,23,3,4,1,16,17,18,1,2,3,4,1,2,3,4,28,29,40,7,7,7,7,7,7,7,19,13,1,16,32,4,1,2,3,4,1,2,3,4,5,6,7,7,25,26,12,13,1,2, +1,2,3,4,1,2,3,4,1,16,17,4,1,16,17,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,7,7,7,7,7,7,7,40,25,26,12,13,1,2,3,4,1,2,3,4,10,11,20,21,7,7,7,7,22,9,3,4, +3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,27,28,11,12,27,28,11,12,27,28,29,7,7,7,7,7,7,7,7,7,7,8,9,3,4,10,11,12,13,5,11,47,33,7,7,7,7,30,31,32,4,1,2, +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,20,21,25,26,20,21,25,9,3,14,25,26,20,21,7,7,7,7,7,7,7,34,30,31,3,4,1,2,3,14,8,9,3,14,7,7,7,7,30,31,32,4,1,2,3,4, +3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,14,7,7,40,7,7,7,43,27,28,29,7,7,7,7,7,7,7,41,37,38,7,36,19,44,1,2,3,4,1,16,17,18,1,16,37,38,7,7,15,13,1,2,3,4,1,2, +1,2,3,14,8,9,3,4,1,2,3,4,10,11,12,27,10,29,7,7,7,7,7,7,25,26,20,21,7,7,7,7,7,7,43,44,1,16,37,38,8,9,3,4,1,2,3,4,1,2,3,4,5,6,7,7,25,26,12,4,1,2,3,4, +3,4,1,16,17,18,1,2,3,4,1,2,3,14,25,26,20,21,7,7,7,7,7,7,7,7,7,7,7,7,7,41,37,38,8,9,3,4,1,16,17,18,1,2,3,4,1,2,3,4,1,11,47,21,7,7,7,7,22,2,3,4,1,2, +1,2,3,4,1,2,3,4,10,11,12,13,10,29,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,43,44,1,16,32,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,7,7,7,7,30,31,32,4,1,2,3,4, +3,4,1,2,3,4,10,11,20,21,25,26,20,21,7,7,7,7,7,7,7,7,7,41,37,38,30,41,37,38,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,16,37,38,7,7,19,13,1,2,3,4,1,2, +1,2,3,4,10,11,20,21,7,7,7,7,30,41,37,38,7,7,7,7,7,7,43,44,1,16,32,4,1,16,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,5,6,7,7,25,26,12,13,1,2,3,4, +3,4,1,2,3,14,7,7,7,7,30,31,32,4,1,16,37,38,7,7,7,7,46,48,12,13,1,2,3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,5,11,47,33,7,7,7,7,22,23,3,4,1,2, +1,2,3,4,1,16,37,38,7,7,19,13,1,2,3,4,1,16,37,38,7,7,7,7,22,9,3,4,1,2,3,14,8,9,3,4,10,11,12,13,1,11,12,13,10,11,12,13,10,11,47,33,7,7,7,7,30,31,32,4,1,2,3,4, +3,4,1,2,3,4,10,29,7,7,8,9,3,13,1,2,3,4,10,29,2147483682,7,7,7,19,13,1,2,3,4,1,16,17,18,1,2,3,14,8,9,3,14,46,48,20,21,8,9,3,14,7,7,7,7,7,34,19,13,1,2,3,4,1,2, +1,2,3,4,1,2,3,14,30,31,32,13,1,2,3,4,1,2,3,14,2147483684,7,7,7,25,26,12,13,1,2,3,4,1,2,3,4,1,16,17,18,10,29,7,7,7,7,19,13,10,29,7,7,7,7,7,36,25,23,3,4,1,2,3,4, +3,4,1,2,3,4,1,16,32,4,1,2,3,13,1,2,3,4,1,39,37,38,7,7,7,7,22,9,3,4,1,2,3,4,10,11,12,13,10,11,20,21,7,7,7,7,25,48,20,21,7,7,7,7,30,31,32,4,10,11,12,13,1,2, +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,16,37,38,7,7,19,13,10,11,12,13,10,11,20,21,46,48,20,21,7,7,7,7,7,7,7,7,7,7,7,7,7,7,19,13,1,2,3,14,8,9,3,4, +3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,29,7,7,46,48,20,21,46,48,20,21,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,9,3,4,1,16,17,18,1,2, +1,2,3,14,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,20,21,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,30,31,32,4,10,2,3,13,1,2,3,4, +3,4,1,16,17,18,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,30,31,37,38,30,31,37,38,7,7,19,13,10,2,3,4,1,2,3,4,1,2, +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,13,10,29,7,7,7,7,7,7,7,40,7,7,7,7,7,7,30,31,37,38,30,31,32,4,1,16,32,4,1,16,37,38,22,9,3,4,1,2,3,4,1,2,3,4, +3,4,1,2,3,4,10,11,12,13,1,2,3,4,10,11,20,33,25,26,20,33,7,7,7,7,30,31,37,38,7,7,7,34,30,31,32,4,1,39,32,4,1,2,3,4,1,2,3,4,10,29,19,13,10,11,12,13,1,2,3,4,1,2, +1,2,3,4,1,2,3,14,25,26,12,13,10,2,3,14,7,7,7,7,7,7,7,7,7,7,35,13,1,39,37,38,7,36,19,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,49,50,48,20,21,8,9,3,4,1,2,3,4, +3,4,1,2,3,4,1,16,37,38,8,9,3,4,1,16,37,38,7,7,7,7,7,7,7,7,22,23,3,4,1,39,37,38,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,29,7,7,7,7,19,44,1,2,3,4,1,2, +10,11,12,13,1,2,3,4,10,29,35,13,51,2,3,4,1,16,37,38,7,7,7,7,30,31,32,4,1,2,3,4,1,39,32,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,21,7,7,7,7,8,9,3,4,1,2,3,4, +3,14,8,9,3,4,10,11,20,52,50,26,12,44,1,2,3,4,1,16,37,38,30,31,32,13,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,14,46,48,12,13,1,16,37,38,30,41,17,4,1,2,3,4,1,2, +1,16,17,18,10,11,20,21,7,7,7,7,22,9,3,4,1,2,3,4,1,16,32,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,14,22,9,3,4,10,29,7,7,22,9,3,4,1,16,17,4,1,2,3,4,1,2,3,4, +3,4,1,2,3,24,30,41,37,38,30,41,17,4,1,2,3,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,21,22,9,3,4,1,16,17,4,10,11,20,21,7,7,19,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2, +1,2,3,4,1,16,53,4,1,16,53,4,1,2,3,4,1,2,3,13,1,2,3,4,1,2,3,4,1,2,3,4,1,16,17,4,10,11,12,13,10,11,20,21,7,7,7,7,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4, +3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,20,21,22,9,3,14,30,31,37,38,7,7,19,44,1,2,3,4,1,2,3,4,1,2,3,4,1,2, +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,30,31,17,18,1,16,17,4,1,16,37,38,46,48,12,13,1,2,3,4,10,11,12,13,10,11,12,13, +3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,13,10,29,19,13,1,2,3,4,1,2,3,4,10,29,54,55,22,9,3,4,10,11,20,21,25,48,20,21,22,9, +10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,14,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,8,9,3,4,10,11,12,13,1,2,3,14,30,41,17,44,1,2,3,14,7,7,7,41,56,38,35,13, +3,14,8,9,3,4,1,2,3,4,1,2,3,4,10,39,17,18,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,16,17,4,1,2,3,14,22,9,3,4,1,16,3,4,1,2,3,4,5,29,7,7,43,44,5,6,25,26, +1,16,17,18,1,2,3,4,1,2,3,4,1,2,3,4,5,2,3,4,1,2,3,4,1,2,3,4,1,2,17,4,1,2,3,4,1,2,3,4,1,16,17,4,10,2,3,13,1,2,3,4,1,2,3,14,30,31,53,57,58,59,56,38, +3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,29,35,44,12,13,10,11,10,6, +1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,49,50,48,60,26,20,61,20,52, +3,4,1,2,3,4,10,11,12,13,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,14,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,16,37,38,7,7,7,7,30,41, +1,2,3,4,1,2,3,14,8,9,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,16,17,18,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,27,1,16,37,38,7,41,17,18, +12,27,28,11,12,27,28,16,17,18,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,28,11,12,27,10,11,12,27,10,29,43,44,28,11 + + + diff --git a/res/maps/map2_tiles.png b/res/maps/map2_tiles.png new file mode 100644 index 0000000..1e6c09f Binary files /dev/null and b/res/maps/map2_tiles.png differ diff --git a/res/scripts/map1_off_right.lua b/res/scripts/map1_off_right.lua new file mode 100644 index 0000000..026c32e --- /dev/null +++ b/res/scripts/map1_off_right.lua @@ -0,0 +1,9 @@ +function map1_off_right() + -- Because this script gets triggered within the CharacterSystem's tick method, + -- if we immediately cleared out the entities from the old map, we might end up + -- returning there and processing stale data. This yield here ensures that we + -- are no longer in the CharacterSystem, because processing gets picked back up + -- in the ScriptSystem. + coroutine.yield() + loadMap("../res/maps/map2.tmx", "fromLeft") +end diff --git a/src/animation_system.cpp b/src/animation_system.cpp index cf34066..997b7f7 100644 --- a/src/animation_system.cpp +++ b/src/animation_system.cpp @@ -6,7 +6,7 @@ #include "vector.h" #include "util.h" -void AnimationSystem::initSprite(int spriteId, std::string_view filename, Renderer& renderer) { +void AnimationSystem::initSprite(int spriteId, std::string_view filename) { std::ifstream datafile(filename.data()); if (!datafile.is_open()) { throw std::invalid_argument(std::string("Could not find sprite datafile: ") + std::string(filename)); @@ -18,9 +18,7 @@ void AnimationSystem::initSprite(int spriteId, std::string_view filename, Render char ch; std::string line; - std::string imagename; - datafile >> imagename; - sprite.textureId = renderer.loadImageFromFile(imagename); + datafile >> sprite.spritesheet; std::string framefilename; datafile >> framefilename; diff --git a/src/animation_system.h b/src/animation_system.h index 2e13784..a116673 100644 --- a/src/animation_system.h +++ b/src/animation_system.h @@ -7,7 +7,6 @@ #include "timer.h" class Game; -class Renderer; class AnimationSystem : public System { public: @@ -18,7 +17,7 @@ public: void tick(double dt) override; - void initSprite(int spriteId, std::string_view filename, Renderer& renderer); + void initSprite(int spriteId, std::string_view filename); void setSpriteDirection(int spriteId, Direction dir); diff --git a/src/camera_system.cpp b/src/camera_system.cpp index 4709d01..991d096 100644 --- a/src/camera_system.cpp +++ b/src/camera_system.cpp @@ -4,7 +4,7 @@ #include "map.h" void CameraSystem::tick(double dt) { - if (!locked_) { + if (!locked_ && followingSprite_ != -1) { const Sprite& follow = game_.getSprite(followingSprite_); const Map& map = game_.getMap(); vec2i mapBounds = map.getMapSize() * map.getTileSize(); @@ -25,3 +25,7 @@ void CameraSystem::tick(double dt) { } } } + +void CameraSystem::clearSpriteCache() { + followingSprite_ = -1; +} diff --git a/src/camera_system.h b/src/camera_system.h index 3eb8374..77d813f 100644 --- a/src/camera_system.h +++ b/src/camera_system.h @@ -26,12 +26,14 @@ public: void tick(double dt) override; + void clearSpriteCache() override; + private: Game& game_; vec2i pos_; vec2i fov_ { CANVAS_WIDTH, CANVAS_HEIGHT }; - int followingSprite_; + int followingSprite_ = -1; bool locked_ = true; }; diff --git a/src/game.cpp b/src/game.cpp index 447b62a..861e8ee 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,4 +1,8 @@ #include "game.h" +#include "transform_system.h" +#include "animation_system.h" +#include "character_system.h" +#include "camera_system.h" int Game::emplaceSprite(std::string alias) { int id = sprites_.size(); @@ -7,3 +11,59 @@ int Game::emplaceSprite(std::string alias) { spritesByAlias_[alias] = id; return id; } + +void Game::clearSprites() { + sprites_.clear(); + spriteIds_.clear(); + spritesByAlias_.clear(); + + for (std::unique_ptr& system : systems_) { + system->clearSpriteCache(); + } +} + +void Game::loadMap(std::string filename, std::string warpPoint) { + clearSprites(); + + map_ = std::make_unique(filename); + + int lucasSprite = emplaceSprite("lucas"); + getSystem().initSprite(lucasSprite, map_->getWarpPoint(warpPoint)); + getSystem().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true); + getSystem().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt"); + getSprite(lucasSprite).controllable = true; + getSystem().initSprite(lucasSprite); + + int kumaSprite = emplaceSprite("kuma"); + getSystem().initSprite(kumaSprite, {32, 32}); + getSystem().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt"); + getSystem().addSpriteToParty(lucasSprite, kumaSprite); + + int dusterSprite = emplaceSprite("duster"); + getSystem().initSprite(dusterSprite, {32, 32}); + getSystem().initSprite(dusterSprite, "../res/sprites/duster_anim.txt"); + getSystem().addSpriteToParty(lucasSprite, dusterSprite); + + int boneySprite = emplaceSprite("boney"); + getSystem().initSprite(boneySprite, {32, 32}); + getSystem().initSprite(boneySprite, "../res/sprites/boney_anim.txt"); + getSystem().addSpriteToParty(lucasSprite, boneySprite); + + for (const Prototype& p : map_->getPrototypes()) { + int spriteId = emplaceSprite(p.name); + getSystem().initSprite(spriteId, p.pos); + getSystem().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true); + getSystem().initSprite(spriteId, p.animationFilename); + getSprite(spriteId).interactionScript = p.interactionScript; + } + + for (const Trigger& t : map_->getTriggers()) { + int spriteId = emplaceSprite(t.name); + getSystem().initSprite(spriteId, t.pos); + getSystem().setUpCollision(spriteId, {0, 0}, t.size, false); + getSprite(spriteId).walkthroughScript = t.script; + } + + getSystem().setFollowingSprite(lucasSprite); + getSystem().unlockCamera(); +} diff --git a/src/game.h b/src/game.h index 87e23d3..8ea7576 100644 --- a/src/game.h +++ b/src/game.h @@ -73,7 +73,7 @@ public: }); } - void setMap(std::unique_ptr map) { map_ = std::move(map); } + void loadMap(std::string filename, std::string warpPoint); const Map& getMap() const { return *map_; } @@ -81,6 +81,8 @@ public: private: + void clearSprites(); + Mixer mixer_; bool shouldQuit_ = false; diff --git a/src/main.cpp b/src/main.cpp index a350c8d..5f28408 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,48 +22,7 @@ void loop(Renderer& renderer) { game.emplaceSystem(); game.emplaceSystem(); - auto map = std::make_unique("../res/maps/map1.tmx", renderer); - game.setMap(std::move(map)); - - int lucasSprite = game.emplaceSprite("lucas"); - game.getSystem().initSprite(lucasSprite, game.getMap().getWarpPoint("spawn")); - game.getSystem().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true); - game.getSystem().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt", renderer); - game.getSprite(lucasSprite).controllable = true; - game.getSystem().initSprite(lucasSprite); - - int kumaSprite = game.emplaceSprite("kuma"); - game.getSystem().initSprite(kumaSprite, {32, 32}); - game.getSystem().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt", renderer); - game.getSystem().addSpriteToParty(lucasSprite, kumaSprite); - - int dusterSprite = game.emplaceSprite("duster"); - game.getSystem().initSprite(dusterSprite, {32, 32}); - game.getSystem().initSprite(dusterSprite, "../res/sprites/duster_anim.txt", renderer); - game.getSystem().addSpriteToParty(lucasSprite, dusterSprite); - - int boneySprite = game.emplaceSprite("boney"); - game.getSystem().initSprite(boneySprite, {32, 32}); - game.getSystem().initSprite(boneySprite, "../res/sprites/boney_anim.txt", renderer); - game.getSystem().addSpriteToParty(lucasSprite, boneySprite); - - for (const Prototype& p : game.getMap().getPrototypes()) { - int spriteId = game.emplaceSprite(p.name); - game.getSystem().initSprite(spriteId, p.pos); - game.getSystem().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true); - game.getSystem().initSprite(spriteId, p.animationFilename, renderer); - game.getSprite(spriteId).interactionScript = p.interactionScript; - } - - for (const Trigger& t : game.getMap().getTriggers()) { - int spriteId = game.emplaceSprite(t.name); - game.getSystem().initSprite(spriteId, t.pos); - game.getSystem().setUpCollision(spriteId, {0, 0}, t.size, false); - game.getSprite(spriteId).walkthroughScript = t.script; - } - - game.getSystem().setFollowingSprite(lucasSprite); - game.getSystem().unlockCamera(); + game.loadMap("../res/maps/map1.tmx", "spawn"); renderer.render(game); diff --git a/src/map.cpp b/src/map.cpp index b6f6755..99711c6 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -4,9 +4,8 @@ #include #include #include -#include "renderer.h" -Map::Map(std::string_view filename, Renderer& renderer) { +Map::Map(std::string_view filename) : filename_(filename) { tmx::Map mapfile; if (!mapfile.load(filename.data())) { throw std::invalid_argument("Could not find map file: " + std::string(filename)); @@ -24,7 +23,7 @@ Map::Map(std::string_view filename, Renderer& renderer) { // There should only be one tileset. const tmx::Tileset& tileset = mapfile.getTilesets()[0]; firstGID = tileset.getFirstGID(); - tilesetTextureId_ = renderer.loadImageFromFile(tileset.getImagePath()); + tilesetFilename_ = tileset.getImagePath(); tilesetColumns_ = tileset.getColumnCount(); for (const auto& layer : mapfile.getLayers()) { diff --git a/src/map.h b/src/map.h index 4c5d6d4..adf9b80 100644 --- a/src/map.h +++ b/src/map.h @@ -5,12 +5,9 @@ #include #include #include -#include "renderer.h" #include "vector.h" #include "step_type.h" -class Renderer; - struct Tile { unsigned int id = 0; bool flipHorizontal = false; @@ -38,7 +35,9 @@ struct Trigger { class Map { public: - Map(std::string_view filename, Renderer& renderer); + explicit Map(std::string_view filename); + + const std::string& getName() const { return filename_; } const vec2i& getMapSize() const { return mapSize_; } @@ -46,7 +45,7 @@ public: const std::vector>& getLayers() const { return layers_; } - int getTilesetTextureId() const { return tilesetTextureId_; } + const std::string& getTilesetFilename() const { return tilesetFilename_; } int getTilesetColumns() const { return tilesetColumns_; } @@ -62,10 +61,11 @@ public: private: + std::string filename_; vec2i mapSize_; vec2i tileSize_; std::vector> layers_; - int tilesetTextureId_; + std::string tilesetFilename_; int tilesetColumns_; std::vector prototypes_; std::map warpPoints_; diff --git a/src/renderer.cpp b/src/renderer.cpp index 87bbbcd..e9db413 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -35,6 +35,16 @@ Renderer::Renderer() { } texture_ptr Renderer::renderMapLayer(const Map& map, int layer) { + if (cachedTilesetName_ != map.getTilesetFilename()) { + surface_ptr pfs(IMG_Load(map.getTilesetFilename().c_str())); + if (!pfs) { + throw img_error(); + } + + tilesetTex_ = texture_ptr(SDL_CreateTextureFromSurface(ren_.get(), pfs.get())); + cachedTilesetName_ = map.getTilesetFilename(); + } + vec2i mapBounds = map.getMapSize() * map.getTileSize(); texture_ptr canvas( @@ -77,7 +87,7 @@ texture_ptr Renderer::renderMapLayer(const Map& map, int layer) { } else if (tile.flipVertical) { flip = SDL_FLIP_VERTICAL; } - SDL_RenderCopyEx(ren_.get(), textures_[map.getTilesetTextureId()].get(), &srcRect, &destRect, 0, nullptr, flip); + SDL_RenderCopyEx(ren_.get(), tilesetTex_.get(), &srcRect, &destRect, 0, nullptr, flip); } } @@ -85,10 +95,9 @@ texture_ptr Renderer::renderMapLayer(const Map& map, int layer) { } void Renderer::render(Game& game) { - if (!renLay1_) { + if (cachedMapName_ != game.getMap().getName()) { + cachedMapName_ = game.getMap().getName(); renLay1_ = renderMapLayer(game.getMap(), 0); - } - if (!renLay0_) { renLay0_ = renderMapLayer(game.getMap(), 1); } @@ -118,7 +127,7 @@ void Renderer::render(Game& game) { const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).at(sprite.animationFrame)); const SDL_Rect& src = frame.srcRect; SDL_Rect dest { sprite.loc.x() - frame.center.x(), sprite.loc.y() - frame.center.y(), frame.size.w(), frame.size.h() }; - SDL_RenderCopy(ren_.get(), textures_.at(sprite.textureId).get(), &src, &dest); + SDL_RenderCopy(ren_.get(), textures_.at(loadImageFromFile(sprite.spritesheet)).get(), &src, &dest); } } diff --git a/src/renderer.h b/src/renderer.h index 2d7f93b..6d512c2 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -136,6 +136,9 @@ private: // Map rendering texture_ptr renderMapLayer(const Map& map, int layer); + std::string cachedMapName_; + std::string cachedTilesetName_; + texture_ptr tilesetTex_; texture_ptr renLay0_; texture_ptr renLay1_; diff --git a/src/script_system.cpp b/src/script_system.cpp index e2b117a..6e38905 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -50,6 +50,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { return game_.getSpriteByAlias(alias); }); + engine_.set_function( + "loadMap", + [&] (std::string filename, std::string warpPoint) { + game_.loadMap(filename, warpPoint); + }); + engine_.script_file("../res/scripts/common.lua"); } diff --git a/src/sprite.h b/src/sprite.h index 4a65763..283fb65 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -42,7 +42,7 @@ public: // Animation bool isAnimated = false; - int textureId; + std::string spritesheet; Direction dir = Direction::down; std::string animationName = "still"; int animationId = 0; diff --git a/src/system.h b/src/system.h index 218dc60..93b903e 100644 --- a/src/system.h +++ b/src/system.h @@ -15,6 +15,8 @@ class System { public: virtual void tick(double dt) {} + + virtual void clearSpriteCache() {} }; #endif /* end of include guard: SYSTEM_H_6B40E1B9 */ diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 2ec133e..8a09c20 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp @@ -209,3 +209,11 @@ void TransformSystem::removeCollidable(int spriteId) { upCollidables_.erase({ colDR.y(), spriteId }); downCollidables_.erase({ colUL.y(), spriteId }); } + +void TransformSystem::clearSpriteCache() { + spritesByY_.clear(); + leftCollidables_.clear(); + rightCollidables_.clear(); + upCollidables_.clear(); + downCollidables_.clear(); +} diff --git a/src/transform_system.h b/src/transform_system.h index 10e33db..46b6877 100644 --- a/src/transform_system.h +++ b/src/transform_system.h @@ -43,6 +43,8 @@ public: CollisionResult checkCollision(int spriteId, vec2i newLoc, Direction dir); + void clearSpriteCache() override; + private: Game& game_; -- cgit 1.4.1