diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-07 15:25:48 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-07 15:25:48 +0200 |
commit | 3ebb7582afc24992674cf6ebc0d6f314569d727f (patch) | |
tree | 093d355bb411b051e4e6ba3d80bb061f77b4939b | |
parent | 120eb58c117f251fc548275a7440c2b2492ec6aa (diff) | |
download | hurrycurry-3ebb7582afc24992674cf6ebc0d6f314569d727f.tar hurrycurry-3ebb7582afc24992674cf6ebc0d6f314569d727f.tar.bz2 hurrycurry-3ebb7582afc24992674cf6ebc0d6f314569d727f.tar.zst |
transmit boosting state
-rw-r--r-- | server/examples/client.rs | 10 | ||||
-rw-r--r-- | server/src/customer/movement.rs | 1 | ||||
-rw-r--r-- | server/src/game.rs | 3 | ||||
-rw-r--r-- | server/src/protocol.rs | 2 | ||||
-rw-r--r-- | test-client/main.ts | 3 | ||||
-rw-r--r-- | test-client/protocol.ts | 4 | ||||
-rw-r--r-- | test-client/visual.ts | 1 |
7 files changed, 16 insertions, 8 deletions
diff --git a/server/examples/client.rs b/server/examples/client.rs index 6c757f77..e7863cdb 100644 --- a/server/examples/client.rs +++ b/server/examples/client.rs @@ -1,19 +1,19 @@ /* Undercooked - a game about cooking Copyright 2024 metamuffin - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License only. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. - + */ use std::{ io::{stdin, BufRead, BufReader, Write}, @@ -49,6 +49,7 @@ fn main() { toks.next().unwrap().parse().unwrap(), toks.next().unwrap().parse().unwrap(), ), + boosting: false, rot: 0., }, "i" => PacketS::Position { @@ -56,6 +57,7 @@ fn main() { toks.next().unwrap().parse().unwrap(), toks.next().unwrap().parse().unwrap(), ), + boosting: false, rot: toks.next().unwrap_or("0").parse().unwrap(), }, _ => { diff --git a/server/src/customer/movement.rs b/server/src/customer/movement.rs index c6350ebd..bf2752f1 100644 --- a/server/src/customer/movement.rs +++ b/server/src/customer/movement.rs @@ -72,6 +72,7 @@ impl MovementBase { PacketS::Position { pos: self.position, + boosting: false, rot, } } diff --git a/server/src/game.rs b/server/src/game.rs index 13ee5410..d8184c1e 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -274,7 +274,7 @@ impl Game { self.packet_out .push_back(PacketC::RemovePlayer { id: player }) } - PacketS::Position { pos, rot } => { + PacketS::Position { pos, rot, boosting } => { let pid = player; let player = self .players @@ -297,6 +297,7 @@ impl Game { player: pid, pos: player.position, rot, + boosting, }); // if !movement_ok { // bail!( diff --git a/server/src/protocol.rs b/server/src/protocol.rs index 58182917..facfa5ab 100644 --- a/server/src/protocol.rs +++ b/server/src/protocol.rs @@ -47,6 +47,7 @@ pub enum PacketS { Position { pos: Vec2, rot: f32, + boosting: bool, }, Interact { pos: IVec2, @@ -98,6 +99,7 @@ pub enum PacketC { player: PlayerID, pos: Vec2, rot: f32, + boosting: bool, }, MoveItem { from: ItemLocation, diff --git a/test-client/main.ts b/test-client/main.ts index 0cd5c4cb..c4db6935 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -159,6 +159,7 @@ function packet(p: PacketC) { if (p.player == my_id) return pl.position.x = pos.x pl.position.y = pos.y + pl.boosting = p.boosting pl.rot = p.rot break; } @@ -289,7 +290,7 @@ function set_interact(edge: boolean) { function tick_update() { const p = players.get(my_id) if (!p) return - send({ type: "position", pos: [p.position.x, p.position.y], rot: p.rot }) + send({ type: "position", pos: [p.position.x, p.position.y], rot: p.rot, boosting: p.boosting }) } function frame_update(dt: number) { diff --git a/test-client/protocol.ts b/test-client/protocol.ts index fd0f8d43..f3bb8acb 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -30,7 +30,7 @@ export interface Gamedata { export type PacketS = { type: "join", name: string, character: number } // You join, sent as first packet. - | { type: "position", pos: Vec2, rot: number } // Update your position and rotation in radians (0 is -y) + | { type: "position", pos: Vec2, rot: number, boosting: boolean } // Update your position and rotation in radians (0 is -y) | { type: "interact", pos: Vec2, edge: boolean } // Interact with some tile. edge is true when pressing and false when releasing interact button | { type: "communicate", message?: Message, persist: boolean } // Send a message | { type: "collide", player: PlayerID, force: Vec2 } // Apply force to another player as a result of a collision @@ -40,7 +40,7 @@ export type PacketC = | { type: "data", data: Gamedata } // Game data was changed | { type: "add_player", id: PlayerID, name: string, position: Vec2, character: number } // Somebody else joined (or was already in the game) | { type: "remove_player", id: PlayerID } // Somebody left - | { type: "position", player: PlayerID, pos: Vec2, rot: number } // Update the position of a players (your own position is included here) + | { type: "position", player: PlayerID, pos: Vec2, rot: number, boosting: boolean } // Update the position of a players (your own position is included here) | { type: "move_item", from: ItemLocation, to: ItemLocation } // Item moved | { type: "set_item", location: ItemLocation, item?: ItemIndex } // the item contained in a tile or player changed | { type: "set_progress", item: ItemLocation, progress?: number, warn: boolean } // A tile is doing something. progress goes from 0 to 1, then null when finished diff --git a/test-client/visual.ts b/test-client/visual.ts index 2fbe9f78..5d9b7a76 100644 --- a/test-client/visual.ts +++ b/test-client/visual.ts @@ -132,6 +132,7 @@ function draw_player(player: PlayerData) { ctx.save() ctx.translate(player.anim_position.x, player.anim_position.y) ctx.rotate(-player.rot) + if (player.boosting) ctx.scale(1.3, 1.3) draw_character(player.character) ctx.restore() |