# HG changeset patch # User Emmanuel Gil Peyrot # Date 1565307407 -7200 # Node ID ff7b6355cdf192a511ac1f1a3f006acdc5621527 # Parent 988e5130fb00e0f54447fcb2ee0d93e60b37b7f5 Port the Enemy struct from Python, for now without its methods. diff --git a/Cargo.toml b/Cargo.toml --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,6 @@ luminance-derive = { version = "*", path [profile.dev] panic = "abort" + +[profile.release] +panic = "abort" diff --git a/src/th06/enemy.rs b/src/th06/enemy.rs new file mode 100644 --- /dev/null +++ b/src/th06/enemy.rs @@ -0,0 +1,150 @@ +//! Module providing an Enemy struct, to be changed by EclRunner. + +use crate::th06::anm0::Anm0; +use crate::th06::anm0_vm::{Sprite, AnmRunner}; +use crate::th06::interpolator::{Interpolator1, Interpolator2}; +use crate::util::prng::Prng; +use std::cell::RefCell; +use std::collections::HashMap; +use std::rc::{Rc, Weak}; + +#[derive(Debug, Clone, Copy)] +struct Position { + x: f32, + y: f32, +} + +#[derive(Debug, Clone, Copy)] +struct Offset { + dx: f32, + dy: f32, +} + +impl Position { + pub fn new(x: f32, y: f32) -> Position { + Position { x, y } + } +} + +impl Offset { + pub fn new(dx: f32, dy: f32) -> Offset { + Offset { dx, dy } + } +} + +impl std::ops::Add for Position { + type Output = Position; + fn add(self, offset: Offset) -> Position { + Position { + x: self.x + offset.dx, + y: self.y + offset.dy, + } + } +} + +#[derive(Debug, Clone)] +struct Callback; + +#[derive(Debug, Clone)] +struct Laser; + +#[derive(Debug, Clone)] +struct Process; + +struct Game { + enemies: Vec, + prng: Rc>, +} + +/// Common to all elements in game. +struct Element { + pos: Position, + removed: bool, + sprite: Weak>, + anmrunner: AnmRunner, +} + +/// The enemy struct, containing everything pertaining to an enemy. +pub struct Enemy { + // Common to all elements in game. + pos: Position, + removed: bool, + sprite: Rc>, + anmrunner: Rc>, + + // Specific to enemy. + // Floats. + z: f32, + angle: f32, + speed: f32, + rotation_speed: f32, + acceleration: f32, + + // Ints. + type_: u32, + bonus_dropped: u32, + die_score: u32, + frame: u32, + life: u32, + death_flags: u32, + current_laser_id: u32, + low_life_trigger: u32, + timeout: u32, + remaining_lives: u32, + bullet_launch_interval: u32, + bullet_launch_timer: u32, + death_anim: u32, + direction: u32, + update_mode: u32, + + // Bools. + visible: bool, + was_visible: bool, + touchable: bool, + collidable: bool, + damageable: bool, + boss: bool, + automatic_orientation: bool, + delay_attack: bool, + + // Tuples. + difficulty_coeffs: (f32, f32, u32, u32, u32, u32), + extended_bullet_attributes: Option<(u32, u32, u32, u32, f32, f32, f32, f32)>, + bullet_attributes: Option<(i16, i16, u32, u32, u32, f32, f32, f32, f32, u32)>, + bullet_launch_offset: Offset, + movement_dependant_sprites: Option<(f32, f32, f32, f32)>, + screen_box: Option<(f32, f32, f32, f32)>, + + // Callbacks. + death_callback: Option, + boss_callback: Option, + low_life_callback: Option, + timeout_callback: Option, + + // Laser. + laser_by_id: HashMap, + + // Options. + options: Vec, + + // Interpolators. + interpolator: Option>, + speed_interpolator: Option>, + + // Misc stuff, do we need them? + anm0: Weak>, + process: Rc>, + game: Weak>, + prng: Weak>, + hitbox_half_size: (f32, f32), +} + +impl Enemy { + /// Sets the animation to the one indexed by index in the current anm0. + pub fn set_anim(&mut self, index: u8) { + self.sprite = Rc::new(RefCell::new(Sprite::new())); + let anm0 = self.anm0.upgrade().unwrap(); + let anmrunner = AnmRunner::new(&*anm0.borrow(), index, self.sprite.clone(), self.prng.clone(), 0); + self.anmrunner = Rc::new(RefCell::new(anmrunner)); + } +} diff --git a/src/th06/mod.rs b/src/th06/mod.rs --- a/src/th06/mod.rs +++ b/src/th06/mod.rs @@ -4,4 +4,5 @@ pub mod pbg3; pub mod anm0; pub mod anm0_vm; pub mod ecl; +pub mod enemy; pub mod interpolator;