resizing everything
This commit is contained in:
parent
12ed150a17
commit
09c776ba3f
@ -3,8 +3,8 @@ 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};
|
||||||
|
|
||||||
const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 80.0;
|
const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0;
|
||||||
const FISH_FOLLOW_PLAYER_SPEED: f32 = 2.0;
|
const FISH_FOLLOW_PLAYER_SPEED: f32 = 1.8;
|
||||||
const FISH_FOLLOW_PLAYER_SPEED_FAST: f32 = FISH_FOLLOW_PLAYER_SPEED * 3.0;
|
const FISH_FOLLOW_PLAYER_SPEED_FAST: f32 = FISH_FOLLOW_PLAYER_SPEED * 3.0;
|
||||||
const FISH_ATTACH_RADIUS: f32 = 20.0;
|
const FISH_ATTACH_RADIUS: f32 = 20.0;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ impl FishEntity {
|
|||||||
direction_to_player.normalize();
|
direction_to_player.normalize();
|
||||||
|
|
||||||
// Handle player picking up fish
|
// Handle player picking up fish
|
||||||
if player.position.distance_to(self.position).abs() <= player.size.y * 1.2 {
|
if player.position.distance_to(self.position).abs() <= player.size.y * 2.2 {
|
||||||
self.following_player = true;
|
self.following_player = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ impl GameCore {
|
|||||||
offset: Vector2::zero(),
|
offset: Vector2::zero(),
|
||||||
target: Vector2::zero(),
|
target: Vector2::zero(),
|
||||||
rotation: 0.0,
|
rotation: 0.0,
|
||||||
zoom: 1.0,
|
zoom: 2.0,
|
||||||
},
|
},
|
||||||
show_simple_debug_info: false,
|
show_simple_debug_info: false,
|
||||||
world: world,
|
world: world,
|
||||||
|
@ -61,6 +61,7 @@ impl Screen for InGameScreen {
|
|||||||
x: (win_width as f32 / 2.0),
|
x: (win_width as f32 / 2.0),
|
||||||
y: (win_height as f32 / 2.0),
|
y: (win_height as f32 / 2.0),
|
||||||
};
|
};
|
||||||
|
let camera_window_center = window_center * (1.0 / game_core.master_camera.zoom);
|
||||||
|
|
||||||
// Update player movement
|
// Update player movement
|
||||||
playerlogic::update_player_movement(draw_handle, game_core, window_center);
|
playerlogic::update_player_movement(draw_handle, game_core, window_center);
|
||||||
|
@ -5,10 +5,10 @@ use crate::{
|
|||||||
pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96},
|
pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96},
|
||||||
};
|
};
|
||||||
|
|
||||||
const NORMAL_PLAYER_SPEED: i32 = 4;
|
const NORMAL_PLAYER_SPEED: i32 = 3;
|
||||||
const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2;
|
const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2;
|
||||||
const CAMERA_FOLLOW_SPEED: f32 = 0.7;
|
const CAMERA_FOLLOW_SPEED: f32 = 0.7;
|
||||||
const TURN_SPEED: f32 = 0.05;
|
const TURN_SPEED: f32 = 0.15;
|
||||||
const BOOST_DECREASE_PER_SECOND: f32 = 0.75;
|
const BOOST_DECREASE_PER_SECOND: f32 = 0.75;
|
||||||
const BOOST_REGEN_PER_SECOND: f32 = 0.25;
|
const BOOST_REGEN_PER_SECOND: f32 = 0.25;
|
||||||
const BREATH_DECREASE_PER_SECOND: f32 = 0.01;
|
const BREATH_DECREASE_PER_SECOND: f32 = 0.01;
|
||||||
@ -27,45 +27,45 @@ pub fn update_player_movement(
|
|||||||
let raw_movement_direction = mouse_world_pose - game_core.player.position;
|
let raw_movement_direction = mouse_world_pose - game_core.player.position;
|
||||||
let mut normalized_movement_direction = raw_movement_direction;
|
let mut normalized_movement_direction = raw_movement_direction;
|
||||||
normalized_movement_direction.normalize();
|
normalized_movement_direction.normalize();
|
||||||
|
|
||||||
let tau: f32 = PI as f32 * 2.0;
|
|
||||||
// get angles as floats
|
|
||||||
let mut player_angle: f32 = Vector2::zero().angle_to(game_core.player.direction);
|
|
||||||
let mut desired_angle: f32 = Vector2::zero().angle_to(normalized_movement_direction);
|
|
||||||
|
|
||||||
// make angle positive
|
let tau: f32 = PI as f32 * 2.0;
|
||||||
if desired_angle < 0.0 {
|
// get angles as floats
|
||||||
desired_angle += tau;
|
let mut player_angle: f32 = Vector2::zero().angle_to(game_core.player.direction);
|
||||||
}
|
let mut desired_angle: f32 = Vector2::zero().angle_to(normalized_movement_direction);
|
||||||
|
|
||||||
// turn towards mouse at turn speed
|
// make angle positive
|
||||||
if player_angle % tau > desired_angle {
|
if desired_angle < 0.0 {
|
||||||
if (player_angle % tau) - desired_angle > PI as f32 {
|
desired_angle += tau;
|
||||||
player_angle += TURN_SPEED;
|
}
|
||||||
} else {
|
|
||||||
player_angle -= TURN_SPEED;
|
// turn towards mouse at turn speed
|
||||||
}
|
if player_angle % tau > desired_angle {
|
||||||
|
if (player_angle % tau) - desired_angle > PI as f32 {
|
||||||
|
player_angle += TURN_SPEED;
|
||||||
} else {
|
} else {
|
||||||
if desired_angle - (player_angle % tau) > PI as f32 {
|
player_angle -= TURN_SPEED;
|
||||||
player_angle -= TURN_SPEED;
|
|
||||||
} else {
|
|
||||||
player_angle += TURN_SPEED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if desired_angle - (player_angle % tau) > PI as f32 {
|
||||||
|
player_angle -= TURN_SPEED;
|
||||||
|
} else {
|
||||||
|
player_angle += TURN_SPEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// snap to mouse if close enough
|
// snap to mouse if close enough
|
||||||
if f32::abs(player_angle - desired_angle) < (TURN_SPEED * 1.1) {
|
if f32::abs(player_angle - desired_angle) < (TURN_SPEED * 1.1) {
|
||||||
player_angle = desired_angle;
|
player_angle = desired_angle;
|
||||||
}
|
}
|
||||||
if player_angle > tau {
|
if player_angle > tau {
|
||||||
player_angle -= tau;
|
player_angle -= tau;
|
||||||
}
|
}
|
||||||
if player_angle < 0.0 {
|
if player_angle < 0.0 {
|
||||||
player_angle += tau;
|
player_angle += tau;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set angle
|
// set angle
|
||||||
game_core.player.direction = Vector2::new(f32::cos(player_angle), f32::sin(player_angle));
|
game_core.player.direction = Vector2::new(f32::cos(player_angle), f32::sin(player_angle));
|
||||||
|
|
||||||
// In the case the player is in "null", just jump the camera to them
|
// In the case the player is in "null", just jump the camera to them
|
||||||
if game_core.player.position == Vector2::zero() {
|
if game_core.player.position == Vector2::zero() {
|
||||||
@ -135,9 +135,12 @@ pub fn render_player(context_2d: &mut RaylibMode2D<RaylibDrawHandle>, game_core:
|
|||||||
TRANSLUCENT_WHITE_64,
|
TRANSLUCENT_WHITE_64,
|
||||||
);
|
);
|
||||||
context_2d.draw_ring(
|
context_2d.draw_ring(
|
||||||
player.position,
|
Vector2 {
|
||||||
boost_ring_max_radius - 2.0,
|
x: player.position.x as i32 as f32,
|
||||||
boost_ring_max_radius + 2.0,
|
y: player.position.y as i32 as f32,
|
||||||
|
},
|
||||||
|
boost_ring_max_radius ,
|
||||||
|
boost_ring_max_radius + 1.0,
|
||||||
0,
|
0,
|
||||||
(360.0 * player.breath_percent) as i32,
|
(360.0 * player.breath_percent) as i32,
|
||||||
0,
|
0,
|
||||||
|
@ -17,8 +17,8 @@ impl Player {
|
|||||||
Self {
|
Self {
|
||||||
boost_percent: 1.0,
|
boost_percent: 1.0,
|
||||||
size: Vector2 {
|
size: Vector2 {
|
||||||
x: 11.0 * 4.0,
|
x: 11.0,
|
||||||
y: 21.0 * 4.0
|
y: 21.0
|
||||||
},
|
},
|
||||||
breath_percent: 1.0,
|
breath_percent: 1.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
Reference in New Issue
Block a user