1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-22 05:33:02 +00:00

add switch boss health bar

This commit is contained in:
Sallai József 2022-08-28 16:17:54 +03:00
parent 029d6d52e4
commit f7d635a3d7
2 changed files with 98 additions and 39 deletions

View file

@ -25,13 +25,7 @@ pub struct BossLifeBar {
impl BossLifeBar {
pub fn new() -> BossLifeBar {
BossLifeBar {
target: BossLifeTarget::None,
life: 0,
max_life: 0,
prev_life: 0,
counter: 0,
}
BossLifeBar { target: BossLifeTarget::None, life: 0, max_life: 0, prev_life: 0, counter: 0 }
}
pub fn set_npc_target(&mut self, npc_id: u16, npc_list: &NPCList) {
@ -49,6 +43,91 @@ impl BossLifeBar {
self.max_life = self.life;
self.prev_life = self.life;
}
fn draw_regular(&self, state: &mut SharedGameState, ctx: &mut Context, _frame: &Frame) -> GameResult {
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?;
let box_length = 256;
let bar_length = box_length - 58;
let text_rect = Rect::new_size(0, 48, 32, 8);
let box_rect1 = Rect::new_size(0, 0, 244, 8);
let box_rect2 = Rect::new_size(0, 16, 244, 8);
let mut rect_prev_bar = Rect::new_size(0, 32, 232, 8);
let mut rect_life_bar = Rect::new_size(0, 24, 232, 8);
rect_prev_bar.right = ((self.prev_life as u32 * bar_length) / self.max_life as u32).min(bar_length) as u16;
rect_life_bar.right = ((self.life as u32 * bar_length) / self.max_life as u32).min(bar_length) as u16;
batch.add_rect(
((state.canvas_size.0 - box_length as f32) / 2.0).floor(),
state.canvas_size.1 - 20.0,
&box_rect1,
);
batch.add_rect(
((state.canvas_size.0 - box_length as f32) / 2.0).floor(),
state.canvas_size.1 - 12.0,
&box_rect2,
);
batch.add_rect(
((state.canvas_size.0 - box_length as f32) / 2.0).floor(),
state.canvas_size.1 - 20.0,
&box_rect1,
);
batch.add_rect(
((state.canvas_size.0 - box_length as f32) / 2.0 + 40.0).floor(),
state.canvas_size.1 - 16.0,
&rect_prev_bar,
);
batch.add_rect(
((state.canvas_size.0 - box_length as f32) / 2.0 + 40.0).floor(),
state.canvas_size.1 - 16.0,
&rect_life_bar,
);
batch.add_rect(
((state.canvas_size.0 - box_length as f32) / 2.0 + 8.0).floor(),
state.canvas_size.1 - 16.0,
&text_rect,
);
batch.draw(ctx)?;
Ok(())
}
fn draw_nx(&self, state: &mut SharedGameState, ctx: &mut Context, _frame: &Frame) -> GameResult {
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?;
let box_length = 148;
let bar_length = box_length - 52;
let text_rect = Rect::new_size(0, 48, 32, 8);
let box_rect1 = Rect::new_size(0, 0, 136, 8);
let box_rect2 = Rect::new_size(0, 16, 136, 8);
let box_rect3 = Rect::new_size(238, 0, 6, 8);
let box_rect4 = Rect::new_size(238, 16, 6, 8);
let mut rect_prev_bar = Rect::new_size(0, 32, 124, 8);
let mut rect_life_bar = Rect::new_size(0, 24, 124, 8);
rect_prev_bar.right = ((self.prev_life as u32 * bar_length) / self.max_life as u32).min(bar_length) as u16;
rect_life_bar.right = ((self.life as u32 * bar_length) / self.max_life as u32).min(bar_length) as u16;
let base_x = state.canvas_size.0 - box_length as f32;
batch.add_rect((base_x - 6.0).floor(), state.canvas_size.1 - 20.0, &box_rect1);
batch.add_rect((base_x - 6.0).floor(), state.canvas_size.1 - 12.0, &box_rect2);
batch.add_rect((base_x - 6.0).floor(), state.canvas_size.1 - 20.0, &box_rect1);
batch.add_rect((state.canvas_size.0 - 18.0).floor(), state.canvas_size.1 - 20.0, &box_rect3);
batch.add_rect((state.canvas_size.0 - 18.0).floor(), state.canvas_size.1 - 12.0, &box_rect4);
batch.add_rect((state.canvas_size.0 - 18.0).floor(), state.canvas_size.1 - 20.0, &box_rect3);
batch.add_rect((base_x + 34.0).floor(), state.canvas_size.1 - 16.0, &rect_prev_bar);
batch.add_rect((base_x + 34.0).floor(), state.canvas_size.1 - 16.0, &rect_life_bar);
batch.add_rect((base_x + 2.0).floor(), state.canvas_size.1 - 16.0, &text_rect);
batch.draw(ctx)?;
Ok(())
}
}
impl GameEntity<(&NPCList, &BossNPC)> for BossLifeBar {
@ -86,35 +165,9 @@ impl GameEntity<(&NPCList, &BossNPC)> for BossLifeBar {
return Ok(());
}
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?;
let box_length = 256;
let bar_length = box_length - 58;
let text_rect = Rect::new_size(0, 48, 32, 8);
let box_rect1 = Rect::new_size(0, 0, 244, 8);
let box_rect2 = Rect::new_size(0, 16, 244, 8);
let mut rect_prev_bar = Rect::new_size(0, 32, 232, 8);
let mut rect_life_bar = Rect::new_size(0, 24, 232, 8);
rect_prev_bar.right = ((self.prev_life as u32 * bar_length) / self.max_life as u32).min(bar_length) as u16;
rect_life_bar.right = ((self.life as u32 * bar_length) / self.max_life as u32).min(bar_length) as u16;
batch.add_rect(((state.canvas_size.0 - box_length as f32) / 2.0).floor(),
state.canvas_size.1 - 20.0, &box_rect1);
batch.add_rect(((state.canvas_size.0 - box_length as f32) / 2.0).floor(),
state.canvas_size.1 - 12.0, &box_rect2);
batch.add_rect(((state.canvas_size.0 - box_length as f32) / 2.0).floor(),
state.canvas_size.1 - 20.0, &box_rect1);
batch.add_rect(((state.canvas_size.0 - box_length as f32) / 2.0 + 40.0).floor(),
state.canvas_size.1 - 16.0, &rect_prev_bar);
batch.add_rect(((state.canvas_size.0 - box_length as f32) / 2.0 + 40.0).floor(),
state.canvas_size.1 - 16.0, &rect_life_bar);
batch.add_rect(((state.canvas_size.0 - box_length as f32) / 2.0 + 8.0).floor(),
state.canvas_size.1 - 16.0, &text_rect);
batch.draw(ctx)?;
Ok(())
match state.constants.is_switch {
true => self.draw_nx(state, ctx, _frame),
false => self.draw_regular(state, ctx, _frame),
}
}
}

View file

@ -131,7 +131,10 @@ impl PauseMenu {
self.pause_menu
.set_entry(PauseMenuEntry::AddPlayer2, MenuEntry::Active(state.t("menus.pause_menu.add_player2")));
self.pause_menu.set_entry(PauseMenuEntry::DropPlayer2, MenuEntry::Hidden);
self.pause_menu.selected = PauseMenuEntry::AddPlayer2;
if self.pause_menu.selected == PauseMenuEntry::DropPlayer2 {
self.pause_menu.selected = PauseMenuEntry::AddPlayer2;
}
}
PlayerCount::Two => {
self.pause_menu.set_entry(PauseMenuEntry::AddPlayer2, MenuEntry::Hidden);
@ -139,7 +142,10 @@ impl PauseMenu {
PauseMenuEntry::DropPlayer2,
MenuEntry::Active(state.t("menus.pause_menu.drop_player2")),
);
self.pause_menu.selected = PauseMenuEntry::DropPlayer2;
if self.pause_menu.selected == PauseMenuEntry::AddPlayer2 {
self.pause_menu.selected = PauseMenuEntry::DropPlayer2;
}
}
}
}