use crate::ui::grid::{GRID_CELL_HEIGHT, GRID_CELL_WIDTH, GRID_START_X, GRID_START_Y};
use crate::entities::sun::{Sun, SunType};
use crate::entities::pea::Pea;
use crate::plants::plant_trait::PlantTrait;
use crate::core::resources::Resources;
use ggez::graphics;
use crate::zombies::Zombie;
use rand::Rng;
pub struct Sunflower {
is_first_production: bool,
}
impl Sunflower {
pub fn new() -> Self {
Sunflower {
is_first_production: true,
}
}
}
const INITIAL_HEALTH: i32 = 300;
const COST: i32 = 50;
impl PlantTrait for Sunflower {
fn get_initial_health(&self) -> i32 {
INITIAL_HEALTH
}
fn get_cooldown(&self) -> u64 {
if self.is_first_production {
rand::thread_rng().gen_range(3000..=12500)
} else {
rand::thread_rng().gen_range(23500..=25000)
}
}
fn get_frame_count(&self) -> usize {
18 }
fn update_action(&mut self, grid_x: usize, grid_y: usize, suns: &mut Vec<Sun>, _peas: &mut Vec<Pea>, _zombies: &Vec<Zombie>) {
let sun_x = GRID_START_X + (grid_x as f32) * GRID_CELL_WIDTH + GRID_CELL_WIDTH / 2.0;
let sun_y = GRID_START_Y + (grid_y as f32) * GRID_CELL_HEIGHT;
suns.push(Sun::new(sun_x, sun_y, SunType::SunflowerGeneration));
if self.is_first_production {
self.is_first_production = false;
}
}
fn get_cost(&self) -> i32 {
COST
}
fn get_card_image<'a>(&self, resources: &'a Resources) -> &'a graphics::Image {
&resources.sunflower_card
}
fn get_current_frame_image<'a>(&self, resources: &'a Resources, animation_frame: usize) -> &'a graphics::Image {
let frame_count = resources.sunflower_images.len();
if frame_count > 0 {
let safe_index = animation_frame % frame_count;
&resources.sunflower_images[safe_index]
} else {
&resources.sunflower_card
}
}
}