use crate::{
actor::{
ActParameters, ActorCreateInterface, ActorData, ActorInterface,
HeroTouchEndParameters, HeroTouchStartParameters,
RenderParameters, ShotParameters, ShotProcessing,
},
level::{solids::LevelSolids, tiles::LevelTiles},
Result, ANIMATION_MINE, TILE_HEIGHT, TILE_WIDTH,
};
#[derive(Debug)]
pub(crate) struct Specific {
tile: usize,
counter: u16,
base_y: i32,
}
impl ActorCreateInterface for Specific {
fn create(
general: &mut ActorData,
_solids: &mut LevelSolids,
_tiles: &mut LevelTiles,
) -> Specific {
general.position.resize(TILE_WIDTH, TILE_HEIGHT);
Specific {
tile: ANIMATION_MINE,
counter: 0,
base_y: general.position.y(),
}
}
}
impl ActorInterface for Specific {
fn hero_touch_start(&mut self, p: HeroTouchStartParameters) {
p.general.hurts_hero = true;
}
fn hero_touch_end(&mut self, p: HeroTouchEndParameters) {
p.general.hurts_hero = false;
}
fn act(&mut self, p: ActParameters) {
let distance = match self.counter {
0 => 0,
1 | 11 => 16,
2 | 10 => 28,
3 | 9 => 36,
4 | 8 => 40,
5 | 7 => 41,
6 => 42,
_ => unreachable!(),
};
p.general.position.set_y(self.base_y - distance);
self.counter += 1;
self.counter %= 12;
}
fn render(&mut self, p: RenderParameters) -> Result<()> {
p.renderer
.place_tile(self.tile, p.general.position.top_left())?;
Ok(())
}
fn can_get_shot(&self, _general: &ActorData) -> bool {
true
}
fn shot(&mut self, _p: ShotParameters) -> ShotProcessing {
ShotProcessing::Absorb
}
}