summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-17 00:06:29 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-17 00:06:29 +0200
commit922f04cfadbd3bab3eef09df036ad5edcc899199 (patch)
treeaf593a61683fd1e95bebe5ac3edb2ea4dea80855
parentdf418c0d3fec83fc1cbe0dabc6d4b9dfbdbcbabb (diff)
downloadhurrycurry-922f04cfadbd3bab3eef09df036ad5edcc899199.tar
hurrycurry-922f04cfadbd3bab3eef09df036ad5edcc899199.tar.bz2
hurrycurry-922f04cfadbd3bab3eef09df036ad5edcc899199.tar.zst
fade dead items et al
-rw-r--r--Cargo.lock30
-rw-r--r--pixel-client/Cargo.toml2
-rw-r--r--pixel-client/src/game.rs56
-rw-r--r--pixel-client/src/helper.rs30
-rw-r--r--pixel-client/src/render/misc.rs17
-rw-r--r--pixel-client/src/render/sprite.rs21
6 files changed, 128 insertions, 28 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fb31b8bc..d48a3b6d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -993,21 +993,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e281a65eeba3d4503a2839252f86374528f9ceafe6fed97c1d3b52e1fb625c1"
[[package]]
-name = "light-client"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "bincode",
- "clap",
- "env_logger",
- "hurrycurry-protocol",
- "log",
- "sdl2",
- "serde_json",
- "tungstenite",
-]
-
-[[package]]
name = "linux-raw-sys"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1232,6 +1217,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
+name = "pixelcurry"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "bincode",
+ "clap",
+ "env_logger",
+ "hurrycurry-protocol",
+ "log",
+ "sdl2",
+ "serde_json",
+ "tungstenite",
+]
+
+[[package]]
name = "pkg-config"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
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/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 {