it's broken but getting help lol

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-07-01 15:08:30 -04:00
parent 20a215518c
commit dcd924cec0
11 changed files with 246 additions and 17 deletions

View File

@ -2,11 +2,18 @@ const std = @import("std");
pub fn mapgen(b: *std.build.Step) !void { pub fn mapgen(b: *std.build.Step) !void {
_ = b; _ = b;
var alloc = std.heap.page_allocator; var alloc = std.heap.page_allocator;
var deno = std.ChildProcess.init(&.{"deno", "run", "-A", "./src/tools/genmap.js", "./maps/TestMap.json", "./src/maps/testmap.zig"}, alloc);
const maps = [_][2][]const u8{
[2][]const u8{"./maps/TestMap.json", "./src/maps/test.zig"},
[2][]const u8{"./maps/RPGmap.json", "./src/maps/rpg.zig"},
};
for (&maps) |map| {
var deno = std.ChildProcess.init(&.{"deno", "run", "-A", "./src/tools/genmap.js", map[0], map[1]}, alloc);
try deno.spawn(); try deno.spawn();
_ = try deno.wait(); _ = try deno.wait();
}
} }
pub fn build(b: *std.build.Builder) !void { pub fn build(b: *std.build.Builder) !void {
@ -15,7 +22,7 @@ pub fn build(b: *std.build.Builder) !void {
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned); const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned);
lib.step.dependOn(map_step); //lib.step.dependOn(map_step);
lib.setBuildMode(mode); lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });

150
maps/RPGmap.json Normal file
View File

