summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/map1.tmx277
-rw-r--r--src/direction.h10
-rw-r--r--src/map.cpp38
-rw-r--r--src/map.h3
-rw-r--r--src/party.cpp121
-rw-r--r--src/party.h2
-rw-r--r--src/vector.h8
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 @@
1<map version="1.0" orientation="orthogonal" renderorder="right-down" width="48" height="32" tilewidth="16" tileheight="16"> 1<?xml version="1.0" encoding="UTF-8"?>
2 <tileset firstgid="1" name="fromRom" tilewidth="16" tileheight="16" tilecount="232" columns="10"> 2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="48" height="32" tilewidth="16" tileheight="16" infinite="0" nextlayerid="2" nextobjectid="1">
3 <image source="../res/map1_tiles.png" /> 3 <tileset firstgid="1" name="fromRom" tilewidth="16" tileheight="16" tilecount="240" columns="10">
4 </tileset> 4 <image source="../res/map1_tiles.png" width="160" height="384"/>
5 <layer id="1" name="Layer 1" width="48" height="32"> 5 <tile id="102">
6 <data encoding="csv">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</data> 6 <properties>
7 </layer> 7 <property name="solid" type="bool" value="true"/>
8 <layer id="0" name="Layer 0" width="48" height="32"> 8 </properties>
9 <data encoding="csv">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</data> 9 </tile>
10 </layer> 10 <tile id="103">
11 <properties>
12 <property name="solid" type="bool" value="true"/>
13 </properties>
14 </tile>
15 <tile id="117">
16 <properties>
17 <property name="solid" type="bool" value="true"/>
18 </properties>
19 </tile>
20 <tile id="129">
21 <properties>
22 <property name="solid" type="bool" value="true"/>
23 </properties>
24 </tile>
25 <tile id="130">
26 <properties>
27 <property name="solid" type="bool" value="true"/>
28 </properties>
29 </tile>
30 <tile id="131">
31 <properties>
32 <property name="solid" type="bool" value="true"/>
33 </properties>
34 </tile>
35 <tile id="137">
36 <properties>
37 <property name="solid" type="bool" value="true"/>
38 </properties>
39 </tile>
40 <tile id="138">
41 <properties>
42 <property name="solid" type="bool" value="true"/>
43 </properties>
44 </tile>
45 <tile id="139">
46 <properties>
47 <property name="solid" type="bool" value="true"/>
48 </properties>
49 </tile>
50 <tile id="140">
51 <properties>
52 <property name="solid" type="bool" value="true"/>
53 </properties>
54 </tile>
55 <tile id="147">
56 <properties>
57 <property name="solid" type="bool" value="true"/>
58 </properties>
59 </tile>
60 <tile id="150">
61 <properties>
62 <property name="solid" type="bool" value="true"/>
63 </properties>
64 </tile>
65 <tile id="151">
66 <properties>
67 <property name="solid" type="bool" value="true"/>
68 </properties>
69 </tile>
70 <tile id="158">
71 <properties>
72 <property name="solid" type="bool" value="true"/>
73 </properties>
74 </tile>
75 <tile id="159">
76 <properties>
77 <property name="solid" type="bool" value="true"/>
78 </properties>
79 </tile>
80 <tile id="168">
81 <properties>
82 <property name="solid" type="bool" value="true"/>
83 </properties>
84 </tile>
85 <tile id="169">
86 <properties>
87 <property name="solid" type="bool" value="true"/>
88 </properties>
89 </tile>
90 <tile id="176">
91 <properties>
92 <property name="solid" type="bool" value="true"/>
93 </properties>
94 </tile>
95 <tile id="177">
96 <properties>
97 <property name="solid" type="bool" value="true"/>
98 </properties>
99 </tile>
100 <tile id="178">
101 <properties>
102 <property name="solid" type="bool" value="true"/>
103 </properties>
104 </tile>
105 <tile id="179">
106 <properties>
107 <property name="solid" type="bool" value="true"/>
108 </properties>
109 </tile>
110 <tile id="185">
111 <properties>
112 <property name="solid" type="bool" value="true"/>
113 </properties>
114 </tile>
115 <tile id="186">
116 <properties>
117 <property name="solid" type="bool" value="true"/>
118 </properties>
119 </tile>
120 <tile id="195">
121 <properties>
122 <property name="solid" type="bool" value="true"/>
123 </properties>
124 </tile>
125 <tile id="200">
126 <properties>
127 <property name="solid" type="bool" value="true"/>
128 </properties>
129 </tile>
130 <tile id="201">
131 <properties>
132 <property name="solid" type="bool" value="true"/>
133 </properties>
134 </tile>
135 <tile id="215">
136 <properties>
137 <property name="solid" type="bool" value="true"/>
138 </properties>
139 </tile>
140 <tile id="216">
141 <properties>
142 <property name="solid" type="bool" value="true"/>
143 </properties>
144 </tile>
145 <tile id="218">
146 <properties>
147 <property name="solid" type="bool" value="true"/>
148 </properties>
149 </tile>
150 <tile id="219">
151 <properties>
152 <property name="solid" type="bool" value="true"/>
153 </properties>
154 </tile>
155 <tile id="220">
156 <properties>
157 <property name="solid" type="bool" value="true"/>
158 </properties>
159 </tile>
160 <tile id="221">
161 <properties>
162 <property name="solid" type="bool" value="true"/>
163 </properties>
164 </tile>
165 <tile id="223">
166 <properties>
167 <property name="solid" type="bool" value="true"/>
168 </properties>
169 </tile>
170 <tile id="224">
171 <properties>
172 <property name="solid" type="bool" value="true"/>
173 </properties>
174 </tile>
175 <tile id="226">
176 <properties>
177 <property name="solid" type="bool" value="true"/>
178 </properties>
179 </tile>
180 <tile id="227">
181 <properties>
182 <property name="solid" type="bool" value="true"/>
183 </properties>
184 </tile>
185 <tile id="228">
186 <properties>
187 <property name="solid" type="bool" value="true"/>
188 </properties>
189 </tile>
190 <tile id="229">
191 <properties>
192 <property name="solid" type="bool" value="true"/>
193 </properties>
194 </tile>
195 </tileset>
196 <layer id="1" name="Layer 1" width="48" height="32">
197 <data encoding="csv">
19855,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,
19961,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,
20070,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,
20177,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,
20278,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,
20379,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,
20479,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,
2052147483735,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,
2062147483743,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,
2072147483765,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,
2082147483765,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,
209133,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,
210138,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,
211116,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,
212138,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,
213116,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,
214138,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,
215116,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,
216116,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,
217116,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,
218116,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,
2192147483792,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,
220150,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,
221150,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,
222151,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,
223150,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,
224150,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,
225150,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,
226151,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,
227150,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,
228150,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,
229150,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
230</data>
231 </layer>
232 <layer id="1" name="Layer 0" width="48" height="32">
233 <data encoding="csv">
2341,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,
2351,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,
2361,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,
2371,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,
2381,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,
2391,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,
2401,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,
24121,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,
2428,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,
2436,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,
2448,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,
2456,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,
2468,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,
2476,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,
2488,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,
2496,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,
2508,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,
2516,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,
2528,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,
2536,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,
2548,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,
2556,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,
2568,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,
2576,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,
2588,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,
2596,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,
2608,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,
2616,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,
2628,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,
2636,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,
2648,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,
2656,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
266</data>
267 </layer>
11</map> 268</map>
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) {
41 } 41 }
42} 42}
43 43
44inline bool dirHasDir(Direction value, Direction inner) {
45 switch (inner) {
46 case Direction::up: return value == Direction::up_left || value == Direction::up || value == Direction::up_right;
47 case Direction::down: return value == Direction::down_left || value == Direction::down || value == Direction::down_right;
48 case Direction::left: return value == Direction::up_left || value == Direction::left || value == Direction::down_left;
49 case Direction::right: return value == Direction::up_right || value == Direction::right || value == Direction::down_right;
50 default: return value == inner;
51 }
52}
53
44#endif /* end of include guard: DIRECTION_H_AB66A90E */ 54#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 @@
1#include "map.h" 1#include "map.h"
2#include <tmxlite/Map.hpp> 2#include <tmxlite/Map.hpp>
3#include <tmxlite/Layer.hpp> 3#include <tmxlite/Layer.hpp>
4#include <tmxlite/Property.hpp>
4#include <tmxlite/TileLayer.hpp> 5#include <tmxlite/TileLayer.hpp>
5#include <tmxlite/Tileset.hpp> 6#include <tmxlite/Tileset.hpp>
6#include "renderer.h" 7#include "renderer.h"
@@ -21,11 +22,10 @@ Map::Map(std::string_view filename, Renderer& renderer) {
21 22
22 int firstGID = 0; 23 int firstGID = 0;
23 // There should only be one tileset. 24 // There should only be one tileset.
24 for (const tmx::Tileset& tileset : mapfile.getTilesets()) { 25 const tmx::Tileset& tileset = mapfile.getTilesets()[0];
25 firstGID = tileset.getFirstGID(); 26 firstGID = tileset.getFirstGID();
26 tilesetTextureId_ = renderer.loadImageFromFile(tileset.getImagePath()); 27 tilesetTextureId_ = renderer.loadImageFromFile(tileset.getImagePath());
27 tilesetColumns_ = tileset.getColumnCount(); 28 tilesetColumns_ = tileset.getColumnCount();
28 }
29 29
30 for (const auto& layer : mapfile.getLayers()) { 30 for (const auto& layer : mapfile.getLayers()) {
31 if (layer->getType() == tmx::Layer::Type::Tile) { 31 if (layer->getType() == tmx::Layer::Type::Tile) {
@@ -34,13 +34,33 @@ Map::Map(std::string_view filename, Renderer& renderer) {
34 std::vector<Tile> tilesToStore; 34 std::vector<Tile> tilesToStore;
35 35
36 for (const auto& maptile : tileLayer.getTiles()) { 36 for (const auto& maptile : tileLayer.getTiles()) {
37 tilesToStore.push_back(Tile { 37 Tile tile;
38 .id = maptile.ID - firstGID, 38 tile.id = maptile.ID - firstGID;
39 .flipHorizontal = (maptile.flipFlags & tmx::TileLayer::Horizontal) != 0, 39 tile.flipHorizontal = (maptile.flipFlags & tmx::TileLayer::Horizontal) != 0;
40 .flipVertical = (maptile.flipFlags & tmx::TileLayer::Vertical) != 0 }); 40 tile.flipVertical = (maptile.flipFlags & tmx::TileLayer::Vertical) != 0;
41
42 for (const tmx::Property& property : tileset.getTile(maptile.ID)->properties) {
43 if (property.getName() == "solid" && property.getBoolValue()) {
44 tile.blocked = true;
45 }
46 }
47
48 tilesToStore.push_back(std::move(tile));
41 } 49 }
42 50
43 layers_.push_back(std::move(tilesToStore)); 51 layers_.push_back(std::move(tilesToStore));
44 } 52 }
45 } 53 }
46} 54}
55
56bool Map::isBlocked(int x, int y) const {
57 int i = x + y * mapSize_.w();
58
59 for (const std::vector<Tile>& layer : layers_) {
60 if (layer.at(i).blocked) {
61 return true;
62 }
63 }
64
65 return false;
66}
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 {
12 unsigned int id = 0; 12 unsigned int id = 0;
13 bool flipHorizontal = false; 13 bool flipHorizontal = false;
14 bool flipVertical = false; 14 bool flipVertical = false;
15 bool blocked = false;
15}; 16};
16 17
17class Map { 18class Map {
@@ -29,6 +30,8 @@ public:
29 30
30 int getTilesetColumns() const { return tilesetColumns_; } 31 int getTilesetColumns() const { return tilesetColumns_; }
31 32
33 bool isBlocked(int x, int y) const;
34
32private: 35private:
33 36
34 vec2i mapSize_; 37 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 @@
1#include "party.h" 1#include "party.h"
2#include "consts.h" 2#include "consts.h"
3#include <iostream>
3 4
4void Party::addMember(Game& game, int spriteId) { 5void Party::addMember(Game& game, int spriteId) {
5 int index = members_.size(); 6 int index = members_.size();
@@ -93,41 +94,84 @@ void Party::move(Game& game, const Input& keystate) {
93 94
94 pLoc += (unitVecInDirection(dir) * speed); 95 pLoc += (unitVecInDirection(dir) * speed);
95 96
96 game.moveSprite(members_[0].spriteId, pLoc); 97 // Check collision.
98 const Map& map = game.getMap();
99 bool blocked = false;
100
101 const vec2i UL_COL_BOX = { 8, 8 };
102 const vec2i DR_COL_BOX = { 4, 0 };
103 vec2i oldColPosUL = (p1.loc() - UL_COL_BOX) / map.getTileSize();
104 vec2i newColPosUL = (pLoc - UL_COL_BOX) / map.getTileSize();
105 vec2i oldColPosDR = (p1.loc() + DR_COL_BOX) / map.getTileSize();
106 vec2i newColPosDR = (pLoc + DR_COL_BOX) / map.getTileSize();
107
108 if (dirHasDir(dir, Direction::right) &&
109 newColPosDR.x() > oldColPosDR.x()) {
110 for (int y = newColPosUL.y(); y <= newColPosDR.y(); y++) {
111 if (map.isBlocked(newColPosDR.x(), y)) {
112 blocked = true;
113 pLoc.x() = p1.loc().x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1;
114 break;
115 }
116 }
117 }
97 118
98 for (int i = 1; i < members_.size(); i++) { 119 if (dirHasDir(dir, Direction::left) &&
99 const Sprite& pNext = game.getSprite(members_[i].spriteId); 120 newColPosUL.x() < oldColPosUL.x()) {
100 const Movement& posdir = members_[i].movement.front(); 121 for (int y = newColPosUL.y(); y <= newColPosDR.y(); y++) {
101 game.moveSprite(members_[i].spriteId, posdir.pos); 122 if (map.isBlocked(newColPosUL.x(), y)) {
102 game.setSpriteDirection(members_[i].spriteId, posdir.dir); 123 blocked = true;
124 pLoc.x() = p1.loc().x();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1;
125 break;
126 }
127 }
128 }
103 129
104 members_[i].movement.pop_front(); 130 if (dirHasDir(dir, Direction::down) &&
105 members_[i].movement.push_back({.pos = pLoc, .dir = dir}); 131 newColPosDR.y() > oldColPosDR.y()) {
132 for (int x = newColPosUL.x(); x <= newColPosDR.x(); x++) {
133 if (map.isBlocked(x, newColPosDR.y())) {
134 blocked = true;
135 pLoc.y() = p1.loc().y();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1;
136 break;
137 }
138 }
106 } 139 }
107}
108 140
109void Party::beginCrouch(Game& game) { 141 if (dirHasDir(dir, Direction::up) &&
110 if (state_ == State::Running) { 142 newColPosUL.y() < oldColPosUL.y()) {
111 state_ = State::Normal; 143 for (int x = newColPosUL.x(); x <= newColPosDR.x(); x++) {
144 if (map.isBlocked(x, newColPosUL.y())) {
145 blocked = true;
146 pLoc.y() = p1.loc().y();//(newColPosDR * map.getTileSize() - (collisionBox / 2)).x() - 1;
147 break;
148 }
149 }
150 }
151
152 if (blocked && state_ == State::Running) {
153 stopRunning(game);
154 }
155
156 // Move everything
157 if (pLoc != p1.loc()) {
158 game.moveSprite(members_[0].spriteId, pLoc);
112 159
113 // Double the movement buffer for the followers.
114 for (int i = 1; i < members_.size(); i++) { 160 for (int i = 1; i < members_.size(); i++) {
115 std::deque<Movement> newMove; 161 const Sprite& pNext = game.getSprite(members_[i].spriteId);
116 vec2i lastPos = game.getSprite(members_[i].spriteId).loc(); 162 const Movement& posdir = members_[i].movement.front();
117 163 game.moveSprite(members_[i].spriteId, posdir.pos);
118 while (!members_[i].movement.empty()) { 164 game.setSpriteDirection(members_[i].spriteId, posdir.dir);
119 Movement m1 = members_[i].movement.front();
120 Movement m2 = m1;
121 m1.pos = (m1.pos + lastPos) / 2;
122 lastPos = m2.pos;
123
124 newMove.push_back(m1);
125 newMove.push_back(m2);
126 members_[i].movement.pop_front();
127 }
128 165
129 members_[i].movement = std::move(newMove); 166 members_[i].movement.pop_front();
167 members_[i].movement.push_back({.pos = pLoc, .dir = dir});
130 } 168 }
169 }
170}
171
172void Party::beginCrouch(Game& game) {
173 if (state_ == State::Running) {
174 stopRunning(game);
131 } else { 175 } else {
132 state_ = State::Crouching; 176 state_ = State::Crouching;
133 177
@@ -159,3 +203,26 @@ void Party::endCrouch(Game& game) {
159 } 203 }
160 } 204 }
161} 205}
206
207void Party::stopRunning(Game& game) {
208 state_ = State::Normal;
209
210 // Double the movement buffer for the followers.
211 for (int i = 1; i < members_.size(); i++) {
212 std::deque<Movement> newMove;
213 vec2i lastPos = game.getSprite(members_[i].spriteId).loc();
214
215 while (!members_[i].movement.empty()) {
216 Movement m1 = members_[i].movement.front();
217 Movement m2 = m1;
218 m1.pos = (m1.pos + lastPos) / 2;
219 lastPos = m2.pos;
220
221 newMove.push_back(m1);
222 newMove.push_back(m2);
223 members_[i].movement.pop_front();
224 }
225
226 members_[i].movement = std::move(newMove);
227 }
228}
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:
18 18
19private: 19private:
20 20
21 void stopRunning(Game& game);
22
21 enum class State { 23 enum class State {
22 Normal, 24 Normal,
23 Crouching, 25 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:
97 return vec2(x() * other.x(), y() * other.y()); 97 return vec2(x() * other.x(), y() * other.y());
98 } 98 }
99 99
100 vec2 operator/(const vec2& other) const {
101 return vec2(x() / other.x(), y() / other.y());
102 }
103
100 bool operator==(const vec2& other) const { 104 bool operator==(const vec2& other) const {
101 return std::tie(x(), other.x()) == std::tie(y(), other.y()); 105 return (x() == other.x()) && (y() == other.y());
102 } 106 }
103 107
104 bool operator!=(const vec2& other) const { 108 bool operator!=(const vec2& other) const {
105 return std::tie(x(), other.x()) != std::tie(y(), other.y()); 109 return (x() != other.x()) || (y() != other.y());
106 } 110 }
107 111
108}; 112};