use crate::config::CONFIG;
use bracket_lib::terminal::BTerm;
pub(crate) struct Bird {
height: f64,
speed: f64,
}
impl Bird {
pub fn new() -> Bird {
Bird {
height: CONFIG.height as f64 / 2.,
speed: 0.,
}
}
pub fn init(&mut self) {
self.height = CONFIG.height as f64 / 2.;
self.speed = 0.;
}
pub fn get_height(&self) -> f64 {
self.height
}
pub fn update(&mut self) {
self.height += self.speed;
self.speed -= CONFIG.gravity;
}
pub fn flap(&mut self) {
if self.speed < CONFIG.flap_speed {
self.speed = CONFIG.flap_speed;
}
}
pub fn print(&self, ctx: &mut BTerm) {
ctx.print_centered((CONFIG.height as f64 - self.get_height()) as i32, "bird");
}
}