1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-19 04:02:47 +00:00
doukutsu-rs/src/entity.rs

54 lines
1.8 KiB
Rust
Raw Normal View History

2021-04-19 19:19:55 +00:00
use crate::common::interpolate_fix9_scale;
use crate::frame::Frame;
2021-01-27 18:20:47 +00:00
use crate::framework::context::Context;
use crate::framework::error::GameResult;
use crate::shared_game_state::SharedGameState;
2020-08-18 16:46:07 +00:00
2020-09-05 02:09:52 +00:00
pub trait GameEntity<C> {
fn tick(&mut self, state: &mut SharedGameState, custom: C) -> GameResult;
2020-08-18 16:46:07 +00:00
2020-08-19 13:11:34 +00:00
fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult;
2020-08-18 16:46:07 +00:00
}
2021-04-19 19:19:55 +00:00
pub trait Interpolatable {
fn position_x(&self) -> i32;
fn position_y(&self) -> i32;
fn prev_position_x(&self) -> i32;
fn prev_position_y(&self) -> i32;
fn draw_tick(&mut self);
#[inline]
fn interpolate_x(&self, frame_delta: f64) -> f32 {
interpolate_fix9_scale(self.prev_position_x(), self.position_x(), frame_delta)
}
#[inline]
fn interpolate_y(&self, frame_delta: f64) -> f32 {
interpolate_fix9_scale(self.prev_position_y(), self.position_y(), frame_delta)
}
#[inline]
fn interpolate(&self, frame_delta: f64) -> (f32, f32) {
(self.interpolate_x(frame_delta), self.interpolate_y(frame_delta))
}
#[inline]
fn interpolate_relative_x(&self, target: &dyn Interpolatable, frame_delta: f64) -> f32 {
interpolate_fix9_scale(self.prev_position_x() - target.prev_position_x(), self.position_x() - target.position_x(), frame_delta)
}
#[inline]
fn interpolate_relative_y(&self, target: &dyn Interpolatable, frame_delta: f64) -> f32 {
interpolate_fix9_scale(self.prev_position_y() - target.prev_position_y(), self.position_y() - target.position_y(), frame_delta)
}
#[inline]
fn interpolate_relative(&self, target: &dyn Interpolatable, frame_delta: f64) -> (f32, f32) {
(self.interpolate_relative_x(target, frame_delta), self.interpolate_relative_y(target, frame_delta))
}
}