diff options
Diffstat (limited to 'pixel-client')
| -rw-r--r-- | pixel-client/Cargo.toml | 2 | ||||
| -rw-r--r-- | pixel-client/makefile | 51 | ||||
| -rw-r--r-- | pixel-client/src/game.rs | 56 | ||||
| -rw-r--r-- | pixel-client/src/helper.rs | 30 | ||||
| -rw-r--r-- | pixel-client/src/render/misc.rs | 17 | ||||
| -rw-r--r-- | pixel-client/src/render/sprite.rs | 21 | ||||
| -rw-r--r-- | pixel-client/tools/Cargo.toml | 2 | 
7 files changed, 151 insertions, 28 deletions
diff --git a/pixel-client/Cargo.toml b/pixel-client/Cargo.toml index d7cb336c..4ffec449 100644 --- a/pixel-client/Cargo.toml +++ b/pixel-client/Cargo.toml @@ -1,5 +1,5 @@  [package] -name = "light-client" +name = "pixelcurry"  version = "0.1.0"  edition = "2021" diff --git a/pixel-client/makefile b/pixel-client/makefile index 6a56fc62..6aa891d3 100644 --- a/pixel-client/makefile +++ b/pixel-client/makefile @@ -1,4 +1,18 @@ - +# Hurry Curry! - 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/>. +#  SPRITES = $(shell find assets/sprites -name '*.ta')  SPRITES_PNG = $(patsubst %.ta,%.png,$(SPRITES)) @@ -8,7 +22,16 @@ TEXTURES_IMPORT_PNG = $(patsubst %.import.png,%.ta,$(shell find assets/textures  PNG = $(shell find assets/textures -name '*.png') -.PHONY: tex_pack tex_export tex_import clean +CLIENT_DEPS = assets/atlas.meta.csv assets/atlas.ta assets/connect.csv assets/palette.csv + +IMPORT = ../target/release/tex_import +EXPORT = ../target/release/tex_export +PACK = ../target/release/tex_pack +COMPOSE = ../target/release/tex_compose +CLIENT = ../target/release/pixelcurry + +.PHONY: all tex_pack tex_export tex_import clean +all: $(CLIENT)  tex_pack: assets/atlas.ta  tex_import: $(TEXTURES_IMPORT_PNG)  tex_export: $(TEXTURES_PNG) $(SPRITES_PNG) assets/atlas.png @@ -17,21 +40,21 @@ clean:  	rm -fr assets/sprites  	rm -f assets/atlas.ta assets/atlas.meta.csv +$(CLIENT): $(shell find src -type f) $(CLIENT_DEPS) +	cargo build --release --bin pixelcurry +$(IMPORT) $(EXPORT) $(PACK) $(COMPOSE): $(shell find tools/src -type f) +	{ cd tools; cargo build --release; } -IMPORT = ../target/release/tex_import -EXPORT = ../target/release/tex_export -PACK = ../target/release/tex_pack -COMPOSE = ../target/release/tex_compose - -%.ta: %.import.png +%.ta: %.import.png $(IMPORT)  	$(IMPORT) $< $@ -%.png: %.ta -	../target/release/tex_export $< $@ +%.png: %.ta $(EXPORT) +	$(EXPORT) $< $@ -assets/sprites/%/all: assets/%.ini $(TEXTURES) +assets/sprites/%/all: assets/%.ini $(TEXTURES) $(COMPOSE)  	@mkdir -p $(basename $@) -	../target/release/tex_compose $< assets/textures $(basename $@) +	$(COMPOSE) $< assets/textures $(basename $@)  	@touch $@ -assets/atlas.ta assets/atlas.meta.csv: assets/sprites/items/all assets/sprites/tiles/all assets/sprites/misc/all -	../target/release/tex_pack assets/atlas.ta assets/atlas.meta.csv $(SPRITES) +assets/atlas.ta assets/atlas.meta.csv: assets/sprites/items/all assets/sprites/tiles/all assets/sprites/misc/all $(PACK) +	@echo $(PACK) assets/atlas.ta assets/atlas.meta.csv ... +	@$(PACK) assets/atlas.ta assets/atlas.meta.csv $(SPRITES) diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs index 7d8e466a..170e6a6e 100644 --- a/pixel-client/src/game.rs +++ b/pixel-client/src/game.rs @@ -16,7 +16,7 @@  */  use crate::{ -    helper::Vec2InterpolateExt, +    helper::InterpolateExt,      render::{          misc::MiscTextures,          sprite::{Sprite, SpriteDraw}, @@ -42,6 +42,7 @@ pub struct Game {      tilemap: Tilemap,      collision_map: HashSet<IVec2>,      players: HashMap<PlayerID, Player>, +    items_removed: Vec<Item>,      my_id: PlayerID,      camera_center: Vec2, @@ -74,7 +75,9 @@ pub struct Player {  pub struct Item {      position: Vec2, +    parent_position: Vec2,      kind: ItemIndex, +    alive: f32,      progress: Option<(f32, bool)>,  } @@ -90,6 +93,7 @@ impl Game {              movement_send_cooldown: 0.,              misc_textures: MiscTextures::init(layout),              item_sprites: Vec::new(), +            items_removed: Vec::new(),              interacting: false,              score: Score::default(),              camera_center: Vec2::ZERO, @@ -187,11 +191,25 @@ impl Game {                      }                  }              } -            PacketC::MoveItem { from, to } => *self.get_item(to) = self.get_item(from).take(), +            PacketC::MoveItem { from, to } => { +                let mut item = self.get_item(from).take(); +                if let Some(item) = &mut item { +                    item.parent_position = self.get_location_position(to); +                } +                *self.get_item(to) = item; +            }              PacketC::SetItem { location, item } => { -                *self.get_item(location) = item.map(|kind| Item { +                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, +                }; +                self.items_removed.extend(slot.take()); +                *slot = item.map(|kind| Item {                      kind, -                    position: Vec2::ZERO, +                    parent_position: position, +                    alive: 0., +                    position,                      progress: None,                  })              } @@ -239,6 +257,12 @@ impl Game {              ItemLocation::Player(pid) => &mut self.players.get_mut(&pid).unwrap().item,          }      } +    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, +        } +    }      pub fn tick(&mut self, dt: f32, keyboard: &KeyboardState, packet_out: &mut VecDeque<PacketS>) {          let mut direction = IVec2::new( @@ -289,14 +313,19 @@ impl Game {          for (_pid, player) in &mut self.players {              if let Some(item) = &mut player.item { -                item.position = player.movement.position +                item.parent_position = player.movement.position; +                item.tick(1., dt);              }          } -        for (pos, tile) in &mut self.tiles { +        for (_pos, tile) in &mut self.tiles {              if let Some(item) = &mut tile.item { -                item.position = pos.as_vec2() + 0.5 +                item.tick(1., dt)              }          } +        self.items_removed.retain_mut(|i| { +            i.tick(0., dt); +            i.alive > 0.01 +        })      }      pub fn draw(&self, ctx: &mut SpriteRenderer) { @@ -315,12 +344,23 @@ impl Game {                  item.draw(ctx, &self.item_sprites, &self.misc_textures)              }          } +        for item in &self.items_removed { +            item.draw(ctx, &self.item_sprites, &self.misc_textures) +        }      }  }  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.) +    }      pub fn draw(&self, ctx: &mut SpriteRenderer, item_sprites: &[Sprite], misc: &MiscTextures) { -        ctx.draw_world(item_sprites[self.kind.0].at(self.position)); +        ctx.draw_world( +            item_sprites[self.kind.0] +                .at(self.position) +                .alpha(self.alive), +        );          if let Some((progress, warn)) = self.progress {              let (bg, fg) = if warn {                  ([100, 0, 0, 200], [255, 0, 0, 200]) diff --git a/pixel-client/src/helper.rs b/pixel-client/src/helper.rs index 9654f519..168e580f 100644 --- a/pixel-client/src/helper.rs +++ b/pixel-client/src/helper.rs @@ -1,11 +1,33 @@ +/* +    Hurry Curry! - 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 hurrycurry_protocol::glam::Vec2; -pub trait Vec2InterpolateExt { -    fn exp_to(&mut self, target: Vec2, dt: f32); +pub trait InterpolateExt { +    fn exp_to(&mut self, target: Self, dt: f32);  } -impl Vec2InterpolateExt for Vec2 { -    fn exp_to(&mut self, target: Vec2, dt: f32) { +impl InterpolateExt for Vec2 { +    fn exp_to(&mut self, target: Self, dt: f32) {          self.x = target.x + (self.x - target.x) * (-dt).exp();          self.y = target.y + (self.y - target.y) * (-dt).exp();      }  } +impl InterpolateExt for f32 { +    fn exp_to(&mut self, target: Self, dt: f32) { +        *self = target + (*self - target) * (-dt).exp(); +    } +} diff --git a/pixel-client/src/render/misc.rs b/pixel-client/src/render/misc.rs index 9f866568..5b9e43d4 100644 --- a/pixel-client/src/render/misc.rs +++ b/pixel-client/src/render/misc.rs @@ -1,3 +1,20 @@ +/* +    Hurry Curry! - 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 super::{sprite::Sprite, AtlasLayout};  use hurrycurry_protocol::glam::Vec2;  use sdl2::rect::Rect; diff --git a/pixel-client/src/render/sprite.rs b/pixel-client/src/render/sprite.rs index 711f45bf..580146b1 100644 --- a/pixel-client/src/render/sprite.rs +++ b/pixel-client/src/render/sprite.rs @@ -1,3 +1,20 @@ +/* +    Hurry Curry! - 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 hurrycurry_protocol::glam::Vec2;  use sdl2::rect::{FRect, Rect}; @@ -56,6 +73,10 @@ impl SpriteDraw {              z_order: i32::MAX,          }      } +    pub fn alpha(mut self, alpha: f32) -> Self { +        self.tint[3] = (alpha.clamp(0., 1.) * 255.) as u8; +        self +    }  }  impl Ord for SpriteDraw { diff --git a/pixel-client/tools/Cargo.toml b/pixel-client/tools/Cargo.toml index f3075594..3392352b 100644 --- a/pixel-client/tools/Cargo.toml +++ b/pixel-client/tools/Cargo.toml @@ -9,4 +9,4 @@ anyhow = "1.0.86"  log = "0.4.22"  env_logger = "0.11.3"  clap = { version = "4.5.9", features = ["derive"] } -sdl2 = "0.37.0" +sdl2 = { version = "0.37.0", features = ["image", "ttf"] }  |