animate octopus
This commit is contained in:
parent
2fec1a9765
commit
b332f7ffb8
@ -1,4 +1,8 @@
|
|||||||
use crate::{lib::utils::calculate_linear_slide, pallette::{TRANSLUCENT_RED_64, TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64}, player::Player};
|
use crate::{
|
||||||
|
lib::utils::calculate_linear_slide,
|
||||||
|
pallette::{TRANSLUCENT_RED_64, TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64},
|
||||||
|
player::Player,
|
||||||
|
};
|
||||||
|
|
||||||
use super::base::EnemyBase;
|
use super::base::EnemyBase;
|
||||||
use rand::{prelude::ThreadRng, Rng};
|
use rand::{prelude::ThreadRng, Rng};
|
||||||
@ -71,7 +75,8 @@ impl EnemyBase for Octopus {
|
|||||||
|
|
||||||
// Every once in a while, start sucking air
|
// Every once in a while, start sucking air
|
||||||
if (context_2d.get_time() % OCTOPUS_SUCK_AIR_DELAY) < 0.1
|
if (context_2d.get_time() % OCTOPUS_SUCK_AIR_DELAY) < 0.1
|
||||||
&& self.suck_air_time_remaining == 0.0 && !is_octopus_stunned
|
&& self.suck_air_time_remaining == 0.0
|
||||||
|
&& !is_octopus_stunned
|
||||||
{
|
{
|
||||||
self.suck_air_time_remaining = OCTOPUS_SUCK_AIR_DURATION;
|
self.suck_air_time_remaining = OCTOPUS_SUCK_AIR_DURATION;
|
||||||
self.has_taken_air_from_player = false;
|
self.has_taken_air_from_player = false;
|
||||||
@ -107,15 +112,22 @@ impl EnemyBase for Octopus {
|
|||||||
self.suck_air_bubbles.clear();
|
self.suck_air_bubbles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: TMP
|
// Render animation
|
||||||
context_2d.draw_circle_v(self.current_position, 10.0, Color::RED);
|
if self.suck_air_time_remaining > 0.0 {
|
||||||
|
resources
|
||||||
|
.octopus_animation_attack
|
||||||
|
.draw(context_2d, self.current_position, 0.0);
|
||||||
|
} else {
|
||||||
|
resources
|
||||||
|
.octopus_animation_regular
|
||||||
|
.draw(context_2d, self.current_position, 0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.suck_air_time_remaining > 0.0 && !self.has_taken_air_from_player {
|
if self.suck_air_time_remaining > 0.0 && !self.has_taken_air_from_player {
|
||||||
if player.position.distance_to(self.current_position).abs() <= OCTOPUS_SUCK_AIR_RANGE {
|
if player.position.distance_to(self.current_position).abs() <= OCTOPUS_SUCK_AIR_RANGE {
|
||||||
// Take air from the player
|
// Take air from the player
|
||||||
println!("Stealing");
|
|
||||||
player.breath_percent -= OCTOPUS_SUCK_AIR_AMOUNT;
|
player.breath_percent -= OCTOPUS_SUCK_AIR_AMOUNT;
|
||||||
|
|
||||||
// Set the flag
|
// Set the flag
|
||||||
|
@ -26,6 +26,8 @@ pub struct GlobalResources {
|
|||||||
// Enemies
|
// Enemies
|
||||||
pub jellyfish_animation_regular: FrameAnimationWrapper,
|
pub jellyfish_animation_regular: FrameAnimationWrapper,
|
||||||
pub jellyfish_animation_attack: FrameAnimationWrapper,
|
pub jellyfish_animation_attack: FrameAnimationWrapper,
|
||||||
|
pub octopus_animation_regular: FrameAnimationWrapper,
|
||||||
|
pub octopus_animation_attack: FrameAnimationWrapper,
|
||||||
|
|
||||||
// Darkness layer
|
// Darkness layer
|
||||||
pub darkness_overlay: Texture2D,
|
pub darkness_overlay: Texture2D,
|
||||||
@ -124,6 +126,24 @@ impl GlobalResources {
|
|||||||
15,
|
15,
|
||||||
4,
|
4,
|
||||||
),
|
),
|
||||||
|
octopus_animation_regular: FrameAnimationWrapper::new(
|
||||||
|
raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/enemies/octopus.png")?,
|
||||||
|
)?,
|
||||||
|
Vector2 { x: 20.0, y: 20.0 },
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
),
|
||||||
|
octopus_animation_attack: FrameAnimationWrapper::new(
|
||||||
|
raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/enemies/octopusSuck.png")?,
|
||||||
|
)?,
|
||||||
|
Vector2 { x: 30.0, y: 20.0 },
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
),
|
||||||
darkness_overlay: raylib.load_texture_from_image(
|
darkness_overlay: raylib.load_texture_from_image(
|
||||||
&thread,
|
&thread,
|
||||||
&Image::load_image("./assets/img/map/darkness.png")?,
|
&Image::load_image("./assets/img/map/darkness.png")?,
|
||||||
|
Reference in New Issue
Block a user