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 .
|
|
!!
|
|
type Camera {
|
|
init(pos Vec3, look Vec3) {
|
|
this.setting = "CAMERA_PERSPECTIVE";
|
|
this.pov = 45.0;
|
|
this.up = Vec3(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);
|
|
}
|
|
|
|
login(str password) Player[] {
|
|
this.server.attach(this.username, password);
|
|
this.players = server.open("players");
|
|
return players.read();
|
|
}
|
|
|
|
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))
|
|
}
|
|
|
|
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("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];
|