2020-09-23 11:31:43 +00:00
|
|
|
use std::fs::read_to_string;
|
|
|
|
|
2020-08-20 18:31:47 +00:00
|
|
|
use crate::bitfield;
|
2020-12-05 21:44:15 +00:00
|
|
|
use crate::common::{Condition, Direction, Rect, CDEG_RAD};
|
2020-08-20 18:31:47 +00:00
|
|
|
use crate::engine_constants::EngineConstants;
|
2020-08-21 05:27:26 +00:00
|
|
|
use crate::rng::RNG;
|
2020-08-20 18:31:47 +00:00
|
|
|
|
|
|
|
#[derive(Debug, EnumIter, PartialEq, Eq, Hash, Copy, Clone)]
|
|
|
|
pub enum CaretType {
|
|
|
|
None,
|
|
|
|
Bubble,
|
|
|
|
ProjectileDissipation,
|
|
|
|
Shoot,
|
|
|
|
SnakeAfterimage,
|
|
|
|
Zzz,
|
|
|
|
SnakeAfterimage2,
|
|
|
|
Exhaust,
|
|
|
|
DrownedQuote,
|
|
|
|
QuestionMark,
|
|
|
|
LevelUp,
|
|
|
|
HurtParticles,
|
|
|
|
Explosion,
|
2020-08-21 05:27:26 +00:00
|
|
|
LittleParticles,
|
2020-08-20 18:31:47 +00:00
|
|
|
Unknown,
|
|
|
|
SmallProjectileDissipation,
|
|
|
|
Empty,
|
|
|
|
PushJumpKey,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Caret {
|
|
|
|
pub ctype: CaretType,
|
|
|
|
pub x: isize,
|
|
|
|
pub y: isize,
|
|
|
|
pub vel_x: isize,
|
|
|
|
pub vel_y: isize,
|
|
|
|
pub offset_x: isize,
|
|
|
|
pub offset_y: isize,
|
2020-11-07 17:17:01 +00:00
|
|
|
pub prev_x: isize,
|
|
|
|
pub prev_y: isize,
|
2020-09-05 04:43:14 +00:00
|
|
|
pub cond: Condition,
|
|
|
|
pub direction: Direction,
|
2020-11-17 02:42:45 +00:00
|
|
|
pub anim_rect: Rect<u16>,
|
2020-12-05 21:44:15 +00:00
|
|
|
action_num: u16,
|
2020-09-12 00:42:44 +00:00
|
|
|
anim_num: u16,
|
|
|
|
anim_counter: u16,
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Caret {
|
2020-09-12 00:42:44 +00:00
|
|
|
pub fn new(x: isize, y: isize, ctype: CaretType, direct: Direction, constants: &EngineConstants) -> Caret {
|
2020-08-20 18:31:47 +00:00
|
|
|
let (offset_x, offset_y) = constants.caret.offsets[ctype as usize];
|
2020-09-12 00:42:44 +00:00
|
|
|
|
|
|
|
Caret {
|
2020-08-20 18:31:47 +00:00
|
|
|
ctype,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
vel_x: 0,
|
|
|
|
vel_y: 0,
|
|
|
|
offset_x,
|
|
|
|
offset_y,
|
2020-11-07 17:17:01 +00:00
|
|
|
prev_x: x,
|
|
|
|
prev_y: y,
|
2020-09-05 04:43:14 +00:00
|
|
|
cond: Condition(0x80),
|
|
|
|
direction: direct,
|
2020-09-12 00:42:44 +00:00
|
|
|
anim_rect: Rect::new(0, 0, 0, 0),
|
2020-12-05 21:44:15 +00:00
|
|
|
action_num: 0,
|
2020-08-20 18:31:47 +00:00
|
|
|
anim_num: 0,
|
2020-09-05 04:43:14 +00:00
|
|
|
anim_counter: 0,
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 05:27:26 +00:00
|
|
|
pub fn tick(&mut self, rng: &RNG, constants: &EngineConstants) {
|
2020-08-20 18:31:47 +00:00
|
|
|
match self.ctype {
|
|
|
|
CaretType::None => {}
|
|
|
|
CaretType::Bubble => {}
|
2020-09-12 00:42:44 +00:00
|
|
|
CaretType::ProjectileDissipation => {
|
|
|
|
match self.direction {
|
|
|
|
Direction::Left => {
|
|
|
|
self.vel_y -= 0x10;
|
|
|
|
self.y += self.vel_y;
|
|
|
|
|
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 5 {
|
|
|
|
self.anim_counter = 0;
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
2020-09-12 04:43:29 +00:00
|
|
|
if self.anim_num >= constants.caret.projectile_dissipation_left_rects.len() as u16 {
|
2020-09-12 00:42:44 +00:00
|
|
|
self.cond.set_alive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_rect = constants.caret.projectile_dissipation_left_rects[self.anim_num as usize];
|
|
|
|
}
|
2020-09-23 11:31:43 +00:00
|
|
|
}
|
2020-09-12 00:42:44 +00:00
|
|
|
Direction::Up => {
|
|
|
|
self.anim_counter += 1;
|
|
|
|
|
|
|
|
if self.anim_counter > 24 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
let len = constants.caret.projectile_dissipation_up_rects.len();
|
|
|
|
self.anim_rect = constants.caret.projectile_dissipation_up_rects[(self.anim_num as usize / 2) % len];
|
2020-09-23 11:31:43 +00:00
|
|
|
}
|
2020-09-12 00:42:44 +00:00
|
|
|
Direction::Right => {
|
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 2 {
|
|
|
|
self.anim_counter = 0;
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
2020-09-12 04:43:29 +00:00
|
|
|
if self.anim_num >= constants.caret.projectile_dissipation_right_rects.len() as u16 {
|
2020-09-12 00:42:44 +00:00
|
|
|
self.cond.set_alive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_rect = constants.caret.projectile_dissipation_right_rects[self.anim_num as usize];
|
|
|
|
}
|
2020-09-23 11:31:43 +00:00
|
|
|
}
|
2020-09-12 00:42:44 +00:00
|
|
|
Direction::Bottom => {
|
|
|
|
self.cond.set_alive(false);
|
2020-09-23 11:31:43 +00:00
|
|
|
}
|
2020-09-30 03:11:25 +00:00
|
|
|
Direction::FacingPlayer => unreachable!(),
|
2020-09-12 00:42:44 +00:00
|
|
|
}
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
2020-09-12 00:42:44 +00:00
|
|
|
CaretType::Shoot => {
|
|
|
|
if self.anim_counter == 0 {
|
|
|
|
self.anim_rect = constants.caret.shoot_rects[self.anim_num as usize];
|
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 3 {
|
|
|
|
self.anim_counter = 0;
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
2020-09-12 04:43:29 +00:00
|
|
|
if self.anim_num >= constants.caret.shoot_rects.len() as u16 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
}
|
2020-09-12 00:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CaretType::SnakeAfterimage | CaretType::SnakeAfterimage2 => {} // dupe, unused
|
2020-09-05 04:43:14 +00:00
|
|
|
CaretType::Zzz => {
|
|
|
|
if self.anim_counter == 0 {
|
2020-09-12 00:42:44 +00:00
|
|
|
self.anim_rect = constants.caret.zzz_rects[self.anim_num as usize];
|
2020-09-05 04:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 4 {
|
|
|
|
self.anim_counter = 0;
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
2020-09-12 04:43:29 +00:00
|
|
|
if self.anim_num >= constants.caret.zzz_rects.len() as u16 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
return;
|
|
|
|
}
|
2020-09-05 04:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.x += 0x80; // 0.4fix9
|
|
|
|
self.y -= 0x80;
|
|
|
|
}
|
2020-08-20 18:31:47 +00:00
|
|
|
CaretType::Exhaust => {
|
2020-09-12 00:42:44 +00:00
|
|
|
if self.anim_counter == 0 {
|
|
|
|
self.anim_rect = constants.caret.exhaust_rects[self.anim_num as usize];
|
|
|
|
}
|
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 1 {
|
|
|
|
self.anim_counter = 0;
|
2020-08-20 18:31:47 +00:00
|
|
|
self.anim_num += 1;
|
|
|
|
|
2020-09-12 00:42:44 +00:00
|
|
|
if self.anim_num >= constants.caret.exhaust_rects.len() as u16 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
return;
|
|
|
|
}
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
match self.direction {
|
2020-09-30 03:11:25 +00:00
|
|
|
Direction::Left => self.x -= 0x400, // 2.0fix9
|
|
|
|
Direction::Up => self.y -= 0x400,
|
|
|
|
Direction::Right => self.x += 0x400,
|
|
|
|
Direction::Bottom => self.y += 0x400,
|
|
|
|
Direction::FacingPlayer => unreachable!(),
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-05 04:43:14 +00:00
|
|
|
CaretType::DrownedQuote => {
|
|
|
|
if self.anim_counter == 0 {
|
|
|
|
self.anim_counter = 1;
|
|
|
|
|
|
|
|
match self.direction {
|
2020-09-30 03:11:25 +00:00
|
|
|
Direction::Left => self.anim_rect = constants.caret.drowned_quote_left_rect,
|
|
|
|
Direction::Right => self.anim_rect = constants.caret.drowned_quote_right_rect,
|
|
|
|
Direction::FacingPlayer => unreachable!(),
|
2020-09-05 04:43:14 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 18:31:47 +00:00
|
|
|
CaretType::QuestionMark => {
|
2020-09-05 04:43:14 +00:00
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter < 5 {
|
2020-08-23 02:17:24 +00:00
|
|
|
self.y -= 0x800; // 4.0fix9
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
if self.anim_counter == 32 {
|
|
|
|
self.cond.set_alive(false);
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
self.anim_rect = match self.direction {
|
2020-08-20 18:31:47 +00:00
|
|
|
Direction::Left => { constants.caret.question_left_rect }
|
|
|
|
Direction::Right => { constants.caret.question_right_rect }
|
|
|
|
_ => { self.anim_rect }
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 11:31:43 +00:00
|
|
|
CaretType::LevelUp => {
|
|
|
|
self.anim_counter += 1;
|
|
|
|
|
|
|
|
if self.anim_counter == 80 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
match self.direction {
|
|
|
|
Direction::Left => {
|
|
|
|
if self.anim_counter < 20 {
|
|
|
|
self.y -= 0x400; // 2.0fix9
|
|
|
|
}
|
|
|
|
|
|
|
|
let count = constants.caret.level_up_rects.len();
|
|
|
|
self.anim_rect = constants.caret.level_up_rects[self.anim_counter as usize / 2 % count]
|
|
|
|
}
|
|
|
|
Direction::Right => {
|
|
|
|
if self.anim_counter < 20 {
|
|
|
|
self.y -= 0x200; // 2.0fix9
|
|
|
|
}
|
|
|
|
|
|
|
|
let count = constants.caret.level_down_rects.len();
|
|
|
|
self.anim_rect = constants.caret.level_down_rects[self.anim_counter as usize / 2 % count]
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2020-12-05 21:44:15 +00:00
|
|
|
CaretType::HurtParticles => {
|
|
|
|
if self.action_num == 0 {
|
|
|
|
self.action_num = 1;
|
|
|
|
let angle = rng.range(0..255) as f64 * CDEG_RAD;
|
|
|
|
self.vel_x = (angle.cos() * 1024.0) as isize;
|
|
|
|
self.vel_y = (angle.sin() * 1024.0) as isize;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.x += self.vel_x;
|
|
|
|
self.y += self.vel_y;
|
|
|
|
|
|
|
|
if self.anim_counter == 0 {
|
|
|
|
self.anim_rect = constants.caret.hurt_particles_rects[self.anim_num as usize];
|
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 2 {
|
|
|
|
self.anim_counter = 0;
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
|
|
|
if self.anim_num >= constants.caret.hurt_particles_rects.len() as u16 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-12 04:43:29 +00:00
|
|
|
CaretType::Explosion => {
|
|
|
|
if self.anim_counter == 0 {
|
|
|
|
self.anim_rect = constants.caret.explosion_rects[self.anim_num as usize];
|
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 2 {
|
|
|
|
self.anim_counter = 0;
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
|
|
|
if self.anim_num >= constants.caret.explosion_rects.len() as u16 {
|
|
|
|
self.cond.set_alive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-21 05:27:26 +00:00
|
|
|
CaretType::LittleParticles => {
|
|
|
|
if self.anim_num == 0 {
|
2020-09-05 04:43:14 +00:00
|
|
|
match self.direction {
|
2020-08-21 05:27:26 +00:00
|
|
|
Direction::Left => {
|
2020-10-30 13:50:10 +00:00
|
|
|
self.vel_x = rng.range(-0x600..0x600) as isize; // -3.0fix9..3.0fix9
|
|
|
|
self.vel_y = rng.range(-0x200..0x200) as isize; // -1.0fix9..1.0fix9
|
2020-08-21 05:27:26 +00:00
|
|
|
}
|
|
|
|
Direction::Up => {
|
2020-10-30 13:50:10 +00:00
|
|
|
self.vel_y = rng.range(-3..-1) as isize * 0x200;
|
2020-08-21 05:27:26 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.anim_num += 1;
|
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
if self.direction == Direction::Left {
|
2020-08-21 05:27:26 +00:00
|
|
|
self.vel_x = (self.vel_x * 4) / 5;
|
|
|
|
self.vel_y = (self.vel_y * 4) / 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.x += self.vel_x;
|
|
|
|
self.y += self.vel_y;
|
|
|
|
|
2020-10-30 13:50:10 +00:00
|
|
|
self.anim_counter += 1;
|
|
|
|
if self.anim_counter > 20 {
|
2020-09-05 04:43:14 +00:00
|
|
|
self.cond.set_alive(false);
|
2020-08-21 05:27:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-12 00:42:44 +00:00
|
|
|
let len = constants.caret.little_particles_rects.len();
|
|
|
|
self.anim_rect = constants.caret.little_particles_rects[self.anim_num as usize / 2 % len];
|
2020-08-21 05:27:26 +00:00
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
if self.direction == Direction::Right {
|
2020-08-21 05:27:26 +00:00
|
|
|
self.x -= 4 * 0x200;
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 18:31:47 +00:00
|
|
|
CaretType::Unknown => {
|
|
|
|
// not implemented because it was apparently broken in og game?
|
2020-09-05 04:43:14 +00:00
|
|
|
self.cond.set_alive(false);
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
CaretType::SmallProjectileDissipation => {}
|
|
|
|
CaretType::Empty => {}
|
|
|
|
CaretType::PushJumpKey => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 04:43:14 +00:00
|
|
|
#[inline]
|
2020-08-20 18:31:47 +00:00
|
|
|
pub fn is_dead(&self) -> bool {
|
2020-09-05 04:43:14 +00:00
|
|
|
!self.cond.alive()
|
2020-08-20 18:31:47 +00:00
|
|
|
}
|
|
|
|
}
|