1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-07-02 01:16:58 +00:00

throttle number popup on NPC damage

This commit is contained in:
Sallai József 2022-08-21 18:57:01 +03:00
parent ca1fa7b7c0
commit f1b3c680c9
2 changed files with 24 additions and 6 deletions

View file

@ -13,11 +13,13 @@ pub struct NumberPopup {
pub prev_x: i32, pub prev_x: i32,
pub prev_y: i32, pub prev_y: i32,
counter: u16, counter: u16,
throttle: u16,
value_display: i16,
} }
impl NumberPopup { impl NumberPopup {
pub fn new() -> NumberPopup { pub fn new() -> NumberPopup {
NumberPopup { value: 0, x: 0, y: 0, prev_x: 0, prev_y: 0, counter: 0 } NumberPopup { value: 0, x: 0, y: 0, prev_x: 0, prev_y: 0, counter: 0, throttle: 0, value_display: 0 }
} }
pub fn set_value(&mut self, value: i16) { pub fn set_value(&mut self, value: i16) {
@ -31,25 +33,41 @@ impl NumberPopup {
pub fn add_value(&mut self, value: i16) { pub fn add_value(&mut self, value: i16) {
self.set_value(self.value + value); self.set_value(self.value + value);
} }
pub fn set_value_throttled(&mut self, value: i16) {
self.throttle = 16;
self.set_value(value);
}
pub fn add_value_throttled(&mut self, value: i16) {
self.set_value_throttled(self.value + value);
}
} }
impl GameEntity<()> for NumberPopup { impl GameEntity<()> for NumberPopup {
fn tick(&mut self, _state: &mut SharedGameState, _custom: ()) -> GameResult<()> { fn tick(&mut self, _state: &mut SharedGameState, _custom: ()) -> GameResult<()> {
if self.value == 0 { if self.throttle > 0 {
self.throttle = self.throttle.saturating_sub(1);
}
if self.value == 0 || self.throttle > 0 {
return Ok(()); return Ok(());
} }
self.value_display = self.value;
self.counter += 1; self.counter += 1;
if self.counter == 80 { if self.counter == 80 {
self.counter = 0; self.counter = 0;
self.value = 0; self.value = 0;
self.value_display = 0;
} }
Ok(()) Ok(())
} }
fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult<()> { fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult<()> {
if self.value == 0 { if self.value_display == 0 {
return Ok(()); return Ok(());
} }
@ -65,7 +83,7 @@ impl GameEntity<()> for NumberPopup {
let x = interpolate_fix9_scale(self.prev_x, self.x, state.frame_time) - frame_x; let x = interpolate_fix9_scale(self.prev_x, self.x, state.frame_time) - frame_x;
let y = interpolate_fix9_scale(self.prev_y, self.y, state.frame_time) - frame_y - y_offset; let y = interpolate_fix9_scale(self.prev_y, self.y, state.frame_time) - frame_y - y_offset;
let n = format!("{:+}", self.value); let n = format!("{:+}", self.value_display);
let x = x - n.len() as f32 * 4.0; let x = x - n.len() as f32 * 4.0;
@ -78,7 +96,7 @@ impl GameEntity<()> for NumberPopup {
batch.add_rect(x + offset as f32 * 8.0, y, &Rect::new_size(40, 48 + clip, 8, 8 - clip)); batch.add_rect(x + offset as f32 * 8.0, y, &Rect::new_size(40, 48 + clip, 8, 8 - clip));
} }
'0'..='9' => { '0'..='9' => {
let number_set = if self.value < 0 { 64 } else { 56 }; let number_set = if self.value_display < 0 { 64 } else { 56 };
let idx = chr as u16 - '0' as u16; let idx = chr as u16 - '0' as u16;
batch.add_rect( batch.add_rect(
x + offset as f32 * 8.0, x + offset as f32 * 8.0,

View file

@ -1182,7 +1182,7 @@ impl GameScene {
} }
if npc.npc_flags.show_damage() { if npc.npc_flags.show_damage() {
npc.popup.add_value(-bullet.damage); npc.popup.add_value_throttled(-bullet.damage);
} }
} }
} else if !bullet.weapon_flags.no_proj_dissipation() } else if !bullet.weapon_flags.no_proj_dissipation()