@ -0,0 +1,150 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"format":"json",
"target":"RPGmap.json"
}
},
"height":10,
"infinite":false,
"layers":[
{
"data":[1, 1, 1, 1, 1, 19, 20, 21, 1, 1, 1, 1, 1, 1, 1, 36, 53, 38, 1, 1, 1, 1, 1, 1, 86, 88, 104, 1, 1, 17, 1, 1, 1, 1, 105, 1, 1, 1, 1, 1, 1, 1, 1, 1, 105, 1, 1, 1, 81, 1, 1, 1, 1, 1, 105, 67, 66, 97, 98, 99, 1, 68, 1, 1, 105, 66, 67, 114, 115, 116, 1, 103, 88, 88, 106, 1, 1, 100, 118, 101, 1, 1, 1, 1, 103, 88, 88, 88, 107, 88, 11, 13, 1, 12, 1, 1, 1, 1, 1, 1],
"height":10,
"id":1,
"name":"map",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":10,
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"coll",
"objects":[
{
"height":16.4511859920595,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":47.3989616206862,
"x":80.301333604805,
"y":-0.325766059248702
},
{
"height":15.4738878143134,
"id":4,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":15.6367708439377,
"x":15.9625369031864,
"y":95.7752214191184
},
{
"height":32.0879568359971,
"id":5,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":80.1384505751807,
"x":80.1384505751807,
"y":79.812684515932
},
{
"height":9.44721571821236,
"id":6,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":16.2883029624351,
"x":127.863178255116,
"y":70.3654687977196
},
{
"height":16.1254199328107,
"id":8,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":15.6367708439377,
"x":143.988598187926,
"y":31.7621907767484
},
{
"height":15.5,
"id":10,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":14.875,
"x":112,
"y":112
},
{
"height":16.125,
"id":11,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":15.25,
"x":144.875,
"y":111.625
},
{
"height":15.375,
"id":13,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":15,
"x":79.875,
"y":16.125
},
{
"height":15.625,
"id":14,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":13.875,
"x":113.875,
"y":16.375
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":15,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.3",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"source":"..\/sprites\/kenney_rpg.tsx"
}],
"tilewidth":16,
"type":"map",
"version":1.4,
"width":10
}

32
maps/RPGmap.tmx Normal file
View File

@ -0,0 +1,32 @@
<?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="3" nextobjectid="15">
<editorsettings>
<export target="RPGmap.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../sprites/kenney_rpg.tsx"/>
<layer id="1" name="map" width="10" height="10">
<data encoding="csv">
1,1,1,1,1,19,20,21,1,1,
1,1,1,1,1,36,53,38,1,1,
1,1,1,1,86,88,104,1,1,17,
1,1,1,1,105,1,1,1,1,1,
1,1,1,1,105,1,1,1,81,1,
1,1,1,1,105,67,66,97,98,99,
1,68,1,1,105,66,67,114,115,116,
1,103,88,88,106,1,1,100,118,101,
1,1,1,1,103,88,88,88,107,88,
11,13,1,12,1,1,1,1,1,1
</data>
</layer>
<objectgroup id="2" name="coll">
<object id="1" x="80.3013" y="-0.325766" width="47.399" height="16.4512"/>
<object id="4" x="15.9625" y="95.7752" width="15.6368" height="15.4739"/>
<object id="5" x="80.1385" y="79.8127" width="80.1385" height="32.088"/>
<object id="6" x="127.863" y="70.3655" width="16.2883" height="9.44722"/>
<object id="8" x="143.989" y="31.7622" width="15.6368" height="16.1254"/>
<object id="10" x="112" y="112" width="14.875" height="15.5"/>
<object id="11" x="144.875" y="111.625" width="15.25" height="16.125"/>
<object id="13" x="79.875" y="16.125" width="15" height="15.375"/>
<object id="14" x="113.875" y="16.375" width="13.875" height="15.625"/>
</objectgroup>
</map>

View File

@ -1,6 +1,7 @@
if not exist "dist" mkdir "dist" if not exist "dist" mkdir "dist"
del /q /f "dist\*.*" del /q /f "dist\*.*"
git checkout dist/.gitignore git checkout dist/.gitignore
zig build mapgen
zig build -Drelease-small=true zig build -Drelease-small=true
wasm-opt -Oz --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm wasm-opt -Oz --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm
wasm-strip ./dist/tamamo.wasm wasm-strip ./dist/tamamo.wasm

View File

@ -4,6 +4,7 @@ set -ex
mkdir -p dist mkdir -p dist
rm -rf dist/* rm -rf dist/*
zig build mapgen
zig build -Drelease-small=true zig build -Drelease-small=true
wasm-opt -Oz --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm wasm-opt -Oz --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm
wasm-strip ./dist/tamamo.wasm wasm-strip ./dist/tamamo.wasm

BIN
sprites/kenney_rpg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

4
sprites/kenney_rpg.tsx Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.4" tiledversion="1.4.3" name="kenney_rpg" tilewidth="16" tileheight="16" tilecount="136" columns="17">
<image source="kenney_rpg.png" width="272" height="128"/>
</tileset>

View File

@ -22,7 +22,7 @@ export fn start() void {
palette.mist(); palette.mist();
} }
const map = @import("./maps/testmap.zig"); const map = @import("./maps/rpg.zig");
fn bonk() void { fn bonk() void {
if (sound_timer != 0) { if (sound_timer != 0) {
@ -59,18 +59,20 @@ fn drawMap() !void {
}; };
for (map.data) |tile, i| { for (map.data) |tile, i| {
var x: u32 = i % 10; const width = sprites.kenney_rpg_width / 16;
var y: u32 = i / 10; const height = sprites.kenney_rpg_width / 16;
var x: u32 = (i % width) * 16;
var y: u32 = (i / height) * 16;
w4.blitSub( w4.blitSub(
&sprites.Cave, &sprites.kenney_rpg,
x * 16, x,
y * 16, y,
16, 16,
16, 16,
@intCast(u32, tile.x) * 16, @intCast(u32, tile.x) * 16,
@intCast(u32, tile.y) * 16, @intCast(u32, tile.y) * 16,
sprites.Cave_width, sprites.kenney_rpg_width,
w4.BlitFlags{.two_bits = true}, w4.BlitFlags{.two_bits = true},
); );
} }

32
src/maps/rpg.zig Normal file
View File

@ -0,0 +1,32 @@
// Generated by genmap.js, DO NOT EDIT
const sh0rk = @import("../sh0rk.zig");
const Point = sh0rk.Point;
const Rect = sh0rk.Rect;
const Tile = sh0rk.Tile;
pub const data = [100]Tile{
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 8, .y = 1}, Tile{.x = 9, .y = 1}, Tile{.x = 0, .y = 2}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0},
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 5, .y = 3}, Tile{.x = 2, .y = 5}, Tile{.x = 7, .y = 3}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0},
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 5, .y = 8}, Tile{.x = 7, .y = 8}, Tile{.x = 3, .y = 10}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 6, .y = 1}, Tile{.x = 0, .y = 0},
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 4, .y = 10}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0},
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 4, .y = 10}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 8}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0},
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 4, .y = 10}, Tile{.x = 6, .y = 6}, Tile{.x = 5, .y = 6}, Tile{.x = 6, .y = 9}, Tile{.x = 7, .y = 9}, Tile{.x = 8, .y = 9}, Tile{.x = 0, .y = 0},
Tile{.x = 7, .y = 6}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 4, .y = 10}, Tile{.x = 5, .y = 6}, Tile{.x = 6, .y = 6}, Tile{.x = 3, .y = 11}, Tile{.x = 4, .y = 11}, Tile{.x = 5, .y = 11}, Tile{.x = 0, .y = 0},
Tile{.x = 2, .y = 10}, Tile{.x = 7, .y = 8}, Tile{.x = 7, .y = 8}, Tile{.x = 5, .y = 10}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 9, .y = 9}, Tile{.x = 7, .y = 11}, Tile{.x = 0, .y = 10}, Tile{.x = 0, .y = 0},
Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 2, .y = 10}, Tile{.x = 7, .y = 8}, Tile{.x = 7, .y = 8}, Tile{.x = 7, .y = 8}, Tile{.x = 6, .y = 10}, Tile{.x = 7, .y = 8}, Tile{.x = 0, .y = 1},
Tile{.x = 2, .y = 1}, Tile{.x = 0, .y = 0}, Tile{.x = 1, .y = 1}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0}, Tile{.x = 0, .y = 0},
};
pub const coll = [9]Rect{
Rect{.base = Point{.x = 80, .y = 0}, .width = 47, .height = 16},
Rect{.base = Point{.x = 16, .y = 96}, .width = 16, .height = 15},
Rect{.base = Point{.x = 80, .y = 80}, .width = 80, .height = 32},
Rect{.base = Point{.x = 128, .y = 70}, .width = 16, .height = 9},
Rect{.base = Point{.x = 144, .y = 32}, .width = 16, .height = 16},
Rect{.base = Point{.x = 112, .y = 112}, .width = 15, .height = 16},
Rect{.base = Point{.x = 145, .y = 112}, .width = 15, .height = 16},
Rect{.base = Point{.x = 80, .y = 16}, .width = 15, .height = 15},
Rect{.base = Point{.x = 114, .y = 16}, .width = 14, .height = 16},
};

File diff suppressed because one or more lines are too long