From a2b5beb434b38aa8d0856166950053f8cf456f42 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 4 Jan 2019 13:22:21 -0500 Subject: Add teleportation "Spawns" in the old code. --- client.c | 7 +++++++ server.c | 13 +++++++++++++ torus.h | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/client.c b/client.c index 9aa052a..867b4de 100644 --- a/client.c +++ b/client.c @@ -271,6 +271,11 @@ static void clientMap(void) { clientMessage(msg); } +static void clientTele(uint8_t port) { + struct ClientMessage msg = { .type = ClientTele, .port = port }; + clientMessage(msg); +} + static struct { enum { ModeNormal, @@ -402,6 +407,8 @@ static void inputNormal(bool keyCode, wchar_t ch) { break; case Esc: modeNormal(); input.shift = 0; break; case 'q': endwin(); exit(EX_OK); + break; case 'Q': clientTele(input.color % ARRAY_LEN(Ports)); + break; case '\\': input.delta = (input.delta == 1 ? 4 : 1); break; case 'h': clientMove(-input.delta, 0); diff --git a/server.c b/server.c index 37f57ca..bd4e980 100644 --- a/server.c +++ b/server.c @@ -359,6 +359,16 @@ static bool clientMap(const struct Client *client) { return true; } +static bool clientTele(struct Client *client, uint8_t port) { + if (port >= ARRAY_LEN(Ports)) return false; + struct Client old = *client; + client->tileX = Ports[port].tileX; + client->tileY = Ports[port].tileY; + client->cellX = CellInitX; + client->cellY = CellInitY; + return clientUpdate(client, &old); +} + int main(int argc, char *argv[]) { int error; @@ -477,6 +487,9 @@ int main(int argc, char *argv[]) { break; case ClientMap: { success = clientMap(client); } + break; case ClientTele: { + success = clientTele(client, msg.port); + } } if (!success) clientRemove(client); } diff --git a/torus.h b/torus.h index 7da2915..b9d842f 100644 --- a/torus.h +++ b/torus.h @@ -104,6 +104,17 @@ static const size_t TilesSize = sizeof(struct Tile[TileRows][TileCols]); static const uint32_t TileInitX = 0; static const uint32_t TileInitY = 0; +static const struct { + uint32_t tileX; + uint32_t tileY; +} Ports[] = { + { TileInitX, TileInitY }, + { TileCols * 3 / 4, TileRows * 3 / 4 }, // NW + { TileCols * 1 / 4, TileRows * 3 / 4 }, // NE + { TileCols * 1 / 4, TileRows * 1 / 4 }, // SE + { TileCols * 3 / 4, TileRows * 1 / 4 }, // SW +}; + enum { MapRows = 11, MapCols = 11, @@ -152,6 +163,7 @@ struct ClientMessage { ClientFlip, ClientPut, ClientMap, + ClientTele, } type; union { struct { @@ -162,5 +174,6 @@ struct ClientMessage { uint8_t color; uint8_t cell; } put; + uint8_t port; }; }; -- cgit 1.4.1