add collission map support
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
3c55e17626
commit
e1feccb8f9
|
@ -21,9 +21,42 @@
|
||||||
"width":10,
|
"width":10,
|
||||||
"x":0,
|
"x":0,
|
||||||
"y":0
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"draworder":"topdown",
|
||||||
|
"id":2,
|
||||||
|
"name":"coll",
|
||||||
|
"objects":[
|
||||||
|
{
|
||||||
|
"height":80,
|
||||||
|
"id":3,
|
||||||
|
"name":"",
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":160,
|
||||||
|
"x":0,
|
||||||
|
"y":80
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"height":32,
|
||||||
|
"id":4,
|
||||||
|
"name":"",
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":16,
|
||||||
|
"x":80,
|
||||||
|
"y":48
|
||||||
}],
|
}],
|
||||||
"nextlayerid":2,
|
"opacity":1,
|
||||||
"nextobjectid":1,
|
"type":"objectgroup",
|
||||||
|
"visible":true,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"nextlayerid":3,
|
||||||
|
"nextobjectid":5,
|
||||||
"orientation":"orthogonal",
|
"orientation":"orthogonal",
|
||||||
"renderorder":"right-down",
|
"renderorder":"right-down",
|
||||||
"tiledversion":"1.4.3",
|
"tiledversion":"1.4.3",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="2" nextobjectid="1">
|
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="5">
|
||||||
<editorsettings>
|
<editorsettings>
|
||||||
<export target="TestMap.json" format="json"/>
|
<export target="TestMap.json" format="json"/>
|
||||||
</editorsettings>
|
</editorsettings>
|
||||||
|
@ -18,4 +18,8 @@
|
||||||
6,50,50,50,22,50,50,50,42,50
|
6,50,50,50,22,50,50,50,42,50
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
|
<objectgroup id="2" name="coll">
|
||||||
|
<object id="3" x="0" y="80" width="160" height="80"/>
|
||||||
|
<object id="4" x="80" y="48" width="16" height="32"/>
|
||||||
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
if not exist "dist" mkdir "dist"
|
||||||
|
del /q /f "dist\*.*"
|
||||||
|
git checkout dist/.gitignore
|
||||||
|
zig build -Drelease-small=true
|
||||||
|
wasm-opt -Oz --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm
|
||||||
|
wasm-strip ./dist/tamamo.wasm
|
||||||
|
|
||||||
|
w4 bundle --windows ./dist/tamamo.exe --mac ./dist/tamamo.macOS --linux ./dist/tamamo.linux --title "Mara 2" --description "Tamamo-no-Mae's Fury" --html ./dist/tamamo.html --timestamp --html-disk-prefix "mara-2" ./dist/tamamo.wasm
|
|
@ -13,7 +13,7 @@ w4 bundle \
|
||||||
--linux ./dist/tamamo.linux \
|
--linux ./dist/tamamo.linux \
|
||||||
--title "Mara 2" \
|
--title "Mara 2" \
|
||||||
--description "Tamamo-no-Mae's Fury" \
|
--description "Tamamo-no-Mae's Fury" \
|
||||||
--html ./dist/web \
|
--html ./dist/tamamo.html \
|
||||||
--timestamp \
|
--timestamp \
|
||||||
--html-disk-prefix "mara-2" \
|
--html-disk-prefix "mara-2" \
|
||||||
./dist/tamamo.wasm
|
./dist/tamamo.wasm
|
11
src/main.zig
11
src/main.zig
|
@ -20,7 +20,7 @@ export fn start() void {
|
||||||
palette.mist();
|
palette.mist();
|
||||||
}
|
}
|
||||||
|
|
||||||
const map = @import("./maps/testmap.zig").map;
|
const map = @import("./maps/testmap.zig");
|
||||||
|
|
||||||
fn drawMap() !void {
|
fn drawMap() !void {
|
||||||
w4.m.colors.* = .{
|
w4.m.colors.* = .{
|
||||||
|
@ -30,7 +30,7 @@ fn drawMap() !void {
|
||||||
._3 = .p3,
|
._3 = .p3,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (map) |tile, i| {
|
for (map.data) |tile, i| {
|
||||||
var x: u32 = i % 10;
|
var x: u32 = i % 10;
|
||||||
var y: u32 = i / 10;
|
var y: u32 = i / 10;
|
||||||
|
|
||||||
|
@ -92,6 +92,13 @@ export fn update() void {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (map.coll) |box| {
|
||||||
|
if (mara_box.collides(box)) {
|
||||||
|
w4.trace("boncc");
|
||||||
|
mara_speed = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mara_box.base.x < 0) {
|
if (mara_box.base.x < 0) {
|
||||||
mara_box.base.x = 0;
|
mara_box.base.x = 0;
|
||||||
} else if (mara_box.base.x > 160 - mara_box.width) {
|
} else if (mara_box.base.x > 160 - mara_box.width) {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
const Tile = @import("../sh0rk.zig").Tile;
|
const sh0rk = @import("../sh0rk.zig");
|
||||||
|
const Point = sh0rk.Point;
|
||||||
|
const Rect = sh0rk.Rect;
|
||||||
|
const Tile = sh0rk.Tile;
|
||||||
|
|
||||||
pub const map = [100]Tile{
|
pub const data = [100]Tile{
|
||||||
Tile{.x = 8, .y = 2},
|
Tile{.x = 8, .y = 2},
|
||||||
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
|
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
|
||||||
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
|
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
|
||||||
|
@ -13,3 +16,8 @@ pub const map = [100]Tile{
|
||||||
Tile{.x = 0, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 5, .y = 0},
|
Tile{.x = 0, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 5, .y = 0},
|
||||||
Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 4}, Tile{.x = 9, .y = 4},
|
Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 4}, Tile{.x = 9, .y = 4},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const coll = [2]Rect{
|
||||||
|
Rect{.base = Point{.x = 0, .y = 80}, .width = 160, .height = 80}, Rect{.base = Point{.x = 80, .y = 48}, .width = 16, .height = 32},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,43 @@ var out = "";
|
||||||
const data = await Deno.readTextFile(mapFile);
|
const data = await Deno.readTextFile(mapFile);
|
||||||
const map = JSON.parse(data);
|
const map = JSON.parse(data);
|
||||||
|
|
||||||
let layer = map.layers[0];
|
|
||||||
|
|
||||||
out += `const Tile = @import("../sh0rk.zig").Tile;\n\n`;
|
out += `const sh0rk = @import("../sh0rk.zig");\n`;
|
||||||
|
|
||||||
out += `pub const map = [${layer.data.length}]Tile{\n `;
|
out += `const Point = sh0rk.Point;\n`;
|
||||||
|
out += `const Rect = sh0rk.Rect;\n`;
|
||||||
|
out += `const Tile = sh0rk.Tile;\n\n`;
|
||||||
|
|
||||||
layer.data.forEach((tile, index) => {
|
let tiles = map.layers[0];
|
||||||
|
out += `pub const data = [${tiles.data.length}]Tile{\n `;
|
||||||
|
|
||||||
|
tiles.data.forEach((tile, index) => {
|
||||||
tile -= 1;
|
tile -= 1;
|
||||||
const tileY = Math.trunc(tile / layer.height);
|
const tileY = Math.trunc(tile / tiles.height);
|
||||||
const tileX = tile % layer.width;
|
const tileX = tile % tiles.width;
|
||||||
out += ` Tile{.x = ${tileX}, .y = ${tileY}},`;
|
out += ` Tile{.x = ${tileX}, .y = ${tileY}},`;
|
||||||
if (index % 10 === 0) {
|
if (index % 10 === 0) {
|
||||||
out += "\n ";
|
out += "\n ";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
out += "\n};\n";
|
out += "\n};\n\n";
|
||||||
|
|
||||||
|
if (map.layers.length >= 2) {
|
||||||
|
let coll = map.layers[1];
|
||||||
|
|
||||||
|
out += `pub const coll = [${coll.objects.length}]Rect{\n `;
|
||||||
|
|
||||||
|
coll.objects.forEach(obj => {
|
||||||
|
const x = Math.round(obj.x);
|
||||||
|
const y = Math.round(obj.y);
|
||||||
|
const width = Math.round(obj.width);
|
||||||
|
const height = Math.round(obj.height);
|
||||||
|
|
||||||
|
out += ` Rect{.base = Point{.x = ${x}, .y = ${y}}, .width = ${width}, .height = ${height}},`;
|
||||||
|
});
|
||||||
|
|
||||||
|
out += "\n};\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
await Deno.writeTextFile(outFname, out);
|
await Deno.writeTextFile(outFname, out);
|
||||||
|
|
Loading…
Reference in New Issue