scrolling kinda works if you squint!

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-07-02 13:04:58 -04:00
parent 243fbb0584
commit 3a86c4674d
8 changed files with 540 additions and 568 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,104 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.9" tiledversion="1.9.0" orientation="orthogonal" renderorder="right-down" width="40" height="40" tilewidth="8" tileheight="8" infinite="0" nextlayerid="6" nextobjectid="39">
<editorsettings>
<export target="RPGmap.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../sprites/kenney_rpg.tsx"/>
<layer id="1" name="map" width="40" height="40">
<data encoding="csv">
1,2,39,40,1,2,137,138,1,2,71,72,73,74,75,76,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,73,74,35,36,171,172,35,36,105,106,107,108,109,110,35,39,40,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,139,140,207,208,143,144,69,73,74,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,173,174,241,242,177,178,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
137,138,137,138,307,274,137,138,341,342,345,346,411,412,137,138,1,2,33,34,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
171,172,171,172,307,307,171,172,375,376,379,380,445,446,171,172,35,36,67,68,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
205,206,205,206,69,70,205,206,413,414,39,40,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
239,240,239,240,103,104,39,40,447,448,73,74,307,104,239,274,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,307,1,2,73,74,413,414,137,39,40,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,447,448,171,73,74,36,171,172,331,332,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,274,206,413,414,235,236,233,234,205,364,365,366,367,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,39,40,239,240,447,448,269,270,267,268,397,398,399,400,401,402,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,237,238,73,74,137,138,413,414,233,234,235,236,431,432,433,434,435,436,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,271,272,35,353,354,172,447,448,267,268,269,270,465,466,467,468,469,470,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,351,352,69,387,388,206,347,348,349,350,343,344,499,500,439,440,503,504,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,385,386,103,104,239,240,381,121,121,121,121,378,403,404,473,474,405,406,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,409,410,345,346,345,346,417,121,121,121,121,418,345,346,417,418,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,
35,36,443,444,379,380,379,380,451,452,451,452,451,452,379,380,451,452,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,
69,57,58,206,69,70,205,206,69,307,205,206,69,70,205,206,39,40,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
90,91,92,93,57,58,57,58,103,104,239,240,103,104,239,240,73,74,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
91,92,91,92,91,92,91,92,93,21,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
125,126,125,126,125,126,125,126,127,94,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
159,160,159,160,159,160,159,160,70,26,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240
</data>
</layer>
<objectgroup id="2" name="coll">
<object id="1" x="80.3013" y="-0.325766" width="47.399" height="16.4512"/>
<object id="6" x="127.863" y="70.3655" width="16.2883" height="9.44722"/>
<object id="16" x="146.182" y="32" width="11.4545" height="15.8182"/>
<object id="17" x="18" y="97.8182" width="11.8182" height="12.7273"/>
<object id="18" x="113.818" y="16.3636" width="12" height="13.4545"/>
<object id="19" x="81.2727" y="16.3636" width="13.0909" height="14.5455"/>
<object id="20" x="82.9091" y="85.2727" width="26" height="26.7273"/>
<object id="21" x="99.6364" y="80.9091" width="8.18182" height="4.54545"/>
<object id="22" x="112" y="94.1818" width="47.6364" height="17.2727"/>
<object id="23" x="120.727" y="86.9091" width="30.3636" height="7.27273"/>
<object id="24" x="127.636" y="80" width="16.3636" height="7.09091"/>
<object id="25" x="114.364" y="111.818" width="11.4545" height="12.5455"/>
<object id="26" x="145.091" y="111.273" width="12.1818" height="12.5455"/>
<object id="28" x="11.2727" y="146.182" width="8.90909" height="7.09091"/>
<object id="36" x="0.397535" y="153.846" width="61.2204" height="27.4299"/>
<object id="37" x="62.0155" y="162.194" width="8.34824" height="11.131"/>
</objectgroup>
<objectgroup id="3" name="act">
<object id="30" name="sign" x="16" y="96" width="16" height="20">
<properties>
<property name="dialogue" value="18 chars per line\nallowed. Or else!"/>
<property name="direction" value="Up"/>
</properties>
</object>
<object id="31" name="gravestone 1" x="82.64" y="103" width="7" height="16">
<properties>
<property name="dialogue" value="Ded."/>
<property name="direction" value="Up"/>
</properties>
</object>
<object id="32" name="gravestone 2" x="96.18" y="103.36" width="7" height="16">
<properties>
<property name="dialogue" value="Moar ded."/>
<property name="direction" value="Up"/>
</properties>
</object>
</objectgroup>
<objectgroup id="5" name="warps">
<object id="35" name="dungeon 1" x="96.4758" y="17.0705" width="14.978" height="10">
<properties>
<property name="warpTarget" type="int" value="1"/>
</properties>
</object>
<object id="38" name="house 1" x="128.801" y="112.9" width="14.7088" height="7.95071">
<properties>
<property name="warpTarget" type="int" value="2"/>
</properties>
</object>
</objectgroup>
<objectgroup id="4" name="spc">
<object id="33" name="mara_start" x="32" y="31" width="16" height="16"/>
</objectgroup>
</map>
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="40" height="40" tilewidth="8" tileheight="8" infinite="0" nextlayerid="6" nextobjectid="39">
<editorsettings>
<export target="RPGmap.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../sprites/kenney_rpg.tsx"/>
<layer id="1" name="map" width="40" height="40">
<data encoding="csv">
1,2,39,40,1,2,137,138,1,2,71,72,73,74,75,76,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,73,74,35,36,171,172,35,36,105,106,107,108,109,110,35,39,40,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,139,140,207,208,143,144,69,73,74,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,173,174,241,242,177,178,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
137,138,137,138,307,274,137,138,341,342,345,346,411,412,137,138,1,2,33,34,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
171,172,171,172,307,307,171,172,375,376,379,380,445,446,171,172,35,36,67,68,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
205,206,205,206,69,70,205,206,413,414,39,40,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
239,240,239,240,103,104,39,40,447,448,73,74,307,104,239,274,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,307,1,2,73,74,413,414,137,39,40,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,447,448,171,73,74,36,171,172,331,332,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,274,206,413,414,235,236,233,234,205,364,365,366,367,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,39,40,239,240,447,448,269,270,267,268,397,398,399,400,401,402,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,237,238,73,74,137,138,413,414,233,234,235,236,431,432,433,434,435,436,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,271,272,35,353,354,172,447,448,267,268,269,270,465,466,467,468,469,470,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,351,352,69,387,388,206,347,348,349,350,343,344,499,500,439,440,503,504,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,385,386,103,104,239,240,381,121,121,121,121,378,403,404,473,474,405,406,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,409,410,345,346,345,346,417,121,121,121,121,418,345,346,417,418,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,
35,36,443,444,379,380,379,380,451,452,451,452,451,452,379,380,451,452,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,
69,57,58,206,69,70,205,206,69,307,205,206,69,70,205,206,39,40,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
90,91,92,93,57,58,57,58,103,104,239,240,103,104,239,240,73,74,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
91,92,91,92,91,92,91,92,93,21,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
125,126,125,126,125,126,125,126,127,94,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
159,160,159,160,159,160,159,160,70,26,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,
1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,
35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,
69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,
103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240
</data>
</layer>
<objectgroup id="2" name="coll">
<object id="1" x="80.3013" y="-0.325766" width="47.399" height="16.4512"/>
<object id="6" x="127.863" y="70.3655" width="16.2883" height="9.44722"/>
<object id="16" x="146.182" y="32" width="11.4545" height="15.8182"/>
<object id="17" x="18" y="97.8182" width="11.8182" height="12.7273"/>
<object id="18" x="113.818" y="16.3636" width="12" height="13.4545"/>
<object id="19" x="81.2727" y="16.3636" width="13.0909" height="14.5455"/>
<object id="20" x="82.9091" y="85.2727" width="26" height="26.7273"/>
<object id="21" x="99.6364" y="80.9091" width="8.18182" height="4.54545"/>
<object id="22" x="112" y="94.1818" width="47.6364" height="17.2727"/>
<object id="23" x="120.727" y="86.9091" width="30.3636" height="7.27273"/>
<object id="24" x="127.636" y="80" width="16.3636" height="7.09091"/>
<object id="25" x="114.364" y="111.818" width="11.4545" height="12.5455"/>
<object id="26" x="145.091" y="111.273" width="12.1818" height="12.5455"/>
<object id="28" x="11.2727" y="146.182" width="8.90909" height="7.09091"/>
<object id="36" x="0.397535" y="153.846" width="61.2204" height="27.4299"/>
<object id="37" x="62.0155" y="162.194" width="8.34824" height="11.131"/>
</objectgroup>
<objectgroup id="3" name="act">
<object id="30" name="sign" x="16" y="96" width="16" height="20">
<properties>
<property name="dialogue" value="18 chars per line\nallowed. Or else!"/>
<property name="direction" value="Up"/>
</properties>
</object>
<object id="31" name="gravestone 1" x="82.64" y="103" width="7" height="16">
<properties>
<property name="dialogue" value="Ded."/>
<property name="direction" value="Up"/>
</properties>
</object>
<object id="32" name="gravestone 2" x="96.18" y="103.36" width="7" height="16">
<properties>
<property name="dialogue" value="Moar ded."/>
<property name="direction" value="Up"/>
</properties>
</object>
</objectgroup>
<objectgroup id="5" name="warps">
<object id="35" name="dungeon 1" x="96.4758" y="17.0705" width="14.978" height="10">
<properties>
<property name="warpTarget" type="int" value="1"/>
</properties>
</object>
<object id="38" name="house 1" x="128.801" y="112.9" width="14.7088" height="7.95071">
<properties>
<property name="warpTarget" type="int" value="2"/>
</properties>
</object>
</objectgroup>
<objectgroup id="4" name="spc">
<object id="33" name="mara_start" x="32" y="31" width="16" height="16"/>
</objectgroup>
</map>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 356 B

