summaryrefslogtreecommitdiff
path: root/pixel-client/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-12-23 15:37:11 +0100
committermetamuffin <metamuffin@disroot.org>2024-12-25 20:01:20 +0100
commitb0df9b7c27a3d6316969d7feff4d912c3abf99f6 (patch)
tree118daa57feda8b571bd00bd22f6ff0dac4cc46de /pixel-client/src
parent2ceeea0e5fc245602618ec47f6ff1f91a094e130 (diff)
downloadhurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar
hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar.bz2
hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar.zst
two-handed server
Diffstat (limited to 'pixel-client/src')
-rw-r--r--pixel-client/src/game.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs
index e7754366..4dc43b72 100644
--- a/pixel-client/src/game.rs
+++ b/pixel-client/src/game.rs
@@ -30,8 +30,8 @@ use hurrycurry_client_lib::{network::sync::Network, spatial_index::SpatialIndex,
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
movement::MovementBase,
- Gamedata, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PacketS, PlayerClass,
- PlayerID, RecipeIndex, Score, TileIndex,
+ Gamedata, Hand, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PacketS,
+ PlayerClass, PlayerID, RecipeIndex, Score, TileIndex,
};
use log::{info, warn};
use sdl2::{
@@ -67,7 +67,7 @@ pub struct Tile {
pub struct Player {
movement: MovementBase,
- item: Option<Item>,
+ items: [Option<Item>; 2],
message_persist: Option<(Message, MessageTimeout)>,
_name: String,
_character: i32,
@@ -156,11 +156,13 @@ impl Game {
self.network.queue_out.push_back(PacketS::Interact {
player: self.my_id,
pos: Some(self.players[&self.my_id].movement.get_interact_target()),
+ hand: Hand::Left,
});
} else {
self.network.queue_out.push_back(PacketS::Interact {
player: self.my_id,
pos: None,
+ hand: Hand::Left,
});
}
self.interacting = interact;
@@ -209,9 +211,11 @@ impl Game {
});
for player in self.players.values_mut() {
- if let Some(item) = &mut player.item {
- item.parent_position = player.movement.position;
- item.tick(1., dt);
+ for item in &mut player.items {
+ if let Some(item) = item {
+ item.parent_position = player.movement.position;
+ item.tick(1., dt);
+ }
}
}
for tile in self.tiles.values_mut() {
@@ -292,7 +296,7 @@ impl Game {
_character: character,
_name: name,
message_persist: None,
- item: None,
+ items: [const { None }; 2],
movement: MovementBase {
position,
input_direction: Vec2::ZERO,
@@ -337,7 +341,9 @@ impl Game {
let position = self.get_location_position(location);
let slot = match location {
ItemLocation::Tile(pos) => &mut self.tiles.get_mut(&pos).unwrap().item,
- ItemLocation::Player(pid) => &mut self.players.get_mut(&pid).unwrap().item,
+ ItemLocation::Player(pid, hand) => {
+ &mut self.players.get_mut(&pid).unwrap().items[hand.index()]
+ }
};
self.items_removed.extend(slot.take());
*slot = item.map(|kind| Item {
@@ -389,13 +395,15 @@ impl Game {
pub fn get_item(&mut self, location: ItemLocation) -> &mut Option<Item> {
match location {
ItemLocation::Tile(pos) => &mut self.tiles.get_mut(&pos).unwrap().item,
- ItemLocation::Player(pid) => &mut self.players.get_mut(&pid).unwrap().item,
+ ItemLocation::Player(pid, hand) => {
+ &mut self.players.get_mut(&pid).unwrap().items[hand.index()]
+ }
}
}
pub fn get_location_position(&self, location: ItemLocation) -> Vec2 {
match location {
ItemLocation::Tile(pos) => pos.as_vec2() + 0.5,
- ItemLocation::Player(p) => self.players[&p].movement.position,
+ ItemLocation::Player(p, _) => self.players[&p].movement.position,
}
}
@@ -494,8 +502,10 @@ impl Player {
_ => (),
}
}
- if let Some(item) = &self.item {
- item.draw(ctx, item_sprites)
+ for item in &self.items {
+ if let Some(item) = item {
+ item.draw(ctx, item_sprites)
+ }
}
}
}