mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-15 06:41:21 +00:00
Floor drawing function
- Draw floors from JSON files, untested at the moment. - Renamed lot.zig to world.zig
This commit is contained in:
parent
aa284c424f
commit
cbe28d6c78
6 changed files with 78 additions and 38 deletions
|
@ -6,7 +6,8 @@ set(IFF2HTML_SOURCES
|
||||||
md5.c
|
md5.c
|
||||||
image.c
|
image.c
|
||||||
opngreduc.c
|
opngreduc.c
|
||||||
../../Libraries/FileHandler/bmp/read_bmp.c
|
../../library/formats/iff/iff.h
|
||||||
|
../../library/formats/bmp/read_bmp.c
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(${FILEHANDLER_INCLUDE} ${LIBPNG_INCLUDE})
|
include_directories(${FILEHANDLER_INCLUDE} ${LIBPNG_INCLUDE})
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
// C headers
|
// C headers
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
|
exe.linkLibCpp();
|
||||||
exe.addIncludePath(.{ .path = "./library/formats" });
|
exe.addIncludePath(.{ .path = "./library/formats" });
|
||||||
exe.addIncludePath(.{ .path = "./library/libvitaboy" });
|
exe.addIncludePath(.{ .path = "./library/libvitaboy" });
|
||||||
exe.addIncludePath(.{ .path = "./tools" });
|
exe.addIncludePath(.{ .path = "./tools" });
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.{
|
.{
|
||||||
.name = "ztso",
|
.name = "mysimulation",
|
||||||
// This is a [Semantic Version](https://semver.org/).
|
// This is a [Semantic Version](https://semver.org/).
|
||||||
// In a future version of Zig it will be used for package deduplication.
|
// In a future version of Zig it will be used for package deduplication.
|
||||||
.version = "0.1.100",
|
.version = "0.1.100",
|
||||||
|
|
28
src/lot.zig
28
src/lot.zig
|
@ -1,28 +0,0 @@
|
||||||
pub const Floor = struct {
|
|
||||||
level: u8,
|
|
||||||
x: u8,
|
|
||||||
y: u8,
|
|
||||||
value: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const World = struct {
|
|
||||||
floors: []Floor,
|
|
||||||
walls: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Item = struct {
|
|
||||||
guid: u8,
|
|
||||||
level: u8,
|
|
||||||
x: u8,
|
|
||||||
y: u8,
|
|
||||||
dir: u8,
|
|
||||||
group: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const House = struct {
|
|
||||||
version: f32,
|
|
||||||
size: u8,
|
|
||||||
category: u8,
|
|
||||||
world: World,
|
|
||||||
items: []Item,
|
|
||||||
};
|
|
19
src/main.zig
19
src/main.zig
|
@ -1,7 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
|
const world = @import("world.zig");
|
||||||
const MAX_INPUT_CHARS = 9;
|
|
||||||
|
|
||||||
const GameScreen = enum {
|
const GameScreen = enum {
|
||||||
login,
|
login,
|
||||||
|
@ -9,13 +8,11 @@ const GameScreen = enum {
|
||||||
world,
|
world,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Still in the proof of concept phase, don't midn the mess
|
// Still in the proof of concept phase, don't mind the mess
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
const screen_width = 800;
|
const screen_width = 800;
|
||||||
const screen_height = 600;
|
const screen_height = 600;
|
||||||
|
|
||||||
// var timePlayed: f32 = 0.0;
|
|
||||||
|
|
||||||
rl.initWindow(screen_width, screen_height, "My Simulation");
|
rl.initWindow(screen_width, screen_height, "My Simulation");
|
||||||
defer rl.closeWindow();
|
defer rl.closeWindow();
|
||||||
|
|
||||||
|
@ -23,13 +20,15 @@ pub fn main() anyerror!void {
|
||||||
var frame_counter: i32 = 0;
|
var frame_counter: i32 = 0;
|
||||||
|
|
||||||
var camera = rl.Camera3D{
|
var camera = rl.Camera3D{
|
||||||
.position = rl.Vector3.init(5.0, 4.0, 5.0),
|
.position = rl.Vector3.init(0.0, 10.0, 10.0),
|
||||||
.target = rl.Vector3.init(0, 2.0, 0),
|
.target = rl.Vector3.init(0, 0.0, 0),
|
||||||
.up = rl.Vector3.init(0, 1.0, 0),
|
.up = rl.Vector3.init(0, 1.0, 0),
|
||||||
.fovy = 60,
|
.fovy = 60,
|
||||||
.projection = rl.CameraProjection.camera_perspective,
|
.projection = rl.CameraProjection.camera_perspective,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const planePosition = rl.Vector3.init(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
// var textBox = rl.Rectangle.init(screen_width / 2.0 - 100, 180, 50);
|
// var textBox = rl.Rectangle.init(screen_width / 2.0 - 100, 180, 50);
|
||||||
// var mouseOnText = false;
|
// var mouseOnText = false;
|
||||||
// var letterCount = 0;
|
// var letterCount = 0;
|
||||||
|
@ -70,6 +69,7 @@ pub fn main() anyerror!void {
|
||||||
defer rl.endDrawing();
|
defer rl.endDrawing();
|
||||||
|
|
||||||
switch (current_screen) {
|
switch (current_screen) {
|
||||||
|
// Mockup loading screen, skips straight to world
|
||||||
.login => {
|
.login => {
|
||||||
// Splash screen
|
// Splash screen
|
||||||
rl.drawTexture(splash, 0, 0, rl.Color.white);
|
rl.drawTexture(splash, 0, 0, rl.Color.white);
|
||||||
|
@ -78,13 +78,16 @@ pub fn main() anyerror!void {
|
||||||
// Loading text
|
// Loading text
|
||||||
rl.drawText("Reticulating splines...", 20, screen_height - 30, 20, rl.Color.white);
|
rl.drawText("Reticulating splines...", 20, screen_height - 30, 20, rl.Color.white);
|
||||||
},
|
},
|
||||||
|
// Skip this for now
|
||||||
.cas => {},
|
.cas => {},
|
||||||
//
|
// "World" (i.e. lot view)
|
||||||
.world => {
|
.world => {
|
||||||
rl.clearBackground(rl.Color.ray_white);
|
rl.clearBackground(rl.Color.ray_white);
|
||||||
|
|
||||||
camera.begin();
|
camera.begin();
|
||||||
defer camera.end();
|
defer camera.end();
|
||||||
|
|
||||||
|
rl.drawPlane(planePosition, rl.Vector2.init(2, 2), rl.Color.green);
|
||||||
rl.drawGrid(64, 1.0);
|
rl.drawGrid(64, 1.0);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
63
src/world.zig
Normal file
63
src/world.zig
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const rl = @import("raylib");
|
||||||
|
const json = std.json;
|
||||||
|
|
||||||
|
pub const Floor = struct {
|
||||||
|
level: u8,
|
||||||
|
x: u8,
|
||||||
|
y: u8,
|
||||||
|
value: u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Wall = struct {
|
||||||
|
level: u8,
|
||||||
|
x: u8,
|
||||||
|
y: u8,
|
||||||
|
value: u8,
|
||||||
|
tls: u8,
|
||||||
|
trs: u8,
|
||||||
|
tlp: u8,
|
||||||
|
trp: u8,
|
||||||
|
blp: u8,
|
||||||
|
brp: u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const World = struct {
|
||||||
|
floors: []Floor,
|
||||||
|
walls: []Wall,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Item = struct {
|
||||||
|
guid: u8,
|
||||||
|
level: u8,
|
||||||
|
x: u8,
|
||||||
|
y: u8,
|
||||||
|
dir: u8,
|
||||||
|
group: u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const House = struct {
|
||||||
|
version: f32,
|
||||||
|
size: u8,
|
||||||
|
category: u8,
|
||||||
|
world: World,
|
||||||
|
items: []Item,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Draws floors from JSON Blueprint files
|
||||||
|
pub fn draw_floors(json_file: [:0]const u8) void {
|
||||||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
defer _ = gpa.deinit();
|
||||||
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
|
const floorLevel = rl.Vector3.init(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
const parsed = try json.parseFromSlice(House, allocator, json_file, .{});
|
||||||
|
defer parsed.deinit();
|
||||||
|
|
||||||
|
const blueprint = parsed.value;
|
||||||
|
|
||||||
|
for (blueprint.world.floors) |flr| {
|
||||||
|
rl.drawPlane(floorLevel, rl.Vector2.init(flr.x, flr.y), rl.Color.green);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue