fix fish direction
This commit is contained in:
parent
e7cd020666
commit
50baf53b9e
@ -1,7 +1,13 @@
|
|||||||
use rand::{prelude::ThreadRng, Rng};
|
use rand::{prelude::ThreadRng, Rng};
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{gamecore::{self, GameCore}, lib::utils::triangles::rotate_vector, player::Player, resources::GlobalResources, world::World};
|
use crate::{
|
||||||
|
gamecore::{self, GameCore},
|
||||||
|
lib::utils::triangles::rotate_vector,
|
||||||
|
player::Player,
|
||||||
|
resources::GlobalResources,
|
||||||
|
world::World,
|
||||||
|
};
|
||||||
|
|
||||||
const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0;
|
const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0;
|
||||||
const FISH_FOLLOW_PLAYER_SPEED: f32 = 1.8;
|
const FISH_FOLLOW_PLAYER_SPEED: f32 = 1.8;
|
||||||
@ -35,7 +41,10 @@ impl FishEntity {
|
|||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
Self {
|
Self {
|
||||||
position: position,
|
position: position,
|
||||||
direction: Vector2::zero(),
|
direction: Vector2 {
|
||||||
|
x: rng.gen_range(0.0..1.0),
|
||||||
|
y: rng.gen_range(0.0..1.0),
|
||||||
|
},
|
||||||
velocity: Vector2::zero(),
|
velocity: Vector2::zero(),
|
||||||
following_player: false,
|
following_player: false,
|
||||||
animation_counter: 0,
|
animation_counter: 0,
|
||||||
@ -156,25 +165,30 @@ impl FishEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, context_2d: &mut RaylibMode2D<RaylibDrawHandle>, resources: &mut GlobalResources) {
|
pub fn render(
|
||||||
|
&mut self,
|
||||||
|
context_2d: &mut RaylibMode2D<RaylibDrawHandle>,
|
||||||
|
resources: &mut GlobalResources,
|
||||||
|
) {
|
||||||
// Direction
|
// Direction
|
||||||
let direction =
|
let direction = (Vector2::zero().angle_to(self.direction.normalized())).to_degrees();
|
||||||
(Vector2::zero().angle_to(self.direction.normalized())).to_degrees();
|
|
||||||
|
|
||||||
self.animation_counter += 1;
|
self.animation_counter += 1;
|
||||||
|
|
||||||
// swimming
|
// swimming
|
||||||
if !self.following_player {
|
if self.following_player {
|
||||||
if self.animation_counter % 3 == 0 {
|
if self.animation_counter % 3 == 0 {
|
||||||
self.current_frame += 1;
|
self.current_frame += 1;
|
||||||
if self.current_frame == 8 {
|
if self.current_frame == 8 {
|
||||||
self.current_frame = 0;
|
self.current_frame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resources.fish_animation_swim.draw_frame(context_2d,
|
resources.fish_animation_swim.draw_frame(
|
||||||
|
context_2d,
|
||||||
self.position,
|
self.position,
|
||||||
direction,
|
direction,
|
||||||
(self.current_frame + self.color * 9) as u32);
|
(self.current_frame + self.color * 9) as u32,
|
||||||
|
);
|
||||||
// idle
|
// idle
|
||||||
} else {
|
} else {
|
||||||
if self.animation_counter % 10 == 0 {
|
if self.animation_counter % 10 == 0 {
|
||||||
@ -184,10 +198,12 @@ impl FishEntity {
|
|||||||
self.current_frame = 0;
|
self.current_frame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resources.fish_animation_idle.draw_frame(context_2d,
|
resources.fish_animation_idle.draw_frame(
|
||||||
|
context_2d,
|
||||||
self.position,
|
self.position,
|
||||||
direction,
|
direction,
|
||||||
(self.current_frame + self.color * 2) as u32);
|
(self.current_frame + self.color * 2) as u32,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user