70 lines
1.5 KiB
Plaintext
70 lines
1.5 KiB
Plaintext
/**
|
|
* Note that these look like classes but act like structs
|
|
* the methods actually have a implied struct as their first argument
|
|
*/
|
|
|
|
/**
|
|
* Camera.
|
|
*/
|
|
plex Camera {
|
|
init(real[3] pos, real[3] look) {
|
|
this.setting = "CAMERA_PERSPECTIVE";
|
|
this.pov = 45.0;
|
|
this.up = [0.0, 1.0, 0.0];
|
|
this.pos = pos;
|
|
this.look = look;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Player.
|
|
*/
|
|
plex Player {
|
|
init(str username, real[3] pos, Color color) {
|
|
this.client = 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(str password) Player[] { ! looks like a method but really it just has an implied "Player this" as the first argument
|
|
this.client.attach(this.username, password);
|
|
this.players = client.open("players");
|
|
return players.read();
|
|
}
|
|
|
|
logout() {
|
|
this.players.flush();
|
|
this.client.clunk();
|
|
}
|
|
|
|
update() {
|
|
if (key_down("right")) {
|
|
this.pos.x += 0.2;
|
|
this.client.write(Command(this.username, KEY_RIGHT))
|
|
}
|
|
|
|
if (key_down("left")) {
|
|
this.pos.x -= 0.2;
|
|
this.client.write(Command(this.username, KEY_LEFT))
|
|
}
|
|
|
|
if (key_down("down")) {
|
|
this.pos.z += 0.2;
|
|
this.client.write(Command(this.username, KEY_DOWN))
|
|
}
|
|
|
|
if (key_down("up")) {
|
|
this.pos.z -= 0.2;
|
|
this.client.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];
|