This commit is contained in:
Evan Pratten 2021-04-24 17:26:47 -04:00
parent fd8385eec1
commit 707543cf55
5 changed files with 35 additions and 7 deletions

View File

@ -3,7 +3,7 @@ use raylib::prelude::*;
use crate::{player::Player, resources::GlobalResources}; use crate::{player::Player, resources::GlobalResources};
pub trait EnemyBase { pub trait EnemyBase {
fn render(&self, context_2d: &mut RaylibMode2D<RaylibDrawHandle>, resources: &mut GlobalResources); fn render(&mut self, context_2d: &mut RaylibMode2D<RaylibDrawHandle>, resources: &mut GlobalResources);
fn handle_logic(&mut self, player: &mut Player, dt: f64); fn handle_logic(&mut self, player: &mut Player, dt: f64);
fn handle_getting_attacked(&mut self); fn handle_getting_attacked(&mut self);
} }

View File

@ -9,13 +9,16 @@ pub struct JellyFish {
#[serde(skip)] #[serde(skip)]
pub stunned_timer: f64, pub stunned_timer: f64,
#[serde(skip)]
pub do_stun_player: bool
} }
impl JellyFish {} impl JellyFish {}
impl EnemyBase for JellyFish { impl EnemyBase for JellyFish {
fn render( fn render(
&self, &mut self,
context_2d: &mut raylib::prelude::RaylibMode2D<raylib::prelude::RaylibDrawHandle>, context_2d: &mut raylib::prelude::RaylibMode2D<raylib::prelude::RaylibDrawHandle>,
resources: &mut GlobalResources, resources: &mut GlobalResources,
) { ) {
@ -27,14 +30,29 @@ impl EnemyBase for JellyFish {
context_2d, context_2d,
Vector2 { Vector2 {
x: self.position.x, 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, 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) { 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) { fn handle_getting_attacked(&mut self) {

View File

@ -2,7 +2,7 @@ use raylib::{core::color::Color, math::{Rectangle, Vector2}, prelude::{RaylibDra
/// A wrapper around an animation spritesheet /// A wrapper around an animation spritesheet
pub struct FrameAnimationWrapper { pub struct FrameAnimationWrapper {
sprite_sheet: Texture2D, pub sprite_sheet: Texture2D,
size: Vector2, size: Vector2,
frame_count: u32, frame_count: u32,
frames_per_second: u8, frames_per_second: u8,

View File

@ -120,7 +120,7 @@ impl Screen for InGameScreen {
fish.update_position(&mut game_core.player, dt, &fish_clone); fish.update_position(&mut game_core.player, dt, &fish_clone);
fish.render(&mut context_2d); 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); jellyfish.render(&mut context_2d, &mut game_core.resources);
} }

View File

@ -21,7 +21,8 @@ pub struct GlobalResources {
pub cave_mid_layer: Texture2D, pub cave_mid_layer: Texture2D,
// Enemies // Enemies
pub jellyfish_animation_regular: FrameAnimationWrapper pub jellyfish_animation_regular: FrameAnimationWrapper,
pub jellyfish_animation_attack: FrameAnimationWrapper,
} }
impl GlobalResources { impl GlobalResources {
@ -75,6 +76,15 @@ impl GlobalResources {
6, 6,
4, 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,
),
}) })
} }
} }