diff options
Diffstat (limited to 'pixel-client/src')
-rw-r--r-- | pixel-client/src/game.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs index 1f74d491..5239a002 100644 --- a/pixel-client/src/game.rs +++ b/pixel-client/src/game.rs @@ -26,12 +26,12 @@ use crate::{ tilemap::Tilemap, State, }; -use hurrycurry_client_lib::{network::sync::Network, spatial_index::SpatialIndex}; +use hurrycurry_client_lib::{network::sync::Network, spatial_index::SpatialIndex, Involvement}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, movement::MovementBase, - Gamedata, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PacketS, PlayerID, Score, - TileIndex, + Gamedata, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PacketS, PlayerID, + RecipeIndex, Score, TileIndex, }; use log::{info, warn}; use sdl2::{ @@ -80,7 +80,7 @@ pub struct Item { parent_position: Vec2, kind: ItemIndex, alive: f32, - progress: Option<(f32, bool)>, + active: Option<Involvement>, } impl Game { @@ -340,15 +340,22 @@ impl Game { parent_position: position, alive: 0., position, - progress: None, + active: None, }) } + PacketC::ClearProgress { item } => self.get_item(item).as_mut().unwrap().active = None, PacketC::SetProgress { item, - progress, + position, + speed, warn, } => { - self.get_item(item).as_mut().unwrap().progress = progress.map(|s| (s, warn)); + self.get_item(item).as_mut().unwrap().active = Some(Involvement { + position, + speed, + warn, + recipe: RecipeIndex(0), + }); } PacketC::ServerMessage { text: _ } => { // TODO @@ -428,7 +435,10 @@ impl Game { impl Item { pub fn tick(&mut self, alive: f32, dt: f32) { self.position.exp_to(self.parent_position, dt * 20.); - self.alive.exp_to(alive, dt * 20.) + self.alive.exp_to(alive, dt * 20.); + if let Some(active) = &mut self.active { + active.position += active.speed * dt; + } } pub fn draw(&self, ctx: &mut Renderer, item_sprites: &[Sprite]) { ctx.draw_world( @@ -436,7 +446,7 @@ impl Item { .at(self.position) .alpha(self.alive), ); - if let Some((progress, warn)) = self.progress { + if let Some(Involvement { position, warn, .. }) = self.active { let (bg, fg) = if warn { ([100, 0, 0, 200], [255, 0, 0, 200]) } else { @@ -451,7 +461,7 @@ impl Item { ctx.draw_world(SpriteDraw::overlay( ctx.misc_textures.solid, self.position + Vec2::new(-0.5, -1.3), - Vec2::new(progress, 0.2), + Vec2::new(position, 0.2), Some(fg), )) } |