diff --git a/src/entities/enemy/base.rs b/src/entities/enemy/base.rs index 04937e6..4fd751f 100644 --- a/src/entities/enemy/base.rs +++ b/src/entities/enemy/base.rs @@ -1,9 +1,9 @@ use raylib::prelude::*; -use crate::player::Player; +use crate::{player::Player, resources::GlobalResources}; pub trait EnemyBase { - fn render(&self, context_2d: &mut RaylibMode2D); + fn render(&self, context_2d: &mut RaylibMode2D, resources: &mut GlobalResources); fn handle_logic(&mut self, player: &mut Player, dt: f64); fn handle_getting_attacked(&mut self); } \ No newline at end of file diff --git a/src/entities/enemy/jellyfish.rs b/src/entities/enemy/jellyfish.rs index 496387f..dbb1af2 100644 --- a/src/entities/enemy/jellyfish.rs +++ b/src/entities/enemy/jellyfish.rs @@ -1,7 +1,7 @@ use super::base::EnemyBase; use raylib::prelude::*; use serde::{Deserialize, Serialize}; -use crate::player::Player; +use crate::{player::Player, resources::GlobalResources}; #[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct JellyFish { @@ -17,10 +17,13 @@ impl JellyFish { } impl EnemyBase for JellyFish { - fn render(&self, context_2d: &mut raylib::prelude::RaylibMode2D) { + fn render(&self, context_2d: &mut raylib::prelude::RaylibMode2D, resources: &mut GlobalResources) { + + // Render the jellyfish + resources.jellyfish_animation_regular.draw(context_2d, self.position, 0.0); - // TODO - context_2d.draw_circle_v(self.position, 5.0, Color::RED); + // // TODO + // context_2d.draw_circle_v(self.position, 5.0, Color::RED); } fn handle_logic(&mut self, player: &mut Player, dt: f64) { diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 26e69b0..ccc51ed 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -121,7 +121,7 @@ impl Screen for InGameScreen { fish.render(&mut context_2d); } for jellyfish in game_core.world.jellyfish.iter() { - jellyfish.render(&mut context_2d); + jellyfish.render(&mut context_2d, &mut game_core.resources); } // Render Player diff --git a/src/resources.rs b/src/resources.rs index b88c5a4..be40c14 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -18,7 +18,10 @@ pub struct GlobalResources { pub player_animation_boost: FrameAnimationWrapper, // Cave - pub cave_mid_layer: Texture2D + pub cave_mid_layer: Texture2D, + + // Enemies + pub jellyfish_animation_regular: FrameAnimationWrapper } impl GlobalResources { @@ -63,6 +66,15 @@ impl GlobalResources { &thread, &Image::load_image("./assets/img/map/cave.png")?, )?, + jellyfish_animation_regular: FrameAnimationWrapper::new( + raylib.load_texture_from_image( + &thread, + &Image::load_image("./assets/img/enemies/jelly.png")?, + )?, + Vector2 { x: 10.0, y: 10.0 }, + 6, + 4, + ), }) } }