Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjercan committed Apr 3, 2024
1 parent 1dfcf90 commit 7dc1b8e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions examples/multi/client.cl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PlayerLobby inherits Thread {
init(c: Client): SELF_TYPE { { client <- c; self; } };

run(): Object {
while true loop
while true loop -- TODO: add exit condition
case client.recv() of
message: PlayerPosition => player_update(message);
message: CoinPosition => coin_update(message);
Expand Down Expand Up @@ -149,7 +149,7 @@ class Main {
screen_width: Int <- maxX * cell_size;
screen_height: Int <- maxY * cell_size;

client: Client <- new Client.init("127.0.0.1", 8081, new MessageHelper).connect();
client: Client <- new Client.init("127.0.0.1", 8080, new MessageHelper).connect();
lobby: PlayerLobby <- new PlayerLobby.init(client);

pthread: PThread <- new PThread;
Expand All @@ -165,11 +165,13 @@ class Main {
keyW: Bool <- raylib.isKeyPressed(raylib.keyW()),
keyS: Bool <- raylib.isKeyPressed(raylib.keyS()),
message: PlayerInput <- new PlayerInput.init(lobby.player_id(), keyA, keyD, keyW, keyS)
in lobby.send(message); -- if need optimizations we can ignore when all keys are false
in lobby.send(message);

raylib.beginDrawing();
raylib.clearBackground(raylib.raywhite());

-- TODO: add score UI

lobby.draw(raylib);

raylib.endDrawing();
Expand Down
2 changes: 2 additions & 0 deletions examples/multi/message.cl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- TODO: add disconnect message/quit

class MessageHelper inherits Serde {
deserialize(input: String): Tuple (* Message, String *) {
let kind: String <- input.substr(0, 1),
Expand Down
3 changes: 2 additions & 1 deletion examples/multi/server.cl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Player inherits Thread {

update(input: PlayerInput): Object {
{
-- TODO: keep players within bounds
if (input.keyA()) then pos_x <- pos_x - size_x else
if (input.keyD()) then pos_x <- pos_x + size_x else
if (input.keyW()) then pos_y <- pos_y - size_y else
Expand Down Expand Up @@ -191,7 +192,7 @@ class PlayerLobby inherits Thread {

class Main {
linux: Linux <- new Linux;
server: Server <- new Server.init(8081, new MessageHelper).listen(10);
server: Server <- new Server.init(8080, new MessageHelper).listen(10);
pthread: PThread <- new PThread;
lobby: PlayerLobby <- new PlayerLobby.init(server);
lobby_thread: Int <- pthread.spawn(lobby);
Expand Down

0 comments on commit 7dc1b8e

Please sign in to comment.