attempt to do some map drawing, and oh god it works

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-07-01 13:11:52 -04:00
parent e157638405
commit fa3824f09f
9 changed files with 257 additions and 18 deletions

40
maps/TestMap.json Normal file
View File

@ -0,0 +1,40 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"format":"json",
"target":"TestMap.json"
}
},
"height":10,
"infinite":false,
"layers":[
{
"data":[29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 18, 29, 29, 29, 29, 29, 29, 29, 29, 29, 38, 29, 29, 29, 29, 1, 2, 3, 4, 2, 48, 4, 2, 3, 4, 6, 50, 50, 50, 50, 50, 50, 22, 50, 23, 16, 22, 50, 23, 50, 43, 50, 50, 50, 50, 26, 41, 50, 50, 50, 50, 50, 22, 50, 50, 6, 50, 50, 50, 22, 50, 50, 50, 42, 50],
"height":10,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":10,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.3",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"source":"..\/sprites\/Cave.tsx"
}],
"tilewidth":16,
"type":"map",
"version":1.4,
"width":10
}

21
maps/TestMap.tmx Normal file
View File

@ -0,0 +1,21 @@
<?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">
<editorsettings>
<export target="TestMap.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../sprites/Cave.tsx"/>
<layer id="1" name="Tile Layer 1" width="10" height="10">
<data encoding="csv">
29,29,29,29,29,29,29,29,29,29,
29,29,29,29,29,29,29,29,29,29,
29,29,29,29,29,29,29,29,29,29,
29,29,29,29,29,18,29,29,29,29,
29,29,29,29,29,38,29,29,29,29,
1,2,3,4,2,48,4,2,3,4,
6,50,50,50,50,50,50,22,50,23,
16,22,50,23,50,43,50,50,50,50,
26,41,50,50,50,50,50,22,50,50,
6,50,50,50,22,50,50,50,42,50
</data>
</layer>
</map>

BIN
sprites/Cave.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

4
sprites/Cave.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="Cave" tilewidth="16" tileheight="16" tilecount="50" columns="10">
<image source="Cave.png" width="160" height="80"/>
</tileset>

Binary file not shown.

BIN
sprites/testmap.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

View File

@ -14,14 +14,153 @@ var mara_box: Rect = Rect{.base = Point{.x = 20, .y = 40}, .width = 16, .height
var mara_speed: i32 = 0; var mara_speed: i32 = 0;
var screen = Rect{.base = Point{.x = 0, .y = 0}, .width = 160, .height = 160}; var screen = Rect{.base = Point{.x = 0, .y = 0}, .width = 160, .height = 160};
var textBuf: [160]u8 = undefined;
export fn start() void { export fn start() void {
palette.mist(); palette.mist();
} }
const Tile = packed struct {
x: u4,
y: u4,
};
pub const map = [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 = 7, .y = 1},
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 = 7, .y = 3},
Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2},
Tile{.x = 0, .y = 0},
Tile{.x = 1, .y = 0},
Tile{.x = 2, .y = 0},
Tile{.x = 3, .y = 0},
Tile{.x = 1, .y = 0},
Tile{.x = 7, .y = 4},
Tile{.x = 3, .y = 0},
Tile{.x = 1, .y = 0},
Tile{.x = 2, .y = 0},
Tile{.x = 3, .y = 0},
Tile{.x = 5, .y = 0},
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 = 9, .y = 4},
Tile{.x = 1, .y = 2},
Tile{.x = 9, .y = 4},
Tile{.x = 2, .y = 2},
Tile{.x = 5, .y = 1},
Tile{.x = 1, .y = 2},
Tile{.x = 9, .y = 4},
Tile{.x = 2, .y = 2},
Tile{.x = 9, .y = 4},
Tile{.x = 2, .y = 4},
Tile{.x = 9, .y = 4},
Tile{.x = 9, .y = 4},
Tile{.x = 9, .y = 4},
Tile{.x = 9, .y = 4},
Tile{.x = 5, .y = 2},
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},
};
fn drawMap() !void {
w4.m.colors.* = .{
._0 = .p0,
._1 = .p1,
._2 = .p2,
._3 = .p3,
};
for (map) |tile, i| {
var x: u32 = i % 10;
var y: u32 = i / 10;
w4.blitSub(
&sprites.Cave,
x * 16,
y * 16,
16,
16,
@intCast(u32, tile.x) * 16,
@intCast(u32, tile.y) * 16,
sprites.Cave_width,
w4.BlitFlags{.two_bits = true},
);
}
}
export fn update() void { export fn update() void {
w4.m.colors._0 = .p3; // w4.m.colors._0 = .p3;
w4.m.colors._1 = .p0; // w4.m.colors._1 = .p0;
w4.text("Mara 2:\nTamamo's Fury", 10, 10); // w4.text("Mara 2:\nTamamo's Fury", 10, 10);
drawMap() catch unreachable;
const gamepad = w4.m.gamepads[0]; const gamepad = w4.m.gamepads[0];
@ -75,24 +214,26 @@ export fn update() void {
.two_bits = true, .two_bits = true,
}; };
w4.m.colors._0 = .p0; // w4.m.colors._0 = .p0;
w4.m.colors._1 = .p1; // w4.m.colors._1 = .p1;
w4.m.colors._2 = .p2; // w4.m.colors._2 = .p2;
w4.m.colors._3 = .p3; // w4.m.colors._3 = .p3;
w4.blit(&sprites.tamamotitle, 60, 60, sprites.tamamotitle_width, sprites.tamamotitle_height, flags); // w4.blit(&sprites.tamamotitle, 60, 60, sprites.tamamotitle_width, sprites.tamamotitle_height, flags);
w4.m.colors._0 = .p0; // w4.m.colors._0 = .p0;
w4.m.colors._1 = .p1; // w4.m.colors._1 = .p1;
w4.m.colors._2 = .p3; // w4.m.colors._2 = .p3;
w4.m.colors._3 = .transparent; // w4.m.colors._3 = .transparent;
w4.blit(&sprites.glaceon, 100, 128, sprites.glaceon_width, sprites.glaceon_height, flags); // w4.blit(&sprites.glaceon, 100, 128, sprites.glaceon_width, sprites.glaceon_height, flags);
w4.m.colors._0 = .transparent; w4.m.colors.* = .{
w4.m.colors._1 = .p0; ._0 = .transparent,
w4.m.colors._2 = .p1; ._1 = .p0,
w4.m.colors._3 = .p3; ._2 = .p1,
._3 = .p3,
};
if (mara_direction == Direction.Left) { if (mara_direction == Direction.Left) {
flags.flip_x = true; flags.flip_x = true;

File diff suppressed because one or more lines are too long

21
src/tools/genmap.js Normal file
View File

@ -0,0 +1,21 @@
if (Deno.args.length !== 1) {
console.log("Usage: ./genmap.js <path-to-map-file>");
Deno.exit(1);
}
const mapFile = Deno.args[0];
const data = await Deno.readTextFile(mapFile);
const map = JSON.parse(data);
let layer = map.layers[0];
console.log(`pub const map = [${layer.data.length}]Tile{`);
layer.data.forEach((tile, index) => {
tile -= 1;
const tileY = Math.trunc(tile / layer.height);
const tileX = tile % layer.width;
console.log(` Tile{.x = ${tileX}, .y = ${tileY}},`);
});
console.log("};");