From 28da301e8cf8850797f24f6127bc392354949a68 Mon Sep 17 00:00:00 2001 From: Alula Date: Fri, 30 Oct 2020 15:24:12 +0100 Subject: [PATCH] air counter and drowning --- src/player.rs | 60 ++++++++++++++++++++++++++++------------- src/scene/game_scene.rs | 26 +++++++++++++----- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/player.rs b/src/player.rs index 92a2b67..738a662 100644 --- a/src/player.rs +++ b/src/player.rs @@ -45,14 +45,16 @@ pub struct Player { pub update_target: bool, pub stars: u8, pub damage: u16, + pub air_counter: u16, + pub air: u16, weapon_offset_y: i8, index_x: isize, index_y: isize, splash: bool, booster_switch: u8, bubble: u8, - exp_wait: isize, - exp_count: isize, + damage_counter: u16, + damage_taken: i16, anim_num: u16, anim_counter: u16, anim_rect: Rect, @@ -93,9 +95,11 @@ impl Player { booster_switch: 0, stars: 0, damage: 0, + air_counter: 0, + air: 0, bubble: 0, - exp_wait: 0, - exp_count: 0, + damage_counter: 0, + damage_taken: 0, anim_num: 0, anim_counter: 0, anim_rect: constants.my_char.animations_right[0], @@ -104,11 +108,37 @@ impl Player { } fn tick_normal(&mut self, state: &mut SharedGameState) -> GameResult { + if !state.control_flags.interactions_disabled() && state.control_flags.control_enabled() { + if self.equip.has_air_tank() { + self.air = 1000; + self.air_counter = 0; + } else if self.flags.in_water() { + self.air_counter = 60; + if self.air > 0 { + self.air -= 1; + } else { + self.cond.set_hidden(true); + state.textscript_vm.start_script(41); + state.create_caret(self.x, self.y, CaretType::DrownedQuote, self.direction); + } + } else { + self.air = 1000; + + if self.air_counter > 0 { + self.air_counter -= 1; + } + } + } + if self.cond.hidden() { return Ok(()); } - let physics = if self.flags.in_water() { state.constants.my_char.water_physics } else { state.constants.my_char.air_physics }; + let physics = if self.flags.in_water() { + state.constants.my_char.water_physics + } else { + state.constants.my_char.air_physics + }; self.question = false; @@ -572,29 +602,21 @@ impl GameEntity<()> for Player { return Ok(()); } - if self.exp_wait != 0 { - self.exp_wait -= 1; + if self.damage_counter != 0 { + self.damage_counter -= 1; } if self.shock_counter != 0 { self.shock_counter -= 1; - } else if self.exp_count != 0 { + } else if self.damage_taken != 0 { // SetValueView(&self.x, &self.y, self.exp_count); // todo: damage popup - self.exp_count = 0; + self.damage_taken = 0; } // todo: add additional control modes like NXEngine has such as noclip? match self.control_mode { - ControlMode::Normal => { - if state.control_flags.interactions_disabled() && state.control_flags.control_enabled() { - // AirProcess(); // todo - } - - self.tick_normal(state)?; - } - ControlMode::IronHead => { - self.tick_ironhead(state)?; - } + ControlMode::Normal => self.tick_normal(state)?, + ControlMode::IronHead => self.tick_ironhead(state)?, } self.cond.set_increase_acceleration(false); diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index a424448..bd30202 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -150,13 +150,24 @@ impl GameScene { if self.player.max_life != 0 { // life box batch.add_rect(16.0, 40.0, - &Rect::::new_size(0, 40, 64, 8)); + &Rect::new_size(0, 40, 64, 8)); // yellow bar batch.add_rect(40.0, 40.0, - &Rect::::new_size(0, 32, ((self.life_bar as usize * 40) / self.player.max_life as usize), 8)); + &Rect::new_size(0, 32, ((self.life_bar as usize * 40) / self.player.max_life as usize), 8)); // life batch.add_rect(40.0, 40.0, - &Rect::::new_size(0, 24, ((self.player.life as usize * 40) / self.player.max_life as usize), 8)); + &Rect::new_size(0, 24, ((self.player.life as usize * 40) / self.player.max_life as usize), 8)); + } + + if self.player.air_counter > 0 { + let rect = if self.player.air % 30 > 10 { + Rect::new_size(112, 72, 32, 8) + } else { + Rect::new_size(112, 80, 32, 8) + }; + + batch.add_rect((state.canvas_size.0 / 2.0).floor() - 40.0, + (state.canvas_size.1 / 2.0).floor(), &rect); } batch.draw(ctx)?; @@ -192,6 +203,12 @@ impl GameScene { batch.draw(ctx)?; + if self.player.air_counter > 0 && self.player.air_counter % 6 < 4 { + self.draw_number((state.canvas_size.0 / 2.0).floor() + 8.0, + (state.canvas_size.1 / 2.0).floor(), + (self.player.air / 10) as usize, Alignment::Left, state, ctx)?; + } + if max_ammo != 0 { self.draw_number(weap_x + 64.0, 16.0, ammo as usize, Alignment::Right, state, ctx)?; self.draw_number(weap_x + 64.0, 24.0, max_ammo as usize, Alignment::Right, state, ctx)?; @@ -1104,9 +1121,6 @@ impl Scene for GameScene { self.player.target_y = self.player.y; self.frame.immediate_update(state, &self.player, &self.stage); - // self.inventory.add_weapon(WeaponType::PolarStar, 0); - // self.inventory.add_xp(120, state); - // self.player.equip.set_booster_2_0(true); Ok(()) }