From 93b3e4004387047c25b2f5a190aced01c9091934 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 2 Feb 2021 19:34:48 -0500 Subject: Added collision with map tiles --- res/map1.tmx | 277 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/direction.h | 10 ++ src/map.cpp | 38 ++++++-- src/map.h | 3 + src/party.cpp | 121 +++++++++++++++++++------ src/party.h | 2 + src/vector.h | 8 +- 7 files changed, 411 insertions(+), 48 deletions(-) diff --git a/res/map1.tmx b/res/map1.tmx index ceae330..f9e5f56 100644 --- a/res/map1.tmx +++ b/res/map1.tmx @@ -1,11 +1,268 @@ - - - - - - 55,55,55,55,55,55,56,57,58,58,2147483704,2147483703,2147483707,2147483708,2147483709,2147483703,55,55,55,55,55,55,55,62,63,2147483711,2147483710,55,55,55,55,55,55,55,55,55,55,55,55,56,58,58,2147483712,55,55,55,55,55,61,60,59,55,55,65,66,58,58,58,2147483714,2147483715,2147483716,2147483717,2147483718,71,2147483712,55,61,60,59,55,55,56,57,2147483705,2147483704,55,55,55,55,55,55,61,60,59,55,55,65,66,58,58,58,72,2147483719,55,55,55,70,69,68,67,73,58,74,58,58,58,58,2147483706,2147483723,2147483724,2147483725,2147483706,2147483705,2147483719,70,69,68,67,73,66,58,58,58,2147483713,55,55,65,73,2147483713,70,69,68,67,73,58,58,58,58,58,58,58,2147483712,65,73,77,76,75,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,77,76,75,58,58,58,58,58,58,58,2147483719,2147483724,58,58,58,77,76,75,58,58,58,58,58,58,58,58,58,58,58,58,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,80,81,82,83,84,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,85,86,2147483735,2147483735,2147483735,2147483735,2147483734,2147483733,79,79,79,79,79,79,79,79,79,79,79,88,89,90,91,92,79,79,2147483732,2147483731,2147483730,2147483729,2147483728,79,79,79,79,79,79,79,85,86,2147483735,2147483735,2147483735,2147483735,2147483735,2147483735,2147483735,2147483735,93,94,2147483743,2147483743,2147483743,2147483743,2147483742,2147483741,2147483735,87,2147483734,2147483733,79,79,79,2147483735,2147483735,2147483744,2147483733,97,98,99,100,101,101,79,2147483740,2147483739,2147483738,2147483737,2147483736,79,79,79,85,86,87,87,93,94,2147483743,2147483743,2147483743,102,103,104,105,106,106,107,106,108,2147483757,2147483756,2147483755,2147483758,2147483743,95,2147483742,2147483741,2147483735,2147483735,2147483735,2147483743,2147483743,2147483759,2147483741,2147483760,2147483761,2147483727,2147483727,79,79,79,2147483749,2147483748,2147483747,2147483746,2147483745,79,85,112,93,94,95,95,95,106,106,106,106,114,114,114,114,106,106,108,109,115,116,2147483763,2147483757,109,109,2147483756,2147483755,2147483758,2147483743,2147483743,2147483743,2147483765,2147483765,118,2147483758,2147483767,2147483768,2147483735,2147483734,2147483733,2147483769,2147483770,123,122,121,85,86,2147483735,93,94,95,107,106,106,106,106,106,106,106,106,2147483772,2147483772,106,108,109,115,116,116,116,116,116,116,116,2147483763,2147483756,106,106,106,106,2147483765,118,2147483754,2147483754,2147483754,2147483773,126,2147483742,2147483741,2147483775,2147483776,129,128,127,93,130,130,95,106,106,106,106,106,106,106,106,106,106,106,131,132,109,115,116,116,116,116,116,116,116,116,116,116,2147483763,2147483756,106,106,106,133,130,118,134,106,106,106,2147483755,2147483758,2147483783,136,2147483784,2147483784,135,110,107,118,106,106,106,106,106,108,2147483757,109,2147483757,109,2147483757,109,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,2147483763,109,137,137,138,2147483756,106,106,106,2147483754,108,2147483756,106,106,2147483784,2147483784,2147483784,2147483784,133,130,118,134,106,106,106,108,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,139,140,2147483756,106,108,115,2147483763,137,2147483756,2147483784,2147483784,2147483784,2147483784,108,2147483757,109,138,141,142,109,115,116,116,116,116,116,116,116,2147483764,2147483764,2147483764,116,116,116,116,116,116,116,116,2147483791,2147483792,143,116,145,138,141,142,138,116,146,139,140,147,116,116,148,2147483763,2147483756,106,106,108,115,116,116,116,139,138,141,142,116,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,146,139,140,142,2147483791,2147483792,2147483797,150,149,151,152,2147483764,116,151,116,138,141,116,116,116,116,116,116,116,2147483763,2147483757,109,115,116,148,146,139,140,147,2147483764,2147483764,2147483764,2147483764,102,103,104,105,2147483764,2147483764,2147483764,2147483764,146,139,140,142,2147483791,151,152,150,150,151,152,150,149,143,116,151,138,138,141,116,116,138,141,141,141,116,153,154,116,116,155,116,116,2147483791,143,138,141,142,102,103,104,156,157,103,104,105,146,139,140,142,148,2147483791,2147483792,150,158,159,160,161,158,151,152,161,143,151,116,138,141,138,141,138,141,162,162,162,143,116,153,154,163,2147483791,144,2147483797,149,2147483792,145,138,141,142,1073741988,3221225637,3221225638,167,143,139,140,2147483764,2147483791,144,2147483792,2147483797,2147483816,151,152,169,170,151,152,150,150,151,152,151,116,116,116,138,141,2147483797,158,151,152,161,149,143,116,116,2147483791,2147483797,150,150,158,151,152,161,158,151,152,161,3221225640,1073741988,149,139,140,2147483792,2147483797,150,150,2147483816,2147483814,167,167,167,167,167,167,150,150,151,151,151,116,116,2147483791,2147483792,2147483797,151,152,150,150,150,171,172,2147483792,144,2147483820,2147483819,150,173,174,175,158,151,152,161,150,150,176,177,178,159,160,179,180,181,2147483816,2147483814,102,103,104,105,102,103,104,103,152,151,152,151,116,2147483791,2147483797,151,152,139,150,151,152,182,150,150,150,150,150,150,150,183,184,185,150,150,150,150,150,150,150,150,186,169,170,187,150,150,2147483814,167,167,188,102,103,104,105,102,103,152,150,158,151,2147483792,2147483797,150,150,158,151,152,161,152,189,190,150,189,190,150,150,150,191,192,193,150,150,150,189,190,150,150,150,150,1073741995,1073741996,194,194,151,152,167,1073742019,1073742019,3221225638,188,167,167,167,167,158,151,152,161,150,150,158,151,152,161,158,151,152,161,189,190,150,196,1073741995,1073741996,194,2147483842,3221225644,3221225643,2147483816,2147483845,197,168,150,2147483816,2147483845,150,150,150,198,3221225671,1073742024,3221225672,151,151,152,150,3221225640,1073742019,1073741988,1073742019,158,151,152,161,201,202,150,151,152,164,195,195,203,196,150,2147483816,204,195,168,150,205,198,153,154,2147483846,2147483853,205,194,167,166,195,2147483814,1073741990,151,152,103,104,3221225678,207,151,152,151,152,150,189,190,158,151,152,161,150,150,2147483856,209,151,167,167,103,104,167,204,195,204,2147483814,167,210,211,168,198,2147483802,2147483801,2147483860,2147483860,2147483846,138,141,142,167,3221225638,188,167,151,152,103,104,103,104,103,104,151,152,161,150,150,150,150,150,2147483816,195,195,2147483861,214,150,151,152,167,167,103,104,215,157,103,104,105,167,167,2147483860,2147483860,148,2147483860,2147483860,2147483860,2147483860,2147483860,2147483860,2147483860,2147483848,2147483854,166,167,167,103,104,103,104,151,152,161,150,2147483798,2147483798,2147483864,2147483865,2147483798,2147483816,2147483814,167,167,218,214,150,150,158,151,152,103,104,1073741988,3221225637,3221225638,1073741991,167,167,139,140,1073742024,1073742023,146,139,219,220,221,222,140,147,2147483847,102,103,104,105,158,151,152,103,104,138,138,2147483798,2147483871,2147483872,2147483873,2147483874,3221225640,3221225638,151,152,151,152,150,151,152,161,150,138,141,3221225622,3221225622,3221225640,3221225638,139,140,151,152,207,1073742030,1073742023,2147483860,227,228,229,230,163,3221225671,103,167,167,102,103,104,105,146,139,140,138,104,138,104,150,150,150,150,3221225640,138,151,152,2147483860,151,139,140,150,3221225622,3221225622,3221225622,103,104,3221225622,3221225640,151,152,139,207,103,104,1073742030,3221225670,2147483792,144,143,3221225671,1073742055,3221225678,103,104,103,167,167,167,138,141,1073742023,116,138,141,103,104,151,152,150,150,151,152,150,150,151,150,151,152,139,140,138,141,139,140,103,104,3221225622,139,151,152,139,140,103,104,168,2147483816,103,104,167,167,138,141,138,141,167,116,116,116,116,116,103,104,138,141,2147483853,150,151,152,150,150,151,152,150,150,150,205,138,141,116,116,138,141,139,140,138,141,2147483853,150,151,141,139,139,166,2147483814,103,104,103,104,138,141,138,141,138,141,138,141,103,104,138,141,116,116,2147483846,232,232,2147483853,151,152,150,150,150,150,205,198,116,116,116,116,116,116,138,141,116,116,2147483846,194,198,116,138,141,200,231,138,141,138,141,138,141,116,116,138,141,116,116,138,141,116,116,116,116,116,116,116,2147483846,2147483853,150,150,150,150 - - - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,1,1,2,3,6,7,8,9,4,5,1,1,1,1,2,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,10,7,11,9,4,5,2,3,6,7,8,12,6,7,8,9,4,5,2,3,6,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,13,14,15,12,6,7,15,9,6,7,8,12,6,7,8,12,6,7,8,9,6,7,8,12,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,10,7,8,9,4,5,16,17,6,7,11,18,19,20,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,21,22,1,1,1,1,1,1,1,1,1,1,1,1,2,3,6,7,8,12,6,7,8,9,10,7,8,12,6,23,24,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,8,9,4,5,1,1,1,1,1,1,1,1,1,1,13,14,8,12,6,7,8,12,6,7,8,12,6,7,8,9,25,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,6,7,11,26,1,1,1,1,1,1,1,1,1,1,16,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,8,18,27,28,1,1,1,1,1,1,1,1,1,1,13,14,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,6,23,2,29,21,22,1,1,1,1,1,1,1,1,30,31,19,20,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,8,9,25,32,8,9,4,5,1,1,1,1,1,1,1,1,24,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,18,19,14,6,7,11,18,19,14,11,26,1,1,1,1,1,1,1,1,13,20,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,33,18,19,14,8,12,6,7,8,12,6,23,24,17,8,12,6,23,24,17,6,34,1,1,1,1,1,1,1,1,30,31,19,20,8,12,6,7,33,18,19,20,8,12,6,7,33,18,27,28,24,17,6,7,8,12,6,7,8,9,25,32,6,7,8,9,25,32,8,9,4,5,1,1,1,1,1,1,1,1,24,17,6,7,8,12,6,23,30,31,19,20,33,18,27,28,1,1,13,20,33,18,19,14,33,18,19,14,8,12,8,12,6,7,8,12,6,7,11,26,1,1,1,1,1,1,1,1,13,20,8,12,6,7,33,35,1,29,36,37,38,39,4,5,1,1,16,17,6,23,24,17,6,23,24,17,6,7,6,7,8,12,6,7,11,18,27,28,1,1,1,1,1,1,1,1,30,31,19,20,33,18,27,28,40,41,19,20,33,18,42,35,1,1,13,20,8,9,25,32,8,9,25,32,8,12,8,12,6,7,8,12,6,23,1,1,1,1,1,1,1,1,1,1,1,1,30,31,27,28,1,1,30,31,43,31,27,44,27,28,1,1,30,31,19,20,33,18,19,20,8,12,6,32,6,7,8,12,6,7,8,9,4,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,30,31,27,28,24,17,6,32,33,18,8,12,6,7,11,18,19,14,11,26,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,1,1,1,29,6,32,33,18,27,28,6,7,11,18,27,28,45,31,27,28,1,1,1,1,1,1,1,1,1,1,29,4,5,1,1,1,1,29,4,5,1,1,13,14,15,9,4,5,1,1,40,46,33,18,27,28,1,1,8,12,6,23,1,1,1,1,1,29,21,22,1,1,1,1,1,1,1,40,46,11,26,1,1,1,40,46,8,9,4,5,16,17,6,7,11,26,1,1,30,31,27,28,1,1,1,1,6,7,8,9,4,22,1,1,40,46,47,35,1,1,1,1,1,1,29,36,37,38,39,4,22,1,16,17,6,7,8,9,10,7,11,18,27,28,1,1,1,1,1,1,1,1,1,1,8,12,6,7,8,9,4,5,45,48,49,50,2,3,4,5,1,40,46,19,20,33,18,42,35,1,13,14,8,12,6,7,8,12,6,23,1,1,1,1,1,1,1,1,2,3,4,5,6,7,11,18,19,14,11,26,1,1,2,3,25,7,42,26,1,30,31,43,31,27,44,27,28,1,30,31,19,14,8,12,6,7,8,9,4,5,1,1,2147483699,1,2,3,6,7,8,52,8,12,6,23,24,17,6,34,1,1,13,14,8,12,6,34,1,53,1,1,1,1,1,1,2,3,4,5,30,31,19,14,11,18,19,14,15,9,4,5,2147483702,1,13,14,8,12,6,7,6,7,8,9,25,32,8,9,4,5,16,17,6,7,8,9,4,5,1,1,1,1,1,1,13,14,8,9,4,5,16,17,6,23,24,17,6,7,15,9,4,5,16,17,6,7,8,12,8,12,6,7,8,12,6,7,8,9,10,7,8,12,6,7,8,9,4,5,2,3,4,5,16,17,6,7,8,9,10,32,8,9,25,7,15,12,6,7,15,9,25,32,8,12,6,7,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,42,26,13,14,8,9,25,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,34,16,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,9,25,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +55,55,55,55,55,55,56,57,58,58,2147483704,2147483703,2147483707,2147483708,2147483709,2147483703,55,55,55,55,55,55,55,62,63,2147483711,2147483710,55,55,55,55,55,55,55,55,55,55,55,55,56,58,58,2147483712,55,55,55,55,55, +61,60,59,55,55,65,66,58,58,58,2147483714,2147483715,2147483716,2147483717,2147483718,71,2147483712,55,61,60,59,55,55,56,57,2147483705,2147483704,55,55,55,55,55,55,61,60,59,55,55,65,66,58,58,58,72,2147483719,55,55,55, +70,69,68,67,73,58,74,58,58,58,58,2147483706,2147483723,2147483724,2147483725,2147483706,2147483705,2147483719,70,69,68,67,73,66,58,58,58,2147483713,55,55,65,73,2147483713,70,69,68,67,73,58,58,58,58,58,58,58,2147483712,65,73, +77,76,75,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,77,76,75,58,58,58,58,58,58,58,2147483719,2147483724,58,58,58,77,76,75,58,58,58,58,58,58,58,58,58,58,58,58, +78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78, +79,79,79,79,80,81,82,83,84,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,85,86,2147483735,2147483735,2147483735,2147483735,2147483734,2147483733,79,79,79,79,79,79,79, +79,79,79,79,88,89,90,91,92,79,79,2147483732,2147483731,2147483730,2147483729,2147483728,79,79,79,79,79,79,79,85,86,2147483735,2147483735,2147483735,2147483735,2147483735,2147483735,2147483735,2147483735,93,94,2147483743,2147483743,2147483743,2147483743,2147483742,2147483741,2147483735,87,2147483734,2147483733,79,79,79, +2147483735,2147483735,2147483744,2147483733,97,98,99,100,101,101,79,2147483740,2147483739,2147483738,2147483737,2147483736,79,79,79,85,86,87,87,93,94,2147483743,2147483743,2147483743,102,103,104,105,106,106,107,106,108,2147483757,2147483756,2147483755,2147483758,2147483743,95,2147483742,2147483741,2147483735,2147483735,2147483735, +2147483743,2147483743,2147483759,2147483741,2147483760,2147483761,2147483727,2147483727,79,79,79,2147483749,2147483748,2147483747,2147483746,2147483745,79,85,112,93,94,95,95,95,106,106,106,106,114,114,114,114,106,106,108,109,115,116,2147483763,2147483757,109,109,2147483756,2147483755,2147483758,2147483743,2147483743,2147483743, +2147483765,2147483765,118,2147483758,2147483767,2147483768,2147483735,2147483734,2147483733,2147483769,2147483770,123,122,121,85,86,2147483735,93,94,95,107,106,106,106,106,106,106,106,106,2147483772,2147483772,106,108,109,115,116,116,116,116,116,116,116,2147483763,2147483756,106,106,106,106, +2147483765,118,2147483754,2147483754,2147483754,2147483773,126,2147483742,2147483741,2147483775,2147483776,129,128,127,93,130,130,95,106,106,106,106,106,106,106,106,106,106,106,131,132,109,115,116,116,116,116,116,116,116,116,116,116,2147483763,2147483756,106,106,106, +133,130,118,134,106,106,106,2147483755,2147483758,2147483783,136,2147483784,2147483784,135,110,107,118,106,106,106,106,106,108,2147483757,109,2147483757,109,2147483757,109,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,2147483763,109,137,137, +138,2147483756,106,106,106,2147483754,108,2147483756,106,106,2147483784,2147483784,2147483784,2147483784,133,130,118,134,106,106,106,108,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116, +116,139,140,2147483756,106,108,115,2147483763,137,2147483756,2147483784,2147483784,2147483784,2147483784,108,2147483757,109,138,141,142,109,115,116,116,116,116,116,116,116,2147483764,2147483764,2147483764,116,116,116,116,116,116,116,116,2147483791,2147483792,143,116,145,138,141,142, +138,116,146,139,140,147,116,116,148,2147483763,2147483756,106,106,108,115,116,116,116,139,138,141,142,116,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,2147483764,146,139,140,142,2147483791,2147483792,2147483797,150,149,151,152,2147483764,116,151, +116,138,141,116,116,116,116,116,116,116,2147483763,2147483757,109,115,116,148,146,139,140,147,2147483764,2147483764,2147483764,2147483764,102,103,104,105,2147483764,2147483764,2147483764,2147483764,146,139,140,142,2147483791,151,152,150,150,151,152,150,149,143,116,151, +138,138,141,116,116,138,141,141,141,116,153,154,116,116,155,116,116,2147483791,143,138,141,142,102,103,104,156,157,103,104,105,146,139,140,142,148,2147483791,2147483792,150,158,159,160,161,158,151,152,161,143,151, +116,138,141,138,141,138,141,162,162,162,143,116,153,154,163,2147483791,144,2147483797,149,2147483792,145,138,141,142,1073741988,3221225637,3221225638,167,143,139,140,2147483764,2147483791,144,2147483792,2147483797,2147483816,151,152,169,170,151,152,150,150,151,152,151, +116,116,116,138,141,2147483797,158,151,152,161,149,143,116,116,2147483791,2147483797,150,150,158,151,152,161,158,151,152,161,3221225640,1073741988,149,139,140,2147483792,2147483797,150,150,2147483816,2147483814,167,167,167,167,167,167,150,150,151,151,151, +116,116,2147483791,2147483792,2147483797,151,152,150,150,150,171,172,2147483792,144,2147483820,2147483819,150,173,174,175,158,151,152,161,150,150,176,177,178,159,160,179,180,181,2147483816,2147483814,102,103,104,105,102,103,104,103,152,151,152,151, +116,2147483791,2147483797,151,152,139,150,151,152,182,150,150,150,150,150,150,150,183,184,185,150,150,150,150,150,150,150,150,186,169,170,187,150,150,2147483814,167,167,188,102,103,104,105,102,103,152,150,158,151, +2147483792,2147483797,150,150,158,151,152,161,152,189,190,150,189,190,150,150,150,191,192,193,150,150,150,189,190,150,150,150,150,1073741995,1073741996,194,194,151,152,167,1073742019,1073742019,3221225638,188,167,167,167,167,158,151,152,161, +150,150,158,151,152,161,158,151,152,161,189,190,150,196,1073741995,1073741996,194,2147483842,3221225644,3221225643,2147483816,2147483845,197,168,150,2147483816,2147483845,150,150,150,198,3221225671,1073742024,3221225672,151,151,152,150,3221225640,1073742019,1073741988,1073742019,158,151,152,161,201,202, +150,151,152,164,195,195,203,196,150,2147483816,204,195,168,150,205,198,153,154,2147483846,2147483853,205,194,167,166,195,2147483814,1073741990,151,152,103,104,3221225678,207,151,152,151,152,150,189,190,158,151,152,161,150,150,2147483856,209, +151,167,167,103,104,167,204,195,204,2147483814,167,210,211,168,198,2147483802,2147483801,2147483860,2147483860,2147483846,138,141,142,167,3221225638,188,167,151,152,103,104,103,104,103,104,151,152,161,150,150,150,150,150,2147483816,195,195,2147483861,214, +150,151,152,167,167,103,104,215,157,103,104,105,167,167,2147483860,2147483860,148,2147483860,2147483860,2147483860,2147483860,2147483860,2147483860,2147483860,2147483848,2147483854,166,167,167,103,104,103,104,151,152,161,150,2147483798,2147483798,2147483864,2147483865,2147483798,2147483816,2147483814,167,167,218,214, +150,150,158,151,152,103,104,1073741988,3221225637,3221225638,1073741991,167,167,139,140,1073742024,1073742023,146,139,219,220,221,222,140,147,2147483847,102,103,104,105,158,151,152,103,104,138,138,2147483798,2147483871,2147483872,2147483873,2147483874,3221225640,3221225638,151,152,151,152, +150,151,152,161,150,138,141,3221225622,3221225622,3221225640,3221225638,139,140,151,152,207,1073742030,1073742023,2147483860,227,228,229,230,163,3221225671,103,167,167,102,103,104,105,146,139,140,138,104,138,104,150,150,150,150,3221225640,138,151,152,2147483860, +151,139,140,150,3221225622,3221225622,3221225622,103,104,3221225622,3221225640,151,152,139,207,103,104,1073742030,3221225670,2147483792,144,143,3221225671,1073742055,3221225678,103,104,103,167,167,167,138,141,1073742023,116,138,141,103,104,151,152,150,150,151,152,150,150,151, +150,151,152,139,140,138,141,139,140,103,104,3221225622,139,151,152,139,140,103,104,168,2147483816,103,104,167,167,138,141,138,141,167,116,116,116,116,116,103,104,138,141,2147483853,150,151,152,150,150,151,152,150, +150,150,205,138,141,116,116,138,141,139,140,138,141,2147483853,150,151,141,139,139,166,2147483814,103,104,103,104,138,141,138,141,138,141,138,141,103,104,138,141,116,116,2147483846,232,232,2147483853,151,152,150,150,150, +150,205,198,116,116,116,116,116,116,138,141,116,116,2147483846,194,198,116,138,141,200,231,138,141,138,141,138,141,116,116,138,141,116,116,138,141,116,116,116,116,116,116,116,2147483846,2147483853,150,150,150,150 + + + + +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,1,1,2,3,6,7,8,9,4,5,1,1,1,1,2,3, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,10,7,11,9,4,5,2,3,6,7,8,12,6,7,8,9,4,5,2,3,6,7, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,13,14,15,12,6,7,15,9,6,7,8,12,6,7,8,12,6,7,8,9,6,7,8,12, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,10,7,8,9,4,5,16,17,6,7,11,18,19,20,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7, +21,22,1,1,1,1,1,1,1,1,1,1,1,1,2,3,6,7,8,12,6,7,8,9,10,7,8,12,6,23,24,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12, +8,9,4,5,1,1,1,1,1,1,1,1,1,1,13,14,8,12,6,7,8,12,6,7,8,12,6,7,8,9,25,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7, +6,7,11,26,1,1,1,1,1,1,1,1,1,1,16,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12, +8,18,27,28,1,1,1,1,1,1,1,1,1,1,13,14,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7, +6,23,2,29,21,22,1,1,1,1,1,1,1,1,30,31,19,20,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12, +8,9,25,32,8,9,4,5,1,1,1,1,1,1,1,1,24,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,18,19,14, +6,7,11,18,19,14,11,26,1,1,1,1,1,1,1,1,13,20,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,33,18,19,14,8,12,6,7,8,12,6,23,24,17, +8,12,6,23,24,17,6,34,1,1,1,1,1,1,1,1,30,31,19,20,8,12,6,7,33,18,19,20,8,12,6,7,33,18,27,28,24,17,6,7,8,12,6,7,8,9,25,32, +6,7,8,9,25,32,8,9,4,5,1,1,1,1,1,1,1,1,24,17,6,7,8,12,6,23,30,31,19,20,33,18,27,28,1,1,13,20,33,18,19,14,33,18,19,14,8,12, +8,12,6,7,8,12,6,7,11,26,1,1,1,1,1,1,1,1,13,20,8,12,6,7,33,35,1,29,36,37,38,39,4,5,1,1,16,17,6,23,24,17,6,23,24,17,6,7, +6,7,8,12,6,7,11,18,27,28,1,1,1,1,1,1,1,1,30,31,19,20,33,18,27,28,40,41,19,20,33,18,42,35,1,1,13,20,8,9,25,32,8,9,25,32,8,12, +8,12,6,7,8,12,6,23,1,1,1,1,1,1,1,1,1,1,1,1,30,31,27,28,1,1,30,31,43,31,27,44,27,28,1,1,30,31,19,20,33,18,19,20,8,12,6,32, +6,7,8,12,6,7,8,9,4,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,30,31,27,28,24,17,6,32,33,18, +8,12,6,7,11,18,19,14,11,26,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,1,1,1,1,1,29,6,32,33,18,27,28, +6,7,11,18,27,28,45,31,27,28,1,1,1,1,1,1,1,1,1,1,29,4,5,1,1,1,1,29,4,5,1,1,13,14,15,9,4,5,1,1,40,46,33,18,27,28,1,1, +8,12,6,23,1,1,1,1,1,29,21,22,1,1,1,1,1,1,1,40,46,11,26,1,1,1,40,46,8,9,4,5,16,17,6,7,11,26,1,1,30,31,27,28,1,1,1,1, +6,7,8,9,4,22,1,1,40,46,47,35,1,1,1,1,1,1,29,36,37,38,39,4,22,1,16,17,6,7,8,9,10,7,11,18,27,28,1,1,1,1,1,1,1,1,1,1, +8,12,6,7,8,9,4,5,45,48,49,50,2,3,4,5,1,40,46,19,20,33,18,42,35,1,13,14,8,12,6,7,8,12,6,23,1,1,1,1,1,1,1,1,2,3,4,5, +6,7,11,18,19,14,11,26,1,1,2,3,25,7,42,26,1,30,31,43,31,27,44,27,28,1,30,31,19,14,8,12,6,7,8,9,4,5,1,1,2147483699,1,2,3,6,7,8,52, +8,12,6,23,24,17,6,34,1,1,13,14,8,12,6,34,1,53,1,1,1,1,1,1,2,3,4,5,30,31,19,14,11,18,19,14,15,9,4,5,2147483702,1,13,14,8,12,6,7, +6,7,8,9,25,32,8,9,4,5,16,17,6,7,8,9,4,5,1,1,1,1,1,1,13,14,8,9,4,5,16,17,6,23,24,17,6,7,15,9,4,5,16,17,6,7,8,12, +8,12,6,7,8,12,6,7,8,9,10,7,8,12,6,7,8,9,4,5,2,3,4,5,16,17,6,7,8,9,10,32,8,9,25,7,15,12,6,7,15,9,25,32,8,12,6,7, +6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,42,26,13,14,8,9,25,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12, +8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,34,16,17,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7, +6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,9,25,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12,6,7,8,12 + + diff --git a/src/direction.h b/src/direction.h index ebc0e46..a83a6f8 100644 --- a/src/direction.h +++ b/src/direction.h @@ -41,4 +41,14 @@ inline vec2i unitVecInDirection(Direction dir) { } } +inline bool dirHasDir(Direction value, Direction inner) { + switch (inner) { + case Direction::up: return value == Direction::up_left || value == Direction::up || value == Direction::up_right; + case Direction::down: return value == Direction::down_left || value == Direction::down || value == Direction::down_right; + case Direction::left: return value == Direction::up_left || value == Direction::left || value == Direction::down_left; + case Direction::right: return value == Direction::up_right || value == Direction::right || value == Direction::down_right; + default: return value == inner; + } +} + #endif /* end of include guard: DIRECTION_H_AB66A90E */ diff --git a/src/map.cpp b/src/map.cpp index a60cbba..7d9800d 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1,6 +1,7 @@ #include "map.h" #include #include +#include #include #include #include "renderer.h" @@ -21,11 +22,10 @@ Map::Map(std::string_view filename, Renderer& renderer) { int firstGID = 0; // There should only be one tileset. - for (const tmx::Tileset& tileset : mapfile.getTilesets()) { - firstGID = tileset.getFirstGID(); - tilesetTextureId_ = renderer.loadImageFromFile(tileset.getImagePath()); - tilesetColumns_ = tileset.getColumnCount(); - } + const tmx::Tileset& tileset = mapfile.getTilesets()[0]; + firstGID = tileset.getFirstGID(); + tilesetTextureId_ = renderer.loadImageFromFile(tileset.getImagePath()); + tilesetColumns_ = tileset.getColumnCount(); for (const auto& layer : mapfile.getLayers()) { if (layer->getType() == tmx::Layer::Type::Tile) { @@ -34,13 +34,33 @@ Map::Map(std::string_view filename, Renderer& renderer) { std::vector tilesToStore; for (const auto& maptile : tileLayer.getTiles()) { - tilesToStore.push_back(Tile { - .id = maptile.ID - firstGID, - .flipHorizontal = (maptile.flipFlags & tmx::TileLayer::Horizontal) != 0, - .flipVertical = (maptile.flipFlags & tmx::TileLayer::Vertical) != 0 }); + Tile tile; + tile.id = maptile.ID - firstGID; + tile.flipHorizontal = (maptile.flipFlags & tmx::TileLayer::Horizontal) != 0; + tile.flipVertical = (maptile.flipFlags & tmx::TileLayer::Vertical) != 0; + + for (const tmx::Property& property : tileset.getTile(maptile.ID)->properties) { + if (property.getName() == "solid" && property.getBoolValue()) { + tile.blocked = true; + } + } + + tilesToStore.push_back(std::move(tile)); } layers_.push_back(std::move(tilesToStore)); } } } + +bool Map::isBlocked(int x, int y) const { + int i = x + y * mapSize_.w(); + + for (const std::vector& layer : layers_) { + if (layer.at(i).blocked) { + return true; + } + } + + return false; +} diff --git a/src/map.h b/src/map.h index 1031996..2f8ec1a 100644 --- a/src/map.h +++ b/src/map.h @@ -12,6 +12,7 @@ struct Tile { unsigned int id = 0; bool flipHorizontal = false; bool flipVertical = false; + bool blocked = false; }; class Map { @@ -29,6 +30,8 @@ public: int getTilesetColumns() const { return tilesetColumns_; } + bool isBlocked(int x, int y) const; + private: vec2i mapSize_; diff --git a/src/party.cpp b/src/party.cpp index 2af252f..307bca8 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -1,5 +1,6 @@ #include "party.h" #include "consts.h" +#include void Party::addMember(Game& game, int spriteId) { int index = members_.size(); @@ -93,41 +94,84 @@ void Party::move(Game& game, const Input& keystate) { pLoc += (unitVecInDirection(dir) * speed); - game.moveSprite(members_[0].spriteId, pLoc); + // Check collision. + const Map& map = game.getMap(); + bool blocked = false; + + const vec2i UL_COL_BOX = { 8, 8 }; + const vec2i DR_COL_BOX = { 4, 0 }; + vec2i oldColPosUL = (p1.loc() - UL_COL_BOX) / map.getTileSize(); + vec2i newColPosUL = (pLoc - UL_COL_BOX) / map.getTileSize(); + vec2i oldColPosDR = (p1.loc() + DR_COL_BOX) / map.getTileSize(); + vec2i newColPosDR = (pLoc + DR_COL_BOX) / map.getTileSize(); + + if (dirHasDir(dir, Direction::right) && + newColPosDR.x() > oldColPosDR.x()) { + for (int y = newColPosUL.y(); y <= newColPosDR.y(); y++) { + if (map.isBlocked(newColPosDR.x(), y)) { + blocked = true; + pLoc.x() = p1.loc().x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; + break; + } + } + } - for (int i = 1; i < members_.size(); i++) { - const Sprite& pNext = game.getSprite(members_[i].spriteId); - const Movement& posdir = members_[i].movement.front(); - game.moveSprite(members_[i].spriteId, posdir.pos); - game.setSpriteDirection(members_[i].spriteId, posdir.dir); + if (dirHasDir(dir, Direction::left) && + newColPosUL.x() < oldColPosUL.x()) { + for (int y = newColPosUL.y(); y <= newColPosDR.y(); y++) { + if (map.isBlocked(newColPosUL.x(), y)) { + blocked = true; + pLoc.x() = p1.loc().x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; + break; + } + } + } - members_[i].movement.pop_front(); - members_[i].movement.push_back({.pos = pLoc, .dir = dir}); + if (dirHasDir(dir, Direction::down) && + newColPosDR.y() > oldColPosDR.y()) { + for (int x = newColPosUL.x(); x <= newColPosDR.x(); x++) { + if (map.isBlocked(x, newColPosDR.y())) { + blocked = true; + pLoc.y() = p1.loc().y();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; + break; + } + } } -} -void Party::beginCrouch(Game& game) { - if (state_ == State::Running) { - state_ = State::Normal; + if (dirHasDir(dir, Direction::up) && + newColPosUL.y() < oldColPosUL.y()) { + for (int x = newColPosUL.x(); x <= newColPosDR.x(); x++) { + if (map.isBlocked(x, newColPosUL.y())) { + blocked = true; + pLoc.y() = p1.loc().y();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1; + break; + } + } + } + + if (blocked && state_ == State::Running) { + stopRunning(game); + } + + // Move everything + if (pLoc != p1.loc()) { + game.moveSprite(members_[0].spriteId, pLoc); - // Double the movement buffer for the followers. for (int i = 1; i < members_.size(); i++) { - std::deque newMove; - vec2i lastPos = game.getSprite(members_[i].spriteId).loc(); - - while (!members_[i].movement.empty()) { - Movement m1 = members_[i].movement.front(); - Movement m2 = m1; - m1.pos = (m1.pos + lastPos) / 2; - lastPos = m2.pos; - - newMove.push_back(m1); - newMove.push_back(m2); - members_[i].movement.pop_front(); - } + const Sprite& pNext = game.getSprite(members_[i].spriteId); + const Movement& posdir = members_[i].movement.front(); + game.moveSprite(members_[i].spriteId, posdir.pos); + game.setSpriteDirection(members_[i].spriteId, posdir.dir); - members_[i].movement = std::move(newMove); + members_[i].movement.pop_front(); + members_[i].movement.push_back({.pos = pLoc, .dir = dir}); } + } +} + +void Party::beginCrouch(Game& game) { + if (state_ == State::Running) { + stopRunning(game); } else { state_ = State::Crouching; @@ -159,3 +203,26 @@ void Party::endCrouch(Game& game) { } } } + +void Party::stopRunning(Game& game) { + state_ = State::Normal; + + // Double the movement buffer for the followers. + for (int i = 1; i < members_.size(); i++) { + std::deque newMove; + vec2i lastPos = game.getSprite(members_[i].spriteId).loc(); + + while (!members_[i].movement.empty()) { + Movement m1 = members_[i].movement.front(); + Movement m2 = m1; + m1.pos = (m1.pos + lastPos) / 2; + lastPos = m2.pos; + + newMove.push_back(m1); + newMove.push_back(m2); + members_[i].movement.pop_front(); + } + + members_[i].movement = std::move(newMove); + } +} diff --git a/src/party.h b/src/party.h index 06f8639..2864073 100644 --- a/src/party.h +++ b/src/party.h @@ -18,6 +18,8 @@ public: private: + void stopRunning(Game& game); + enum class State { Normal, Crouching, diff --git a/src/vector.h b/src/vector.h index 8019edf..9f6d54f 100644 --- a/src/vector.h +++ b/src/vector.h @@ -97,12 +97,16 @@ public: return vec2(x() * other.x(), y() * other.y()); } + vec2 operator/(const vec2& other) const { + return vec2(x() / other.x(), y() / other.y()); + } + bool operator==(const vec2& other) const { - return std::tie(x(), other.x()) == std::tie(y(), other.y()); + return (x() == other.x()) && (y() == other.y()); } bool operator!=(const vec2& other) const { - return std::tie(x(), other.x()) != std::tie(y(), other.y()); + return (x() != other.x()) || (y() != other.y()); } }; -- cgit 1.4.1