Add coins

master
Louis Pearson 2022-01-23 06:19:41 -07:00
parent 255eb30727
commit f60ec33b21
10 changed files with 270 additions and 58 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="60" height="60" tilewidth="8" tileheight="8" infinite="0" nextlayerid="4" nextobjectid="19">
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="60" height="60" tilewidth="8" tileheight="8" infinite="0" nextlayerid="4" nextobjectid="27">
<editorsettings>
<chunksize width="20" height="20"/>
<export target="map.json" format="json"/>
@ -47,10 +47,10 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,22,22,22,22,22,23,0,0,0,50,22,22,22,22,22,22,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,0,0,0,0,53,0,54,54,54,54,54,0,0,0,0,54,54,54,54,0,54,54,54,54,54,54,54,54,54,54,54,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,0,0,0,0,51,0,0,0,0,0,37,0,0,39,0,0,0,0,51,0,0,0,0,0,0,0,0,0,0,0,37,
0,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,0,0,0,39,0,0,0,0,3,0,0,0,0,0,37,0,0,39,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,37,
39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,22,22,22,22,22,22,52,0,0,0,37,0,0,39,0,0,0,50,19,19,19,19,19,19,19,19,19,19,19,19,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,0,0,0,0,53,0,54,54,54,54,54,0,0,0,0,54,54,54,54,0,54,54,54,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,0,0,0,0,51,0,0,0,0,0,37,0,0,39,0,0,0,0,51,0,0,0,37,0,0,0,0,0,0,0,0,
0,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,0,0,0,39,0,0,0,0,3,0,0,0,0,0,37,0,0,39,0,0,0,0,3,0,0,0,37,0,0,0,0,0,0,0,0,
39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,22,22,22,22,22,22,52,0,0,0,37,0,0,39,0,0,0,50,19,19,19,19,54,54,54,54,54,54,54,54,0,
39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,53,0,0,0,0,0,0,0,0,39,0,0,0,0,37,0,0,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
39,0,0,0,0,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,0,0,0,0,0,37,54,54,54,54,54,54,54,39,0,0,0,50,0,0,0,0,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
39,0,0,0,50,36,0,54,54,54,54,0,0,54,54,54,54,0,0,0,39,0,0,0,50,19,34,0,0,0,0,0,0,0,20,0,0,0,0,37,0,0,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
@ -59,13 +59,13 @@
39,0,0,0,0,37,39,0,0,0,0,33,19,52,0,0,0,37,0,0,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
39,0,0,0,50,54,55,0,0,0,0,0,0,0,0,0,0,37,0,0,0,19,19,52,4,17,19,19,19,19,19,52,4,21,22,22,22,22,0,0,0,0,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
39,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,50,36,0,0,39,0,0,0,0,20,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,39,0,0,0,50,22,22,22,22,22,22,22,22,22,22,22,22,0,
0,22,22,22,22,22,22,22,22,22,22,22,23,0,0,0,0,37,0,0,39,0,0,0,0,20,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,39,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,54,54,54,0,54,54,54,54,0,0,36,52,0,0,0,37,0,0,39,0,0,0,50,67,0,0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,52,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,
0,39,0,0,0,20,0,0,0,0,37,0,39,0,0,0,0,37,0,0,39,0,0,0,0,33,19,19,19,19,19,19,54,54,54,54,54,54,54,54,54,54,55,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,
0,39,0,0,0,53,19,52,0,0,37,0,39,0,0,0,50,36,0,0,0,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,54,54,54,54,54,54,54,54,54,54,54,54,0,
54,55,0,0,0,0,0,0,0,0,37,0,39,0,0,0,0,53,54,54,0,0,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
0,0,0,0,0,0,0,0,0,50,54,54,66,52,0,0,0,0,0,49,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,66,19,19,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,35,51,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,
0,22,22,22,22,22,22,22,22,22,22,22,23,0,0,0,0,37,0,0,39,0,0,0,0,20,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,39,0,0,0,0,37,0,0,0,0,0,0,54,54,54,0,0,0,
0,0,54,54,54,0,54,54,54,54,0,0,36,52,0,0,0,37,0,0,39,0,0,0,50,67,0,0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,52,0,0,0,37,0,0,0,0,0,39,0,0,0,37,0,0,
0,39,0,0,0,20,0,0,0,0,37,0,39,0,0,0,0,37,0,0,39,0,0,0,0,33,19,19,19,19,19,19,54,54,54,54,54,54,54,54,54,54,55,0,0,0,0,37,0,0,0,0,0,0,22,22,22,0,0,0,
0,39,0,0,0,53,19,52,0,0,37,0,39,0,0,0,50,36,0,0,0,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,54,54,54,54,54,54,54,0,54,54,54,54,0,
54,55,0,0,0,0,0,0,0,0,37,0,39,0,0,0,0,53,54,54,0,0,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,0,0,0,0,0,0,0,0,0,0,20,0,0,20,0,0,0,0,37,
0,0,0,0,0,0,0,0,0,50,54,54,66,52,0,0,0,0,0,49,53,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,66,19,19,52,0,0,0,0,0,50,19,34,0,0,51,0,0,0,0,37,
0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,35,51,35,0,0,0,0,0,0,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,37,
22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,0
</data>
</layer>
@ -118,18 +118,18 @@
27,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,27,0,0,0,0,0,0,27,0,0,0,0,0,0,
27,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,45,0,0,0,0,0,0,45,0,0,0,0,47,25,
27,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,40,26,26,25,0,0,0,0,0,0,0,0,0,0,0,40,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,
27,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45,0,0,0,0,0,0,0,0,0,0,0,24,60,26,26,26,26,26,25,0,0,0,0,0,0,0,0,0,0,0,27,
27,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,24,60,26,26,26,26,25,0,0,0,0,0,47,74,
27,0,0,0,0,0,0,0,0,0,47,26,41,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,0,0,44,0,0,0,0,0,0,0,0,27,0,0,0,0,0,40,46,0,0,0,0,45,0,0,0,0,0,47,74,
27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,0,0,0,0,0,40,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30,
27,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,
27,0,0,0,0,40,26,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,
27,0,0,0,0,24,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,60,26,26,26,26,26,26,26,26,25,0,0,0,0,0,0,0,0,27,
40,26,46,0,47,41,29,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,27,
0,0,0,0,0,0,40,26,26,26,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,27,
0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,27,
0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,24,60,25,0,0,0,0,0,0,0,27,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,30,0,28,0,0,0,0,0,0,0,27,
27,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45,0,0,0,0,0,0,0,0,0,0,0,24,60,26,26,26,26,26,72,26,26,26,26,26,26,26,25,0,0,0,27,
27,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,24,60,26,26,26,26,25,0,0,27,0,0,47,74,
27,0,0,0,0,0,0,0,0,0,47,26,41,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,0,0,44,0,0,0,0,0,0,0,0,27,0,0,0,0,0,40,46,0,0,0,0,45,0,0,27,0,0,47,74,
27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,0,0,0,0,0,40,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,30,
27,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,27,
27,0,0,0,0,40,26,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,25,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,27,
27,0,0,0,0,24,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,60,26,26,26,26,26,26,26,26,25,0,0,0,44,27,44,0,0,27,
40,26,46,0,47,41,29,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,24,60,25,0,0,27,27,27,0,0,27,
0,0,0,0,0,0,40,26,26,26,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,27,0,27,24,26,60,41,27,0,0,27,
0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,27,0,31,41,0,24,26,41,0,0,27,
0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,27,0,27,0,0,27,0,0,0,0,27,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,31,0,27,0,0,0,0,0,0,0,27,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,26,26,26,26,26,26,26,26,73,26,73,26,26,26,26,26,26,26,73
</data>
</layer>
@ -198,5 +198,17 @@
<object id="18" type="door" x="380" y="340">
<point/>
</object>
<object id="26" type="door" x="436" y="470">
<point/>
</object>
<object id="19" type="coin" gid="5" x="216" y="424" width="8" height="8"/>
<object id="20" type="coin" gid="5" x="296" y="472" width="8" height="8"/>
<object id="21" type="coin" gid="5" x="392" y="344" width="8" height="8"/>
<object id="22" type="coin" gid="5" x="120" y="472" width="8" height="8"/>
<object id="23" type="coin" gid="5" x="16" y="416" width="8" height="8"/>
<object id="24" type="coin" gid="5" x="456" y="472" width="8" height="8"/>
<object id="25" type="wire" x="452" y="428">
<polyline points="0,0 -16,0"/>
</object>
</objectgroup>
</map>

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 B

