2020-08-18 16:46:07 +00:00
|
|
|
use crate::player::Player;
|
|
|
|
use crate::stage::Stage;
|
2020-08-19 13:11:34 +00:00
|
|
|
use crate::SharedGameState;
|
2020-08-18 16:46:07 +00:00
|
|
|
|
|
|
|
pub struct Frame {
|
|
|
|
pub x: isize,
|
|
|
|
pub y: isize,
|
|
|
|
pub wait: isize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Frame {
|
2020-08-19 13:11:34 +00:00
|
|
|
pub fn update(&mut self, state: &SharedGameState, player: &Player, stage: &Stage) {
|
|
|
|
if (stage.map.width - 1) * 16 < state.canvas_size.0 as usize {
|
|
|
|
self.x = -(((state.canvas_size.0 as isize - ((stage.map.width - 1) * 16) as isize) * 0x200) / 2);
|
2020-08-18 16:46:07 +00:00
|
|
|
} else {
|
2020-08-19 13:11:34 +00:00
|
|
|
self.x += (player.target_x - (state.canvas_size.0 as isize * 0x200 / 2) - self.x) / self.wait;
|
2020-08-18 16:46:07 +00:00
|
|
|
|
|
|
|
if self.x < 0 {
|
|
|
|
self.x = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-19 13:11:34 +00:00
|
|
|
let max_x = (((stage.map.width as isize - 1) * 16) - state.canvas_size.0 as isize) * 0x200;
|
2020-08-18 16:46:07 +00:00
|
|
|
if self.x > max_x {
|
|
|
|
self.x = max_x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 13:11:34 +00:00
|
|
|
if (stage.map.height - 1) * 16 < state.canvas_size.1 as usize {
|
|
|
|
self.y = -(((state.canvas_size.1 as isize - ((stage.map.height - 1) * 16) as isize) * 0x200) / 2);
|
2020-08-18 16:46:07 +00:00
|
|
|
} else {
|
2020-08-19 13:11:34 +00:00
|
|
|
self.y += (player.target_y - (state.canvas_size.1 as isize * 0x200 / 2) - self.y) / self.wait;
|
2020-08-18 16:46:07 +00:00
|
|
|
|
|
|
|
if self.y < 0 {
|
|
|
|
self.y = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-19 13:11:34 +00:00
|
|
|
let max_y = (((stage.map.height as isize - 1) * 16) - state.canvas_size.1 as isize) * 0x200;
|
2020-08-18 16:46:07 +00:00
|
|
|
if self.y > max_y {
|
|
|
|
self.y = max_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo quake
|
|
|
|
}
|
|
|
|
}
|