formatting
This commit is contained in:
parent
a6e254a100
commit
f1f84e0fe5
|
@ -1,43 +1,39 @@
|
|||
use "common.ztl";
|
||||
|
||||
fn main (argc real, argv str[]) {
|
||||
let screen_width = 800;
|
||||
let screen_height = 450;
|
||||
fn main(argc real, argv str[]) {
|
||||
let screen_width = 800;
|
||||
let screen_height = 450;
|
||||
|
||||
let username = argv[0];
|
||||
let password = argv[1];
|
||||
let username = argv[0];
|
||||
let password = argv[1];
|
||||
|
||||
let me = Player(
|
||||
username,
|
||||
(0.0, 1.0, 2.0),
|
||||
PURPLE
|
||||
);
|
||||
let me = Player(username, (0.0, 1.0, 2.0), PURPLE);
|
||||
|
||||
let running = true;
|
||||
while (running) {
|
||||
window("zwl client", screen_width, screen_height) {
|
||||
splitbox(parent.size*0.25) {
|
||||
canvas("2D") {
|
||||
if (button("logout")) {
|
||||
me.logout();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
let running = true;
|
||||
while (running) {
|
||||
window("zwl client", screen_width, screen_height) {
|
||||
splitbox(parent.size * 0.25) {
|
||||
canvas("2D") {
|
||||
if (button("logout")) {
|
||||
me.logout();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exits("Client Closed Successfully");
|
||||
exits("Client Closed Successfully");
|
||||
}
|
||||
|
|
|
@ -2,67 +2,63 @@
|
|||
* Camera .
|
||||
*/
|
||||
type Camera {
|
||||
init(pos Vec3, look Vec3) {
|
||||
this.setting = "CAMERA_PERSPECTIVE";
|
||||
this.pov = 45.0;
|
||||
this.up = (0.0, 1.0, 0.0);
|
||||
this.pos = pos;
|
||||
this.look = look;
|
||||
}
|
||||
init(pos Vec3, look Vec3) {
|
||||
this.setting = "CAMERA_PERSPECTIVE";
|
||||
this.pov = 45.0;
|
||||
this.up = (0.0, 1.0, 0.0);
|
||||
this.pos = pos;
|
||||
this.look = look;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Player .
|
||||
*/
|
||||
type Player {
|
||||
init (username str, pos Vec3, color Color) {
|
||||
this.server = Client("tcp://localhost:25565");
|
||||
this.username = username;
|
||||
this.pos = pos;
|
||||
this.color = color;
|
||||
this.camera = Camera(
|
||||
(this.pos.x + 10.0,
|
||||
this.pos.y + 10.0,
|
||||
this.pos.z),
|
||||
this.pos
|
||||
);
|
||||
}
|
||||
init(username str, pos Vec3, color Color) {
|
||||
this.server = Client("tcp://localhost:25565");
|
||||
this.username = username;
|
||||
this.pos = pos;
|
||||
this.color = color;
|
||||
this.camera =
|
||||
Camera((this.pos.x + 10.0, this.pos.y + 10.0, this.pos.z), this.pos);
|
||||
}
|
||||
|
||||
login (password str) Player[] {
|
||||
this.server.attach(this.username, password);
|
||||
this.players = server.open("players");
|
||||
return players.read();
|
||||
}
|
||||
login(password str) Player[] {
|
||||
this.server.attach(this.username, password);
|
||||
this.players = server.open("players");
|
||||
return players.read();
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.players.flush();
|
||||
this.server.clunk();
|
||||
}
|
||||
logout() {
|
||||
this.players.flush();
|
||||
this.server.clunk();
|
||||
}
|
||||
|
||||
update() {
|
||||
if (key_down("right")) {
|
||||
this.pos.x = this.pos.x + 0.2;
|
||||
this.server.write(Command(this.username, KEY_RIGHT))
|
||||
}
|
||||
update() {
|
||||
if (key_down("right")) {
|
||||
this.pos.x = this.pos.x + 0.2;
|
||||
this.server.write(Command(this.username, KEY_RIGHT))
|
||||
}
|
||||
|
||||
if (key_down("left")) {
|
||||
this.pos.x = this.pos.x - 0.2;
|
||||
this.server.write(Command(this.username, KEY_LEFT))
|
||||
}
|
||||
if (key_down("left")) {
|
||||
this.pos.x = this.pos.x - 0.2;
|
||||
this.server.write(Command(this.username, KEY_LEFT))
|
||||
}
|
||||
|
||||
if (key_down("down")) {
|
||||
this.pos.z = this.pos.z + 0.2;
|
||||
this.server.write(Command(this.username, KEY_DOWN))
|
||||
}
|
||||
if (key_down("down")) {
|
||||
this.pos.z = this.pos.z + 0.2;
|
||||
this.server.write(Command(this.username, KEY_DOWN))
|
||||
}
|
||||
|
||||
if (key_down("up")) {
|
||||
this.pos.z = this.pos.z - 0.2;
|
||||
this.server.write(Command(this.username, KEY_UP))
|
||||
}
|
||||
this.camera.sync();
|
||||
}
|
||||
if (key_down("up")) {
|
||||
this.pos.z = this.pos.z - 0.2;
|
||||
this.server.write(Command(this.username, KEY_UP))
|
||||
}
|
||||
this.camera.sync();
|
||||
}
|
||||
}
|
||||
|
||||
const RED is [255, 0, 0];
|
||||
const WHITE is [0, 0, 0];
|
||||
const PURPLE is [255, 255, 0];
|
||||
const RED is[255, 0, 0];
|
||||
const WHITE is[0, 0, 0];
|
||||
const PURPLE is[255, 255, 0];
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
use "common.ztl";
|
||||
|
||||
fn main (argc real, argv str[]) {
|
||||
let s = Server("tcp://0.0.0.0:25565");
|
||||
let running = true;
|
||||
let players = [ Player("user", (0, 0, 0), RED) ];
|
||||
while(running) {
|
||||
if (let client = s.accept("players")) {
|
||||
if (let message = client.get()) {
|
||||
if (message == "close") {
|
||||
client.close();
|
||||
running = false;
|
||||
} else if (message == "players") {
|
||||
client.write(players);
|
||||
} else {
|
||||
print("unknown message {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exits(nil);
|
||||
fn main(argc real, argv str[]) {
|
||||
let s = Server("tcp://0.0.0.0:25565");
|
||||
let running = true;
|
||||
let players = [Player("user", (0, 0, 0), RED)];
|
||||
while (running) {
|
||||
if (let client = s.accept("players")) {
|
||||
if (let message = client.get()) {
|
||||
if (message == "close") {
|
||||
client.close();
|
||||
running = false;
|
||||
} else if (message == "players") {
|
||||
client.write(players);
|
||||
} else {
|
||||
print("unknown message {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exits(nil);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue