Pufferfish added

This commit is contained in:
wm-c 2021-04-26 18:24:16 -04:00
parent 1494b188c8
commit 67899182a4
5 changed files with 250 additions and 39 deletions

View File

@ -188,14 +188,93 @@
"pufferfish": [ "pufferfish": [
{ {
"position" : { "position" : {
"x": 400, "x": 261,
"y": 150 "y": 387
}, },
"is_knocking_back": false, "is_knocking_back": false,
"time_knocking_back": 0.0, "time_knocking_back": 0.0,
"inflate_timer": 0.0, "inflate_timer": 0.0,
"size": 6.0, "is_large": false,
"is_stunned": false "stun_timer": 0.0,
"puffer_state": "SmallIdle"
},
{
"position" : {
"x": 195,
"y": 694
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
},
{
"position" : {
"x": 635,
"y": 731
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
},
{
"position" : {
"x": 169,
"y": 1104
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
},
{
"position" : {
"x": 478,
"y": 1333
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
},
{
"position" : {
"x": 499,
"y": 1775
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
},
{
"position" : {
"x": 74,
"y": 1259
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
} }

View File

@ -2,22 +2,31 @@ use raylib::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{lib::utils::calculate_linear_slide, pallette::TRANSLUCENT_RED_64};
use super::base::EnemyBase; use super::base::EnemyBase;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub enum PufferState {
pub struct Pufferfish{ SmallIdle,
pub position: Vector2, Growing,
pub is_knocking_back: bool, LargeIdle,
pub time_knocking_back: f64, Blowing,
pub inflate_timer: f64,
pub size: f32,
pub is_stunned: bool,
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Pufferfish {
pub position: Vector2,
pub is_knocking_back: bool,
pub time_knocking_back: f64,
impl EnemyBase for Pufferfish{ pub inflate_timer: f64,
pub is_large: bool,
pub stun_timer: f64,
pub puffer_state: PufferState,
}
impl EnemyBase for Pufferfish {
fn render( fn render(
&mut self, &mut self,
context_2d: &mut RaylibMode2D<RaylibDrawHandle>, context_2d: &mut RaylibMode2D<RaylibDrawHandle>,
@ -25,42 +34,121 @@ impl EnemyBase for Pufferfish{
resources: &mut crate::resources::GlobalResources, resources: &mut crate::resources::GlobalResources,
dt: f64, dt: f64,
) { ) {
let is_stunned = self.stun_timer > 0.0;
// Render the stun ring
if is_stunned {
println!("Stunned");
let stun_ring_alpha =
calculate_linear_slide(self.stun_timer / 1.0);
context_2d.draw_circle_v(
self.position,
12.0,
TRANSLUCENT_RED_64.fade(0.55 * stun_ring_alpha as f32),
);
self.stun_timer -= dt;
}
let angle = player.position.angle_to(self.position).to_degrees();
match self.puffer_state {
PufferState::SmallIdle => {
resources.pufferfish_small.draw(
context_2d,
Vector2 {
x: self.position.x,
y: self.position.y,
},
angle,
);
context_2d.draw_circle(self.position.x as i32, self.position.y as i32, self.size, Color::RED); if self.position.distance_to(player.position).abs() <= 100.0 && self.inflate_timer > 1.0{
self.puffer_state = PufferState::Growing;
}
self.is_large = false;
},
PufferState::Growing => {
self.inflate_timer = 0.0;
resources.pufferfish_expand.draw(
context_2d,
Vector2 {
x: self.position.x,
y: self.position.y,
},
angle,
);
if resources.pufferfish_expand.get_current_frame_id(context_2d) == 3 {
self.puffer_state = PufferState::LargeIdle;
}
self.is_large = true;
},
PufferState::LargeIdle => {
self.inflate_timer = 0.0;
resources.pufferfish_big.draw(
context_2d,
Vector2 {
x: self.position.x,
y: self.position.y,
},
angle,
);
if self.position.distance_to(player.position).abs() <= 65.0{
self.puffer_state = PufferState::Blowing;
self.is_knocking_back = true;
self.time_knocking_back = 0.0;
}
self.is_large = true;
},
PufferState::Blowing => {
resources.pufferfish_attack.draw(
context_2d,
Vector2 {
x: self.position.x,
y: self.position.y,
},
angle,
);
if resources.pufferfish_expand.get_current_frame_id(context_2d) == 3 && self.inflate_timer > 1.0{
self.puffer_state = PufferState::SmallIdle;
self.inflate_timer = 0.0;
}
self.is_large = false;
},
}
} }
fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) { fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) {
if self.position.distance_to(player.position).abs() <= self.size + 6.0{
self.is_knocking_back = true;
}
if self.is_knocking_back{
self.time_knocking_back += dt;
} self.inflate_timer += dt;
self.time_knocking_back += dt;
if self.time_knocking_back >= 0.5{ if self.time_knocking_back >= 0.5{
self.is_knocking_back = false; self.is_knocking_back = false;
self.time_knocking_back = 0.0;
} }
if self.position.distance_to(player.position).abs() <= 100.0{ if self.position.distance_to(player.position).abs() > 120.0 && self.is_large {
self.inflate_timer += dt; self.puffer_state = PufferState::Blowing;
}else{
self.inflate_timer = 0.0; self.inflate_timer = 0.0;
} }
self.size = (6.0 * (1.0 + self.inflate_timer / 1.0)).clamp(6.0, 12.0) as f32;
} }
fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) { fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) {
} self.stun_timer = stun_duration;
}
}
}

View File

@ -80,7 +80,7 @@ pub fn update_player_movement(
game_core game_core
.player .player
.begin_attack(&mut game_core.world, draw_handle.get_time()); .begin_attack(&mut game_core.world, draw_handle.get_time());
println!("{{\"x\":{}, \"y\":{}}},",f32::round(game_core.player.position.x),f32::round(game_core.player.position.y)); //println!("{{\"x\":{}, \"y\":{}}},",f32::round(game_core.player.position.x),f32::round(game_core.player.position.y));
} }
// Move the player in their direction // Move the player in their direction
@ -214,9 +214,8 @@ pub fn update_player_movement(
// Angle between: UNITS: RADIANS // Angle between: UNITS: RADIANS
let angle = net_pose.y.atan2(net_pose.x); let angle = net_pose.y.atan2(net_pose.x);
// Calculates force // Calculates force
let force = 1.0 / game_core.player.position.distance_to(pufferfish.position); let force = 1.0;
// Calculates componets of force // Calculates componets of force
let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0); let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0);

View File

@ -103,6 +103,11 @@ impl Player {
if whirlpool.position.distance_to(self.position).abs() <= stun_reach { if whirlpool.position.distance_to(self.position).abs() <= stun_reach {
whirlpool.handle_getting_attacked(self.attacking_timer, current_time); whirlpool.handle_getting_attacked(self.attacking_timer, current_time);
} }
}
for pufferfish in world.pufferfish.iter_mut() {
if pufferfish.position.distance_to(self.position).abs() <= stun_reach {
pufferfish.handle_getting_attacked(self.attacking_timer, current_time);
}
} }
} }
} }

