formatting

This commit is contained in:
zongor 2025-06-01 00:01:27 -04:00
parent a6e254a100
commit f1f84e0fe5
3 changed files with 97 additions and 105 deletions

View File

@ -1,43 +1,39 @@
use "common.ztl"; use "common.ztl";
fn main (argc real, argv str[]) { fn main(argc real, argv str[]) {
let screen_width = 800; let screen_width = 800;
let screen_height = 450; let screen_height = 450;
let username = argv[0]; let username = argv[0];
let password = argv[1]; let password = argv[1];
let me = Player( let me = Player(username, (0.0, 1.0, 2.0), PURPLE);
username,
(0.0, 1.0, 2.0),
PURPLE
);
let running = true; let running = true;
while (running) { while (running) {
window("zwl client", screen_width, screen_height) { window("zwl client", screen_width, screen_height) {
splitbox(parent.size*0.25) { splitbox(parent.size * 0.25) {
canvas("2D") { canvas("2D") {
if (button("logout")) { if (button("logout")) {
me.logout(); me.logout();
running = false; running = false;
}
}
}
splitbox(parent.size*0.75) {
canvas("3D") {
model(Floor((0, 0, 0), 30));
me.update();
model(Cube(me.pos, (0.5, 0.5, 0.5), me.appearance));
if (let players = me.server.read("players")) {
for (p in players) {
model(Cube(p.pos, (0.5, 0.5, 0.5), p.apperance));
}
}
}
} }
} }
} }
splitbox(parent.size * 0.75) {
canvas("3D") {
model(Floor((0, 0, 0), 30));
me.update();
model(Cube(me.pos, (0.5, 0.5, 0.5), me.appearance));
if (let players = me.server.read("players")) {
for (p in players) {
model(Cube(p.pos, (0.5, 0.5, 0.5), p.apperance));
}
}
}
}
}
}
exits("Client Closed Successfully"); exits("Client Closed Successfully");
} }

View File

@ -2,67 +2,63 @@
* Camera . * Camera .
*/ */
type Camera { type Camera {
init(pos Vec3, look Vec3) { init(pos Vec3, look Vec3) {
this.setting = "CAMERA_PERSPECTIVE"; this.setting = "CAMERA_PERSPECTIVE";
this.pov = 45.0; this.pov = 45.0;
this.up = (0.0, 1.0, 0.0); this.up = (0.0, 1.0, 0.0);
this.pos = pos; this.pos = pos;
this.look = look; this.look = look;
} }
} }
/** /**
* Player . * Player .
*/ */
type Player { type Player {
init (username str, pos Vec3, color Color) { init(username str, pos Vec3, color Color) {
this.server = Client("tcp://localhost:25565"); this.server = Client("tcp://localhost:25565");
this.username = username; this.username = username;
this.pos = pos; this.pos = pos;
this.color = color; this.color = color;
this.camera = Camera( this.camera =
(this.pos.x + 10.0, Camera((this.pos.x + 10.0, this.pos.y + 10.0, this.pos.z), this.pos);
this.pos.y + 10.0, }
this.pos.z),
this.pos
);
}
login (password str) Player[] { login(password str) Player[] {
this.server.attach(this.username, password); this.server.attach(this.username, password);
this.players = server.open("players"); this.players = server.open("players");
return players.read(); return players.read();
} }
logout() { logout() {
this.players.flush(); this.players.flush();
this.server.clunk(); this.server.clunk();
} }
update() { update() {
if (key_down("right")) { if (key_down("right")) {
this.pos.x = this.pos.x + 0.2; this.pos.x = this.pos.x + 0.2;
this.server.write(Command(this.username, KEY_RIGHT)) this.server.write(Command(this.username, KEY_RIGHT))
} }
if (key_down("left")) { if (key_down("left")) {
this.pos.x = this.pos.x - 0.2; this.pos.x = this.pos.x - 0.2;
this.server.write(Command(this.username, KEY_LEFT)) this.server.write(Command(this.username, KEY_LEFT))
} }
if (key_down("down")) { if (key_down("down")) {
this.pos.z = this.pos.z + 0.2; this.pos.z = this.pos.z + 0.2;
this.server.write(Command(this.username, KEY_DOWN)) this.server.write(Command(this.username, KEY_DOWN))
} }
if (key_down("up")) { if (key_down("up")) {
this.pos.z = this.pos.z - 0.2; this.pos.z = this.pos.z - 0.2;
this.server.write(Command(this.username, KEY_UP)) this.server.write(Command(this.username, KEY_UP))
} }
this.camera.sync(); this.camera.sync();
} }
} }
const RED is [255, 0, 0]; const RED is[255, 0, 0];
const WHITE is [0, 0, 0]; const WHITE is[0, 0, 0];
const PURPLE is [255, 255, 0]; const PURPLE is[255, 255, 0];

View File

@ -1,22 +1,22 @@
use "common.ztl"; use "common.ztl";
fn main (argc real, argv str[]) { fn main(argc real, argv str[]) {
let s = Server("tcp://0.0.0.0:25565"); let s = Server("tcp://0.0.0.0:25565");
let running = true; let running = true;
let players = [ Player("user", (0, 0, 0), RED) ]; let players = [Player("user", (0, 0, 0), RED)];
while(running) { while (running) {
if (let client = s.accept("players")) { if (let client = s.accept("players")) {
if (let message = client.get()) { if (let message = client.get()) {
if (message == "close") { if (message == "close") {
client.close(); client.close();
running = false; running = false;
} else if (message == "players") { } else if (message == "players") {
client.write(players); client.write(players);
} else { } else {
print("unknown message {message}"); print("unknown message {message}");
} }
} }
} }
} }
exits(nil); exits(nil);
} }