After

Width:  |  Height:  |  Size: 711 B

File diff suppressed because one or more lines are too long

View File

@ -15,12 +15,13 @@ const Point = struct {
const Object = struct {
height: f64 = 0,
id: u64 = 0,
gid: u64 = 0,
name: []const u8,
point: bool = false,
polyline: []Point = &.{},
properties: []Property = &.{},
rotation: f64 = 0,
@"type": enum { wire, source, door, spawn, focus },
@"type": enum { wire, source, door, spawn, focus, coin },
visible: bool = true,
width: f64 = 0,
x: f64 = 0,
@ -62,7 +63,7 @@ const MapType = struct {
};
const KB = 1024;
var heap: [128 * KB]u8 = undefined;
var heap: [256 * KB]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&heap);
var alloc = fba.allocator();
var verbose = true;
@ -94,7 +95,7 @@ pub fn do() !void {
while (try argsIter.next(alloc)) |arg| {
defer alloc.free(arg);
if (verbose) std.log.info("{s}", .{arg});
var filebuffer: [32 * KB]u8 = undefined;
var filebuffer: [64 * KB]u8 = undefined;
var filecontents = try cwd.readFile(arg, &filebuffer);
@setEvalBranchQuota(10000);
@ -129,6 +130,9 @@ pub fn do() !void {
var doorlist = std.ArrayList(Object).init(alloc);
defer doorlist.deinit();
var coinlist = std.ArrayList(Object).init(alloc);
defer coinlist.deinit();
var sourcelist = std.ArrayList(Object).init(alloc);
defer sourcelist.deinit();
@ -139,6 +143,7 @@ pub fn do() !void {
switch (obj.@"type") {
.wire => try wirelist.append(obj),
.door => try doorlist.append(obj),
.coin => try coinlist.append(obj),
.source => try sourcelist.append(obj),
.focus => try focilist.append(obj),
.spawn => try appendSpawn(&outlist, obj),
@ -147,6 +152,7 @@ pub fn do() !void {
try appendWires(&outlist, wirelist);
try appendDoors(&outlist, doorlist);
try appendCoins(&outlist, coinlist);
try appendSources(&outlist, sourcelist);
try appendFoci(&outlist, focilist);
},
@ -205,12 +211,24 @@ pub fn appendSources(outlist: *std.ArrayList(u8), sourcelist: std.ArrayList(Obje
try outlist.appendSlice("};\n");
}
pub fn appendFoci(outlist: *std.ArrayList(u8), sourcelist: std.ArrayList(Object)) !void {
pub fn appendCoins(outlist: *std.ArrayList(u8), coinlist: std.ArrayList(Object)) !void {
var outbuffer: [4 * KB]u8 = undefined;
var outcontent = try std.fmt.bufPrint(&outbuffer, "pub const focus: [{}]AABB = [_]AABB{{", .{sourcelist.items.len});
var outcontent = try std.fmt.bufPrint(&outbuffer, "pub const coins: [{}]Vec2 = [_]Vec2{{", .{coinlist.items.len});
try outlist.appendSlice(outcontent);
for (sourcelist.items) |obj| {
for (coinlist.items) |obj| {
var sourcef = try std.fmt.bufPrint(&outbuffer, "Vec2{{ {}, {} }},", .{ @floatToInt(i32, @divTrunc(obj.x, 8)), @floatToInt(i32, @divTrunc(obj.y - 8, 8)) });
try outlist.appendSlice(sourcef);
}
try outlist.appendSlice("};\n");
}
pub fn appendFoci(outlist: *std.ArrayList(u8), focilist: std.ArrayList(Object)) !void {
var outbuffer: [4 * KB]u8 = undefined;
var outcontent = try std.fmt.bufPrint(&outbuffer, "pub const focus: [{}]AABB = [_]AABB{{", .{focilist.items.len});
try outlist.appendSlice(outcontent);
for (focilist.items) |obj| {
var sourcef = try std.fmt.bufPrint(
&outbuffer,
"AABB{{ .pos = Vec2{{ {}, {} }}, .size = Vec2{{ {}, {} }} }}",

View File

@ -134,6 +134,8 @@ fn get_outputs(tile: u8) Current {
46 => .{ false, true, false, false },
// Switch
27, 29 => .{ true, false, true, false },
28 => .{ false, false, false, true },
30 => .{ false, true, false, false },
// Logic
// Calculated in fill
// 59 => .{ false, false, false, false },

View File

@ -101,6 +101,10 @@ const ParticleSystem = struct {
var physics = .{ .gravity = Vec2f{ 0, 0.1 }, .friction = Vec2f{ 0.1, 0.1 } };
var remove = std.BoundedArray(usize, MAXPARTICLES).init(0) catch unreachable;
for (this.particles.slice()) |*part, i| {
if (!inView(part.pos.pos)) {
remove.append(i) catch unreachable;
continue;
}
velocityProcess(1, &part.pos);
physicsProcess(1, &part.pos, &physics);
part.life -= 1;
@ -135,6 +139,13 @@ const ParticleSystem = struct {
}
};
fn inView(vec: Vec2f) bool {
return @reduce(
.And,
@divTrunc(util.world2cell(vec), @splat(2, @as(i32, 20))) * @splat(2, @as(i32, 20)) == camera,
);
}
fn randRange(min: i32, max: i32) i32 {
return random.intRangeLessThanBiased(i32, min, max);
}
@ -158,6 +169,9 @@ var player: Player = undefined;
var music = Music.Procedural.init(.C3, &Music.Minor, 83);
var wires = std.BoundedArray(Wire, 10).init(0) catch unreachable;
var camera = Vec2{ 0, 0 };
const Coin = struct { pos: Pos, sprite: Sprite, anim: Anim, area: AABB };
var coins = std.BoundedArray(Coin, 10).init(0) catch unreachable;
var score: u8 = 0;
const anim_store = struct {
const stand = Anim.frame(8);
@ -165,6 +179,7 @@ const anim_store = struct {
const jump = Anim.frame(13);
const fall = Anim.frame(14);
const wallSlide = Anim.frame(15);
const coin = Anim.simple(15, &[_]usize{ 4, 5, 6 });
};
const AnimData = []const Anim.Ops;
@ -207,6 +222,15 @@ export fn start() void {
.kinematic = .{ .col = .{ .pos = .{ -3, -6 }, .size = .{ 5, 5 } } },
};
for (assets.coins) |coin| {
coins.append(.{
.pos = Pos.init(util.vec2ToVec2f(coin * tile_size)),
.sprite = .{ .offset = .{ 0, 0 }, .size = .{ 8, 8 }, .index = 4, .flags = .{ .bpp = .b2 } },
.anim = Anim{ .anim = &anim_store.coin },
.area = .{ .pos = .{ 0, 0 }, .size = .{ 8, 8 } },
}) catch unreachable;
}
for (assets.wire) |wire| {
const begin = vec2tovec2f(wire.p1);
const end = vec2tovec2f(wire.p2);
@ -263,6 +287,29 @@ export fn update() void {
w4.rect(.{ 0, 0 }, .{ 160, 160 });
drawProcess(1, &player.pos, &player.sprite);
{
var remove = std.BoundedArray(usize, 10).init(0) catch unreachable;
for (coins.slice()) |*coin, i| {
staticAnimProcess(1, &coin.sprite, &coin.anim);
drawProcess(1, &coin.pos, &coin.sprite);
if (coin.area.addv(coin.pos.pos).overlaps(player.kinematic.col.addv(player.pos.pos))) {
score += 1;
remove.append(i) catch unreachable;
music.playCollect(score);
}
}
while (remove.popOrNull()) |i| {
_ = coins.swapRemove(i);
}
// if (score < 3) {
// music.newIntensity = .calm;
// } else if (score < 6) {
// music.newIntensity = .active;
// } else {
// music.newIntensity = .danger;
// }
}
camera = @divTrunc(util.world2cell(player.pos.pos), @splat(2, @as(i32, 20))) * @splat(2, @as(i32, 20));
map.draw(camera);
@ -310,6 +357,21 @@ export fn update() void {
}
}
// Score UI
{
const playerPos = util.vec2fToVec2(player.pos.pos) - camera * Map.tile_size;
// w4.tracef("%d, %d", playerPos[0], playerPos[1]);
const scoreY: u8 = if (playerPos[1] > 80) 0 else 152;
const scoreX: u8 = if (playerPos[0] > 80) 0 else 160 - 64;
w4.DRAW_COLORS.* = 0x0004;
w4.rect(Vec2{ scoreX, scoreY }, Vec2{ 64, 8 });
w4.DRAW_COLORS.* = 0x0042;
w4.text("Score", Vec2{ scoreX, scoreY });
var scoreDigits = [2]u8{ '0', '0' };
scoreDigits[1] = '0' + score;
w4.text(&scoreDigits, Vec2{ scoreX + 48, scoreY });
}
// Music
const musicCommand = music.getNext(1);
for (musicCommand.constSlice()) |sfx| {
@ -418,14 +480,7 @@ fn updateCircuit() void {
circuit.bridge(.{ cellBegin, cellEnd }, wireID);
}
var count = circuit.fill();
if (count < 30) {
music.newIntensity = .calm;
} else if (count < 60) {
music.newIntensity = .active;
} else {
music.newIntensity = .danger;
}
_ = circuit.fill();
for (wires.slice()) |*wire| {
const begin = wire.begin();
const end = wire.end();
@ -514,7 +569,7 @@ fn vec2ftovec2(vec2f: Vec2f) w4.Vec2 {
}
fn drawProcess(_: f32, pos: *Pos, sprite: *Sprite) void {
w4.DRAW_COLORS.* = 0x0010;
w4.DRAW_COLORS.* = 0x2210;
const fpos = pos.pos + sprite.offset;
const ipos = w4.Vec2{ @floatToInt(i32, fpos[0]), @floatToInt(i32, fpos[1]) } - camera * Map.tile_size;
const index = sprite.index;

View File

@ -53,6 +53,7 @@ pub const Procedural = struct {
walking: bool = false,
intensity: Intensity = .calm,
newIntensity: ?Intensity = null,
collect: ?struct { score: u8, start: usize, end: usize } = null,
pub fn init(root: Note, scale: []const usize, seed: usize) @This() {
return @This(){
@ -84,6 +85,12 @@ pub const Procedural = struct {
};
}
pub fn playCollect(this: *@This(), score: u8) void {
const beatTotal = @divTrunc(this.tick, this.beat);
const length: u8 = if (score > 3) 2 else 1;
this.collect = .{ .score = score, .start = beatTotal + 1, .end = beatTotal + (this.beatsPerBar * length) + 1 };
}
pub fn getNext(this: *@This(), dt: u32) MusicCommand {
var cmd = MusicCommand.init(0) catch unreachable;
const beatProgress = this.tick % this.beat;
@ -92,16 +99,22 @@ pub const Procedural = struct {
const bar = @divTrunc(beatTotal, this.beatsPerBar);
this.tick += dt;
if (beat == 0) this.intensity = this.newIntensity orelse this.intensity;
const playNote = beat % 2 == 0 and bar % 4 < 2;
if (this.intensity.atLeast(.active) and playNote and beatProgress == 0) {
// const notelen = @intCast(u8, this.beat * this.beatsPerBar);
cmd.append(Sfx{
.freq = .{ .start = this.nextNote(this.note) },
.duration = .{ .sustain = 5, .release = 5 },
.volume = 5,
.flags = .{ .channel = .pulse2, .mode = .p25 },
}) catch unreachable;
this.note += 1;
if (this.collect) |collect| {
const playNote = if (collect.score < 6) beat % 2 == 0 else beat % 4 != 3;
if (beatTotal >= collect.start and beatTotal < collect.end and playNote and beatProgress == 0) {
// const notelen = @intCast(u8, this.beat * this.beatsPerBar);
cmd.append(Sfx{
.freq = .{ .start = this.nextNote(this.note) },
.duration = .{ .sustain = 5, .release = 5 },
.volume = 25,
.flags = .{ .channel = .pulse2, .mode = .p25 },
}) catch unreachable;
this.note += 1;
}
if (bar > collect.end) {
w4.tracef("end collect");
this.collect = null;
}
}
if (this.intensity.atLeast(.calm) and beat == 0 and beatProgress == 0) cmd.append(.{
.freq = .{ .start = 220, .end = 110 },
@ -118,7 +131,7 @@ pub const Procedural = struct {
if (this.walking and beat % 3 == 1 and beatProgress == 7) cmd.append(.{
.freq = .{ .start = 1761, .end = 1 },
.duration = .{ .release = 5 },
.volume = 5,
.volume = 25,
.flags = .{ .channel = .noise },
}) catch unreachable;
return cmd;

View File

@ -55,6 +55,13 @@ pub const AABB = struct {
pub fn addv(this: @This(), vec2f: Vec2f) @This() {
return @This(){ .pos = this.pos + vec2f, .size = this.size };
}
pub fn overlaps(a: @This(), b: @This()) bool {
return a.pos[0] < b.pos[0] + b.size[0] and
a.pos[0] + a.size[0] > b.pos[0] and
a.pos[1] < b.pos[1] + b.size[1] and
a.pos[1] + a.size[1] > b.pos[1];
}
};
pub fn Queue(comptime T: type, len: usize) type {