From 3007f96ca4c1e2c6eb88fe66a790b01b5c00f33f Mon Sep 17 00:00:00 2001 From: wm-c Date: Sun, 25 Apr 2021 20:49:48 -0400 Subject: [PATCH] Whirlpools have spirites --- assets/worlds/mainworld.json | 3 ++- src/entities/enemy/whirlpool.rs | 5 ++++- src/logic/ingame/playerlogic.rs | 11 +++++------ src/resources.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/assets/worlds/mainworld.json b/assets/worlds/mainworld.json index 4f9198f..9c46d40 100644 --- a/assets/worlds/mainworld.json +++ b/assets/worlds/mainworld.json @@ -36,7 +36,8 @@ "x": 250, "y": 250 }, - "should_remove": false + "should_remove": false, + "rotation": 0 } ] diff --git a/src/entities/enemy/whirlpool.rs b/src/entities/enemy/whirlpool.rs index f0192b3..3be4db4 100644 --- a/src/entities/enemy/whirlpool.rs +++ b/src/entities/enemy/whirlpool.rs @@ -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) { diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 2c9e509..de0543a 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -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; diff --git a/src/resources.rs b/src/resources.rs index cac06cb..35b16ac 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -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, + ), }) } }