animate octopus

This commit is contained in:
Evan Pratten 2021-04-25 15:44:42 -04:00
parent 2fec1a9765
commit b332f7ffb8
2 changed files with 37 additions and 5 deletions

View File

@ -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 rand::{prelude::ThreadRng, Rng};
@ -71,7 +75,8 @@ impl EnemyBase for Octopus {
// Every once in a while, start sucking air
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.has_taken_air_from_player = false;
@ -107,15 +112,22 @@ impl EnemyBase for Octopus {
self.suck_air_bubbles.clear();
}
// TODO: TMP
context_2d.draw_circle_v(self.current_position, 10.0, Color::RED);
// Render animation
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) {
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 {
// Take air from the player
println!("Stealing");
player.breath_percent -= OCTOPUS_SUCK_AIR_AMOUNT;
// Set the flag

View File

@ -26,6 +26,8 @@ pub struct GlobalResources {
// Enemies
pub jellyfish_animation_regular: FrameAnimationWrapper,
pub jellyfish_animation_attack: FrameAnimationWrapper,
pub octopus_animation_regular: FrameAnimationWrapper,
pub octopus_animation_attack: FrameAnimationWrapper,
// Darkness layer
pub darkness_overlay: Texture2D,
@ -124,6 +126,24 @@ impl GlobalResources {
15,
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(
&thread,
&Image::load_image("./assets/img/map/darkness.png")?,