View File

@ -19,7 +19,6 @@ var mara_frame: bool = false;
var mara_box: Rect = Rect{ .base = map.start_point, .width = 16, .height = 16 };
var mara_speed: i16 = 0;
var old_speed: i16 = 0;
var screen = Rect{ .base = Point{ .x = 0, .y = 0 }, .width = 160, .height = 160 };
const screen_width = 20;
const screen_height = 20;
@ -35,7 +34,7 @@ var camera = Point{ .x = 0, .y = 0 };
var state: sh0rk.State = .Gameplay;
fn world_to_screen(p: Point) Point {
p.sub(camera);
return p.sub(camera);
}
fn screen_to_world(p: Point) Point {
@ -69,10 +68,10 @@ fn bonk() void {
},
);
sound_timer = 12;
sound_timer = 30;
}
fn drawMap() !void {
fn map_colors() void {
switch (map.tileset) {
.Dungeon => {
w4.m.colors.* = .{
@ -91,58 +90,44 @@ fn drawMap() !void {
};
},
}
if (!done) {
var buf = fmt.bufPrint(&textBuf, "camera: {},{}", .{ camera.x, camera.y }) catch unreachable;
w4.trace(buf);
}
}
var startCol: i32 = @divTrunc(camera.x, tile_size);
fn drawMap() !void {
map_colors();
var startCol = @divTrunc(camera.x, tile_size);
var endCol = startCol + screen_width;
var startRow: i32 = @divTrunc(camera.y, tile_size);
var startRow = @divTrunc(camera.y, tile_size);
var endRow = startRow + screen_height;
var offsetX = startCol * tile_size;
var offsetY = startRow * tile_size;
if (!done) {
var buf = fmt.bufPrint(&textBuf, "{},{}: {},{}", .{ startCol, startRow, endCol, endRow }) catch unreachable;
w4.trace(buf);
}
if (!done) {
var buf = fmt.bufPrint(&textBuf, "offx: {}, offy: {}", .{ offsetX, offsetY }) catch unreachable;
w4.trace(buf);
}
var col: i32 = startCol;
var col: i16 = startCol;
while (col < endCol) {
var row: i32 = startRow;
var row: i16 = startRow;
defer col += 1;
while (row < endRow) {
defer row += 1;
var tile = map.get_tile(@intCast(u32, col), @intCast(u32, row));
if (col < map.width and row < map.height) {
var tile = map.get_tile(col, row);
var world = Point{ .x = col * 8, .y = row * 8 };
var scr = world_to_screen(world);
if(!done) {
var buf = fmt.bufPrint(&textBuf, "{},{}: {},{}", .{ row, col, scr.x, scr.y }) catch unreachable;
w4.trace(buf);
}
var x = (row - startCol) * tile_size - offsetX;
var y = (col - startRow) * tile_size - offsetY;
if (x < 0) {
x = x * -1;
draw_tile(tile, scr.y, scr.x);
}
if (y < 0) {
y = y * -1;
}
if (!done) {
var buf = fmt.bufPrint(&textBuf, "{},{}: {}: {},{}", .{ col, row, tile, x, y }) catch unreachable;
w4.trace(buf);
}
draw_tile(tile, @intCast(u32, x), @intCast(u32, y));
}
}
}
fn draw_tile(tile: u32, x: u32, y: u32) void {
fn draw_tile(tile: u32, x: i32, y: i32) void {
if (tile == 0) {
w4.rect(x, y, 8, 8);
return;
@ -158,8 +143,8 @@ fn draw_tile(tile: u32, x: u32, y: u32) void {
y,
8,
8,
@intCast(u32, tileX) * 8,
@intCast(u32, tileY) * 8,
tileX * 8,
tileY * 8,
sprites.kenney_rpg_width,
w4.BlitFlags{ .two_bits = true },
),
@ -169,8 +154,8 @@ fn draw_tile(tile: u32, x: u32, y: u32) void {
y,
8,
8,
@intCast(u32, tileX) * 8,
@intCast(u32, tileY) * 8,
tileX * 8,
tileY * 8,
sprites.dungeon_width,
w4.BlitFlags{ .two_bits = true },
),
@ -197,16 +182,16 @@ fn move_mara(gamepad: w4.GamePad) void {
switch (mara_direction) {
.Up => {
mara_box.base.y -= mara_speed;
camera.x -= mara_speed;
},
.Down => {
mara_box.base.y += mara_speed;
camera.x += mara_speed;
},
.Left => {
mara_box.base.x -= mara_speed;
camera.y -= mara_speed;
},
.Right => {
mara_box.base.x += mara_speed;
camera.y += mara_speed;
},
}
}
@ -232,7 +217,7 @@ fn title() !void {
}
const story = "After defeating\nthe evil mage,\nMalto was at\npeace.\n\nOne day Mara was\nwalking along the\nbeach when she saw\nthe killing stone\nwas split in two.\nTamamo-no-Mae was\nfree to wreak havoc\nacross the land.\n\nHelp us again Mara!\nSave Kanar from\nTamamo-no-Mae!\n\nPress x.";
var story_idx: usize = 0;
var story_idx: u16 = 0;
var story_counter: u8 = 4;
fn storydump() !void {
@ -378,7 +363,7 @@ fn draw_mara() void {
flags.flip_x = true;
}
if (frame_count % 32 == 0 and mara_speed > 0) {
if (frame_count % 16 == 0 and mara_speed > 0) {
mara_frame = !mara_frame;
}
@ -390,12 +375,12 @@ fn draw_mara() void {
};
var step: u32 = if (mara_frame) 1 else 0;
w4.blitSub(&sprites.Mara, @intCast(u32, mara_box.base.x), @intCast(u32, mara_box.base.y), 16, 16, 16 * (frame + step), 0, 96, flags);
w4.blitSub(&sprites.Mara, mara_box.base.x, mara_box.base.y, 16, 16, 16 * (frame + step), 0, 96, flags);
}
pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace) noreturn {
_ = st;
w4.trace("!!! PANIC !!!");
w4.trace(msg);
while (true) {}
unreachable;
}

View File

@ -10,8 +10,14 @@ const Rect = sh0rk.Rect;
pub const width = 20;
pub const height = 20;
pub fn get_tile(x: u32, y: u32) u9 {
return data[x * height + y];
pub fn get_tile(x: i32, y: i32) u9 {
if (x < 0 or y < 0) {
return 0;
}
if (x >= width or y >= height) {
return 0;
}
return data[@intCast(u32, x) * height + @intCast(u32, y)];
}
pub const tileset: Tileset = .Dungeon;
pub const ts_width = 14;

View File

@ -10,8 +10,14 @@ const Rect = sh0rk.Rect;
pub const width = 40;
pub const height = 40;
pub fn get_tile(x: u32, y: u32) u9 {
return data[x * height + y];
pub fn get_tile(x: i32, y: i32) u9 {
if (x < 0 or y < 0) {
return 0;
}
if (x >= width or y >= height) {
return 0;
}
return data[@intCast(u32, x) * height + @intCast(u32, y)];
}
pub const tileset: Tileset = .Rpg;
pub const ts_width = 34;

View File

@ -24,8 +24,14 @@ out += `const Rect = sh0rk.Rect;\n\n`;
out += `pub const width = ${map.width};\n`;
out += `pub const height = ${map.height};\n\n`;
out += `pub fn get_tile(x: u32, y: u32) u9 {
return data[x * height + y];
out += `pub fn get_tile(x: i32, y: i32) u9 {
if (x < 0 or y < 0) {
return 0;
}
if (x >= width or y >= height) {
return 0;
}
return data[@intCast(u32, x) * height + @intCast(u32, y)];
}
`;

View File

@ -116,8 +116,8 @@ pub const SystemFlags = packed struct {
//
const raw_api = struct {
extern fn blit(sprite: [*]const u8, x: u32, y: u32, width: u32, height: u32, flags: u32) void;
extern fn blitSub(sprite: [*]const u8, x: u32, y: u32, width: u32, height: u32, src_x: u32, src_y: u32, stride: u32, flags: u32) void;
extern fn blit(sprite: [*]const u8, x: i32, y: i32, width: u32, height: u32, flags: u32) void;
extern fn blitSub(sprite: [*]const u8, x: i32, y: i32, width: u32, height: u32, src_x: u32, src_y: u32, stride: u32, flags: u32) void;
extern fn tone(frequency: u32, duration: u32, volume: u32, flags: u32) void;
};
@ -137,7 +137,7 @@ pub const BlitFlags = packed struct {
};
/// Copies pixels to the framebuffer.
pub fn blit(sprite: []const u8, x: u32, y: u32, width: u32, height: u32, flags: BlitFlags) void {
pub fn blit(sprite: []const u8, x: i32, y: i32, width: u32, height: u32, flags: BlitFlags) void {
raw_api.blit(sprite.ptr, x, y, width, height, @bitCast(u32, flags));
}
@ -145,24 +145,24 @@ pub fn blit(sprite: []const u8, x: u32, y: u32, width: u32, height: u32, flags:
/// srcX: Source X position of the sprite region.
/// srcY: Source Y position of the sprite region.
/// stride: Total width of the overall sprite atlas. This is typically larger than width.
pub fn blitSub(sprite: []const u8, x: u32, y: u32, width: u32, height: u32, src_x: u32, src_y: u32, stride: u32, flags: BlitFlags) void {
pub fn blitSub(sprite: []const u8, x: i32, y: i32, width: u32, height: u32, src_x: u32, src_y: u32, stride: u32, flags: BlitFlags) void {
raw_api.blitSub(sprite.ptr, x, y, width, height, src_x, src_y, stride, @bitCast(u32, flags));
}
/// Draws a line between two points.
pub extern fn line(x1: u32, y1: u32, x2: u32, y2: u32) void;
pub extern fn line(x1: i32, y1: i32, x2: i32, y2: i32) void;
/// Draws an oval (or circle).
pub extern fn oval(x: u32, y: u32, width: u32, height: u32) void;
pub extern fn oval(x: i32, y: i32, width: u32, height: u32) void;
/// Draws a rectangle.
pub extern fn rect(x: u32, y: u32, width: u32, height: u32) void;
pub extern fn rect(x: i32, y: i32, width: u32, height: u32) void;
/// Draws text using the built-in system font.
pub fn text(str: []const u8, x: u32, y: u32) void {
pub fn text(str: []const u8, x: i32, y: i32) void {
textUtf8(str.ptr, str.len, x, y);
}
extern fn textUtf8(strPtr: [*]const u8, strLen: usize, x: u32, y: u32) void;
extern fn textUtf8(strPtr: [*]const u8, strLen: usize, x: i32, y: i32) void;
/// Draws a vertical line
pub extern fn vline(x: u32, y: u32, len: u32) void;