From ef90e1ce66685528cf7f6cfed1788348f0c4d095 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 24 Apr 2021 13:59:08 -0400 Subject: [PATCH] fishy fish --- src/entities/fish.rs | 8 ++++---- src/logic/ingame/mod.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/entities/fish.rs b/src/entities/fish.rs index 7d994bc..452d9ed 100644 --- a/src/entities/fish.rs +++ b/src/entities/fish.rs @@ -1,7 +1,7 @@ use rand::{Rng, prelude::ThreadRng}; use raylib::prelude::*; -use crate::{gamecore::GameCore, lib::utils::triangles::rotate_vector, player::Player}; +use crate::{gamecore::GameCore, lib::utils::triangles::rotate_vector, player::Player, world::World}; const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0; const FISH_FOLLOW_PLAYER_SPEED: f32 = 1.8; @@ -36,7 +36,7 @@ impl FishEntity { return output; } - pub fn handle_follow_player(&mut self, player: &Player, dt: f64) { + pub fn handle_follow_player(&mut self, player: &Player, dt: f64, other_fish: &Vec) { // Distance and direction to player let dist_to_player = player.position - self.position; let dist_to_player_lin = self.position.distance_to(player.position); @@ -86,9 +86,9 @@ impl FishEntity { self.direction = direction_to_player; } - pub fn update_position(&mut self, player: &mut Player, dt: f64) { + pub fn update_position(&mut self, player: &mut Player, dt: f64, other_fish: &Vec) { if self.following_player { - self.handle_follow_player(player, dt); + self.handle_follow_player(player, dt, other_fish); } else { self.handle_free_movement(player, dt); } diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 4a4e0a8..a5b640b 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -74,9 +74,9 @@ impl Screen for InGameScreen { self.render_world(&mut context_2d, game_core); // Render entities - let mut fish = &mut game_core.world.fish; - for fish in fish.iter_mut() { - fish.update_position(&mut game_core.player, dt); + let fish_clone = game_core.world.fish.clone(); + for fish in game_core.world.fish.iter_mut() { + fish.update_position(&mut game_core.player, dt, &fish_clone); fish.render(&mut context_2d); }