Whirlpools have spirites

This commit is contained in:
wm-c 2021-04-25 20:49:48 -04:00
parent 1928d0d292
commit 3007f96ca4
4 changed files with 21 additions and 8 deletions

View File

@ -36,7 +36,8 @@
"x": 250,
"y": 250
},
"should_remove": false
"should_remove": false,
"rotation": 0
}
]

View File

@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
pub struct Whirlpool{
pub position: Vector2,
pub should_remove: bool,
pub rotation: f32,
}
impl Whirlpool{
@ -27,7 +28,9 @@ impl EnemyBase for Whirlpool{
resources: &mut crate::resources::GlobalResources,
dt: f64,
) {
context_2d.draw_circle(self.position.x as i32, self.position.y as i32, 12.0, Color::RED);
resources.whirlpool.draw(context_2d, Vector2{x: self.position.x, y: self.position.y}, self.rotation);
self.rotation += 1.0;
}
fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) {

View File

@ -177,20 +177,19 @@ pub fn update_player_movement(
let angle = net_pose.y.atan2(net_pose.x);
// Calculates force
let force = 1.0;
let force = 15.0 / game_core.player.position.distance_to(whirlpool.position) ;
let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0);
let mut force_y = (force as f32 * angle.sin()).clamp(-1.0, 1.0);
let mut force_x = (force as f32 * angle.cos()).clamp(-5.0, 5.0);
let mut force_y = (force as f32 * angle.sin()).clamp(-5.0, 5.0);
if force_x.is_nan(){
force_x = 1.0 * net_pose.x;
force_x = 5.0 * net_pose.x;
}
if force_y.is_nan(){
force_y = 1.0 * net_pose.y;
force_y = 5.0 * net_pose.y;
}
movement_drift.x -= force_x;

View File

@ -32,6 +32,7 @@ pub struct GlobalResources {
pub jellyfish_animation_attack: FrameAnimationWrapper,
pub octopus_animation_regular: FrameAnimationWrapper,
pub octopus_animation_attack: FrameAnimationWrapper,
pub whirlpool: FrameAnimationWrapper,
// Darkness layer
pub darkness_overlay: Texture2D,
@ -247,6 +248,15 @@ impl GlobalResources {
6,
2,
),
whirlpool: FrameAnimationWrapper::new(
raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/enemies/whirlpool.png")?,
)?,
Vector2 { x: 20.0, y: 20.0 },
4,
4,
),
})
}
}