From 707543cf55a3f24bf32cca894740477c1ac00511 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 24 Apr 2021 17:26:47 -0400 Subject: [PATCH] jelly --- src/entities/enemy/base.rs | 2 +- src/entities/enemy/jellyfish.rs | 24 +++++++++++++++++++++--- src/lib/wrappers/animation.rs | 2 +- src/logic/ingame/mod.rs | 2 +- src/resources.rs | 12 +++++++++++- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/entities/enemy/base.rs b/src/entities/enemy/base.rs index 4fd751f..83f7af2 100644 --- a/src/entities/enemy/base.rs +++ b/src/entities/enemy/base.rs @@ -3,7 +3,7 @@ use raylib::prelude::*; use crate::{player::Player, resources::GlobalResources}; pub trait EnemyBase { - fn render(&self, context_2d: &mut RaylibMode2D, resources: &mut GlobalResources); + fn render(&mut 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 72f7061..a657b3b 100644 --- a/src/entities/enemy/jellyfish.rs +++ b/src/entities/enemy/jellyfish.rs @@ -9,13 +9,16 @@ pub struct JellyFish { #[serde(skip)] pub stunned_timer: f64, + + #[serde(skip)] + pub do_stun_player: bool } impl JellyFish {} impl EnemyBase for JellyFish { fn render( - &self, + &mut self, context_2d: &mut raylib::prelude::RaylibMode2D, resources: &mut GlobalResources, ) { @@ -27,14 +30,29 @@ impl EnemyBase for JellyFish { context_2d, Vector2 { x: self.position.x, - y: self.position.y+ (2.0 * v_trans as f32), + y: self.position.y + (2.0 * v_trans as f32), }, 0.0, ); + resources.jellyfish_animation_attack.draw( + context_2d, + Vector2 { + x: self.position.x + , + y: self.position.y + (2.0 * v_trans as f32) + , + }, + 0.0, + ); + self.do_stun_player = resources.jellyfish_animation_attack.get_current_frame_id(context_2d) == 13; } fn handle_logic(&mut self, player: &mut Player, dt: f64) { - todo!() + + // Handle stunning the player + if self.do_stun_player { + + } } fn handle_getting_attacked(&mut self) { diff --git a/src/lib/wrappers/animation.rs b/src/lib/wrappers/animation.rs index 053cf2b..163b70b 100644 --- a/src/lib/wrappers/animation.rs +++ b/src/lib/wrappers/animation.rs @@ -2,7 +2,7 @@ use raylib::{core::color::Color, math::{Rectangle, Vector2}, prelude::{RaylibDra /// A wrapper around an animation spritesheet pub struct FrameAnimationWrapper { - sprite_sheet: Texture2D, + pub sprite_sheet: Texture2D, size: Vector2, frame_count: u32, frames_per_second: u8, diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index ccc51ed..469d761 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -120,7 +120,7 @@ impl Screen for InGameScreen { fish.update_position(&mut game_core.player, dt, &fish_clone); fish.render(&mut context_2d); } - for jellyfish in game_core.world.jellyfish.iter() { + for jellyfish in game_core.world.jellyfish.iter_mut() { jellyfish.render(&mut context_2d, &mut game_core.resources); } diff --git a/src/resources.rs b/src/resources.rs index be40c14..8b8459d 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -21,7 +21,8 @@ pub struct GlobalResources { pub cave_mid_layer: Texture2D, // Enemies - pub jellyfish_animation_regular: FrameAnimationWrapper + pub jellyfish_animation_regular: FrameAnimationWrapper, + pub jellyfish_animation_attack: FrameAnimationWrapper, } impl GlobalResources { @@ -75,6 +76,15 @@ impl GlobalResources { 6, 4, ), + jellyfish_animation_attack: FrameAnimationWrapper::new( + raylib.load_texture_from_image( + &thread, + &Image::load_image("./assets/img/enemies/jellyAttack.png")?, + )?, + Vector2 { x: 20.0, y: 20.0 }, + 15, + 4, + ), }) } }