Change castle sizes

This commit is contained in:
Tobias Berger 2024-04-12 21:08:16 +02:00
parent 1c7568e60e
commit c9da5e9bb3
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
2 changed files with 19 additions and 14 deletions

View file

@ -169,16 +169,25 @@ fn player_panel(model: &Model, draw: &Draw, bounds: Rect, player: Player) {
Player::Black => [part_bounds[1], part_bounds[0]],
};
let player_stats = *model
.stats_of(player)
.read()
.expect("player stats poisoned");
let castle_bounds = castle_bounds.top_part(0.7);
let castle_texture = &model.textures.castle;
let castle_height = castle_texture.height() as f32 * (player_stats.castle as f32 / 100f32);
#[allow(clippy::cast_precision_loss)]
let castle_rect = Rect::from_x_y_w_h(
castle_bounds.x(),
castle_bounds.y(),
model.textures.castle.width() as f32,
model.textures.castle.height() as f32,
castle_texture.width() as f32,
castle_height,
)
.fit_into(castle_bounds);
draw.texture(&model.textures.castle)
.fit_into(castle_bounds)
.align_bottom_of(castle_bounds);
draw.texture(&castle_texture)
.xy(castle_rect.xy())
.wh(castle_rect.wh())
.finish();
@ -186,11 +195,6 @@ fn player_panel(model: &Model, draw: &Draw, bounds: Rect, player: Player) {
let status_rect = status_bounds
.align_left_of(status_bounds)
.align_middle_y_of(status_bounds);
let player_stats = *model
.stats_of(player)
.read()
.expect("player stats poisoned");
let status = match player {
Player::Red => format!(
"{:<3} Builders\n{:<5} Bricks\n{:<3} Soldiers\n{:<4} Weapons\n{:<7} Magi\n{:<3} Crystals\n{:<5} Castle\n{:<6} Fence",

View file

@ -36,20 +36,21 @@ impl Stats {
card::Stat::Weapons => self.weapons += effect.1,
card::Stat::Magi => self.magi += effect.1,
card::Stat::Crystals => self.crystals += effect.1,
card::Stat::Castle => self.castle += effect.1,
card::Stat::Castle => self.castle = u16::clamp(self.castle + effect.1, 0, 100),
card::Stat::Fence => self.fence += effect.1,
card::Stat::Attack => unreachable!(),
}
if self.castle >= 100 {
// TODO: Handle
println!("Game over!");
}
}
pub fn damage(&mut self, damage: u16) {
let castle_damage = damage.saturating_sub(self.fence);
self.fence = self.fence.saturating_sub(damage);
self.castle = self.castle.saturating_sub(castle_damage);
if self.castle >= 100 {
println!("Game over!");
}
}
pub fn apply_gains(&mut self) {