diff --git a/src/caret.rs b/src/caret.rs index b6fa376..c2a2c72 100644 --- a/src/caret.rs +++ b/src/caret.rs @@ -1,15 +1,8 @@ use crate::bitfield; -use crate::common::{Direction, Rect}; +use crate::common::{Condition, Direction, Rect}; use crate::engine_constants::EngineConstants; use crate::rng::RNG; -bitfield! { - pub struct Cond(u16); - impl Debug; - - pub visible, set_visible: 7; -} - #[derive(Debug, EnumIter, PartialEq, Eq, Hash, Copy, Clone)] pub enum CaretType { None, @@ -40,11 +33,11 @@ pub struct Caret { pub vel_y: isize, pub offset_x: isize, pub offset_y: isize, - pub cond: Cond, - pub direct: Direction, + pub cond: Condition, + pub direction: Direction, pub anim_rect: Rect, anim_num: usize, - anim_wait: isize, + anim_counter: isize, } impl Caret { @@ -58,11 +51,11 @@ impl Caret { vel_y: 0, offset_x, offset_y, - cond: Cond(0x80), - direct, + cond: Condition(0x80), + direction: direct, anim_rect: Rect::::new(0, 0, 0, 0), anim_num: 0, - anim_wait: 0, + anim_counter: 0, } } @@ -74,40 +67,67 @@ impl Caret { CaretType::Shoot => {} CaretType::SnakeAfterimage | CaretType::SnakeAfterimage2 => { // dupe, unused } - CaretType::Zzz => {} + CaretType::Zzz => { + if self.anim_counter == 0 { + self.anim_rect = constants.caret.zzz_rects[self.anim_num]; + } + + self.anim_counter += 1; + if self.anim_counter > 4 { + self.anim_counter = 0; + self.anim_num += 1; + } + + if self.anim_num == constants.caret.zzz_rects.len() { + self.cond.set_alive(false); + } + + self.x += 0x80; // 0.4fix9 + self.y -= 0x80; + } CaretType::Exhaust => { - self.anim_wait += 1; - if self.anim_wait > 1 { - self.anim_wait = 0; + self.anim_counter += 1; + if self.anim_counter > 1 { + self.anim_counter = 0; self.anim_num += 1; } if self.anim_num >= constants.caret.exhaust_rects.len() { - self.cond.set_visible(false); + self.cond.set_alive(false); return; } self.anim_rect = constants.caret.exhaust_rects[self.anim_num]; - match self.direct { + match self.direction { Direction::Left => { self.x -= 0x400; } // 2.0fix9 Direction::Up => { self.y -= 0x400; } Direction::Right => { self.x += 0x400; } Direction::Bottom => { self.y += 0x400; } } } - CaretType::DrownedQuote => {} + CaretType::DrownedQuote => { + if self.anim_counter == 0 { + self.anim_counter = 1; + + match self.direction { + Direction::Left => { self.anim_rect = constants.caret.drowned_quote_left_rect; } + Direction::Right => { self.anim_rect = constants.caret.drowned_quote_right_rect; } + _ => {} + } + } + } CaretType::QuestionMark => { - self.anim_wait += 1; - if self.anim_wait < 5 { + self.anim_counter += 1; + if self.anim_counter < 5 { self.y -= 0x800; // 4.0fix9 } - if self.anim_wait == 32 { - self.cond.set_visible(false); + if self.anim_counter == 32 { + self.cond.set_alive(false); } - self.anim_rect = match self.direct { + self.anim_rect = match self.direction { Direction::Left => { constants.caret.question_left_rect } Direction::Right => { constants.caret.question_right_rect } _ => { self.anim_rect } @@ -118,7 +138,7 @@ impl Caret { CaretType::Explosion => {} CaretType::LittleParticles => { if self.anim_num == 0 { - match self.direct { + match self.direction { Direction::Left => { self.vel_x = rng.range(-0x300..0x300) as isize; // -1.5fix9..1.5fix9 self.vel_y = rng.range(-0x100..0x100) as isize; // -0.5fix9..0.5fix9 @@ -132,7 +152,7 @@ impl Caret { self.anim_num += 1; - if self.direct == Direction::Left { + if self.direction == Direction::Left { self.vel_x = (self.vel_x * 4) / 5; self.vel_y = (self.vel_y * 4) / 5; } @@ -141,19 +161,19 @@ impl Caret { self.y += self.vel_y; if self.anim_num == 20 { - self.cond.set_visible(false); + self.cond.set_alive(false); return; } self.anim_rect = constants.caret.little_particles_rects[self.anim_num / 2 % constants.caret.little_particles_rects.len()]; - if self.direct == Direction::Right { + if self.direction == Direction::Right { self.x -= 4 * 0x200; } } CaretType::Unknown => { // not implemented because it was apparently broken in og game? - self.cond.set_visible(false); + self.cond.set_alive(false); } CaretType::SmallProjectileDissipation => {} CaretType::Empty => {} @@ -161,7 +181,8 @@ impl Caret { } } + #[inline] pub fn is_dead(&self) -> bool { - !self.cond.visible() + !self.cond.alive() } } diff --git a/src/engine_constants.rs b/src/engine_constants.rs index cdf3a4b..411d3f1 100644 --- a/src/engine_constants.rs +++ b/src/engine_constants.rs @@ -49,6 +49,11 @@ pub struct CaretConsts { pub offsets: [(isize, isize); 18], pub bubble_left_rects: Vec>, pub bubble_right_rects: Vec>, + pub zzz_rects: Vec>, + pub drowned_quote_left_rect: Rect, + pub drowned_quote_right_rect: Rect, + pub level_up_rects: Vec>, + pub level_down_rects: Vec>, pub little_particles_rects: Vec>, pub exhaust_rects: Vec>, pub question_left_rect: Rect, @@ -61,6 +66,11 @@ impl Clone for CaretConsts { offsets: self.offsets, bubble_left_rects: self.bubble_left_rects.clone(), bubble_right_rects: self.bubble_right_rects.clone(), + zzz_rects: self.zzz_rects.clone(), + drowned_quote_left_rect: self.drowned_quote_left_rect, + drowned_quote_right_rect: self.drowned_quote_right_rect, + level_up_rects: self.level_up_rects.clone(), + level_down_rects: self.level_down_rects.clone(), little_particles_rects: self.little_particles_rects.clone(), exhaust_rects: self.exhaust_rects.clone(), question_left_rect: self.question_left_rect, @@ -239,6 +249,25 @@ impl EngineConstants { Rect { left: 80, top: 24, right: 88, bottom: 32 }, Rect { left: 88, top: 24, right: 96, bottom: 32 }, ], + zzz_rects: vec![ + Rect { left: 32, top: 64, right: 40, bottom: 72 }, + Rect { left: 32, top: 72, right: 40, bottom: 80 }, + Rect { left: 40, top: 64, right: 48, bottom: 72 }, + Rect { left: 40, top: 72, right: 48, bottom: 80 }, + Rect { left: 40, top: 64, right: 48, bottom: 72 }, + Rect { left: 40, top: 72, right: 48, bottom: 80 }, + Rect { left: 40, top: 64, right: 48, bottom: 72 }, + ], + drowned_quote_left_rect: Rect { left: 16, top: 80, right: 32, bottom: 96 }, + drowned_quote_right_rect: Rect { left: 32, top: 80, right: 48, bottom: 96 }, + level_up_rects: vec![ + Rect { left: 0, top: 0, right: 56, bottom: 16 }, + Rect { left: 0, top: 16, right: 56, bottom: 32 }, + ], + level_down_rects: vec![ + Rect { left: 0, top: 96, right: 56, bottom: 112 }, + Rect { left: 0, top: 112, right: 56, bottom: 128 }, + ], little_particles_rects: vec![ Rect { left: 56, top: 24, right: 64, bottom: 32 }, Rect { left: 0, top: 0, right: 0, bottom: 0 },