undar-lang/docs/project-syntax-example/common.ul

82 lines
1.7 KiB
Fortran

/**
* Note that these look like classes but act like structs
* the methods actually have a implied struct as their first argument
*/
/**
* Camera.
*/
plex Camera {
int setting;
real pov;
real[3] up;
real[3] pos;
real[3] look;
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 {
Client client;
str username;
real[3] pos;
nat color;
Camera camera;
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 nat RED = rgb332([255, 0, 0]);
const nat WHITE = rgb332([0, 0, 0]);
const nat PURPLE = rgb332([255, 255, 0]);