From cdf16aca9d2f6ac1db91a52f190c158c475cfe24 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 24 Jul 2023 23:01:34 +0100 Subject: [PATCH] particles, and centred camera --- src/camera.rs | 3 ++- src/gui.rs | 2 +- src/inventory_system.rs | 9 +-------- src/particle_system.rs | 43 ++++++++++++++++++++++++++++++++++++++--- src/player.rs | 8 ++++++-- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index bfb64c2..81dcf8a 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -7,7 +7,8 @@ const SHOW_BOUNDARIES: bool = false; pub fn get_screen_bounds(ecs: &World, ctx: &mut Rltk) -> (i32, i32, i32, i32) { let player_pos = ecs.fetch::(); - let (x_chars, y_chars) = ctx.get_char_size(); + //let (x_chars, y_chars) = ctx.get_char_size(); + let (x_chars, y_chars) = (80, 43); let centre_x = (x_chars / 2) as i32; let centre_y = (y_chars / 2) as i32; diff --git a/src/gui.rs b/src/gui.rs index 7b648d9..8542577 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -7,7 +7,7 @@ use specs::prelude::*; use std::collections::BTreeMap; pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { - ctx.draw_hollow_box_double(0, 43, 79, 7, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); + ctx.draw_box_double(0, 43, 79, 7, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Render stats let combat_stats = ecs.read_storage::(); diff --git a/src/inventory_system.rs b/src/inventory_system.rs index ce4ef82..01672bd 100644 --- a/src/inventory_system.rs +++ b/src/inventory_system.rs @@ -273,14 +273,7 @@ impl<'a> System<'a> for ItemUseSystem { } let pos = positions.get(entity); if let Some(pos) = pos { - particle_builder.request( - pos.x, - pos.y, - rltk::RGB::named(rltk::GREEN), - rltk::RGB::named(rltk::BLACK), - rltk::to_cp437('♥'), - DEFAULT_PARTICLE_LIFETIME, - ); + particle_builder.heal(pos.x, pos.y); } } } diff --git a/src/particle_system.rs b/src/particle_system.rs index 8fb7637..649a1a1 100644 --- a/src/particle_system.rs +++ b/src/particle_system.rs @@ -2,8 +2,9 @@ use super::{ParticleLifetime, Position, Renderable, Rltk}; use rltk::RGB; use specs::prelude::*; +pub const SHORT_PARTICLE_LIFETIME: f32 = 100.0; // For things which will happen frequently - i.e. attacking. -pub const DEFAULT_PARTICLE_LIFETIME: f32 = 150.0; +pub const DEFAULT_PARTICLE_LIFETIME: f32 = 200.0; // For exceptional things, like large AOEs, to make sure the // player can actually see what's being impacted - i.e. fireball. pub const LONG_PARTICLE_LIFETIME: f32 = 300.0; @@ -56,11 +57,47 @@ impl ParticleBuilder { } pub fn damage_taken(&mut self, x: i32, y: i32) { - self.request(x, y, rltk::RGB::named(rltk::ORANGE), rltk::RGB::named(rltk::BLACK), rltk::to_cp437('‼'), 200.0); + self.request( + x, + y, + rltk::RGB::named(rltk::ORANGE), + rltk::RGB::named(rltk::BLACK), + rltk::to_cp437('‼'), + DEFAULT_PARTICLE_LIFETIME, + ); } pub fn trap_triggered(&mut self, x: i32, y: i32) { - self.request(x, y, rltk::RGB::named(rltk::RED), rltk::RGB::named(rltk::RED), rltk::to_cp437('‼'), 200.0); + self.request( + x, + y, + rltk::RGB::named(rltk::RED), + rltk::RGB::named(rltk::RED), + rltk::to_cp437('‼'), + DEFAULT_PARTICLE_LIFETIME, + ); + } + + pub fn heal(&mut self, x: i32, y: i32) { + self.request( + x, + y, + rltk::RGB::named(rltk::GREEN), + rltk::RGB::named(rltk::BLACK), + rltk::to_cp437('♥'), + DEFAULT_PARTICLE_LIFETIME, + ); + } + + pub fn kick(&mut self, x: i32, y: i32) { + self.request( + x, + y, + rltk::RGB::named(rltk::CHOCOLATE), + rltk::RGB::named(rltk::BLACK), + rltk::to_cp437('‼'), + SHORT_PARTICLE_LIFETIME, + ); } // Makes a particle request in the shape of an 'x'. Sort of. diff --git a/src/player.rs b/src/player.rs index 5255b25..d992b78 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,7 +1,7 @@ use super::{ gamelog, BlocksTile, BlocksVisibility, CombatStats, Door, EntityMoved, Hidden, HungerClock, HungerState, Item, Map, - Monster, Name, Player, Position, Renderable, RunState, State, SufferDamage, Telepath, TileType, Viewshed, - WantsToMelee, WantsToPickupItem, + Monster, Name, ParticleBuilder, Player, Position, Renderable, RunState, State, SufferDamage, Telepath, TileType, + Viewshed, WantsToMelee, WantsToPickupItem, }; use rltk::{Point, RandomNumberGenerator, Rltk, VirtualKeyCode}; use specs::prelude::*; @@ -208,6 +208,8 @@ pub fn kick(i: i32, j: i32, ecs: &mut World) -> RunState { if let Some(door) = door { // If the door is closed, if door.open == false { + let mut particle_builder = ecs.write_resource::(); + particle_builder.kick(pos.x + delta_x, pos.y + delta_y); // 33% chance of breaking it down. if rng.roll_dice(1, 3) == 1 { gamelog::Logger::new() @@ -240,6 +242,8 @@ pub fn kick(i: i32, j: i32, ecs: &mut World) -> RunState { } if let Some(_) = last_non_door_target { gamelog::Logger::new().append("You kick the").item_name_n(target_name).period().log(); + let mut particle_builder = ecs.write_resource::(); + particle_builder.kick(pos.x + delta_x, pos.y + delta_y); // Do something here if it's anything other than a door. break; }