View File

@ -33,6 +33,10 @@ pub struct GlobalResources {
pub octopus_animation_regular: FrameAnimationWrapper, pub octopus_animation_regular: FrameAnimationWrapper,
pub octopus_animation_attack: FrameAnimationWrapper, pub octopus_animation_attack: FrameAnimationWrapper,
pub whirlpool: FrameAnimationWrapper, pub whirlpool: FrameAnimationWrapper,
pub pufferfish_big: FrameAnimationWrapper,
pub pufferfish_small: FrameAnimationWrapper,
pub pufferfish_attack: FrameAnimationWrapper,
pub pufferfish_expand: FrameAnimationWrapper,
// Darkness layer // Darkness layer
pub darkness_overlay: Texture2D, pub darkness_overlay: Texture2D,
@ -257,6 +261,42 @@ impl GlobalResources {
4, 4,
4, 4,
), ),
pufferfish_big: FrameAnimationWrapper::new(
raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/enemies/pufferFishBigIdle.png")?,
)?,
Vector2 { x: 19.0, y: 19.0 },
3,
2,
),
pufferfish_small: FrameAnimationWrapper::new(
raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/enemies/pufferFishIdle.png")?,
)?,
Vector2 { x: 19.0, y: 19.0 },
6,
2,
),
pufferfish_attack: FrameAnimationWrapper::new(
raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/enemies/pufferFishAttack.png")?,
)?,
Vector2 { x: 39.0, y: 25.0 },
4,
2,
),
pufferfish_expand: FrameAnimationWrapper::new(
raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/enemies/pufferFishExpand.png")?,
)?,
Vector2 { x: 19.0, y: 19.0 },
4,
2,
),
}) })
} }
} }