commit
f2007d1d2b
3
game/dist/project-constants.json
vendored
3
game/dist/project-constants.json
vendored
@ -21,6 +21,7 @@
|
|||||||
"max_velocity": 3,
|
"max_velocity": 3,
|
||||||
"acceleration": 2,
|
"acceleration": 2,
|
||||||
"deceleration": 1,
|
"deceleration": 1,
|
||||||
"start_size": 0.8
|
"start_size": 0.8,
|
||||||
|
"melt_speed": 0.00944443
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,53 @@
|
|||||||
use nalgebra as na;
|
use nalgebra as na;
|
||||||
|
|
||||||
|
use raylib::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
use crate::asset_manager::load_texture_from_internal_data;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub position: na::Vector2<f32>,
|
pub position: na::Vector2<f32>,
|
||||||
pub velocity: na::Vector2<f32>,
|
pub velocity: na::Vector2<f32>,
|
||||||
pub size: f32,
|
pub size: f32,
|
||||||
|
pub active_texture: i32,
|
||||||
|
pub textures: Vec<Texture2D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
|
|
||||||
/// Construct a new player.
|
/// Construct a new player.
|
||||||
pub fn new(position: na::Vector2<f32>) -> Self {
|
pub fn new(
|
||||||
|
raylib_handle: &mut raylib::RaylibHandle,
|
||||||
|
thread: &raylib::RaylibThread,
|
||||||
|
position: na::Vector2<f32>,
|
||||||
|
) -> Self {
|
||||||
|
// Load all the textures
|
||||||
|
let textures = vec![
|
||||||
|
load_texture_from_internal_data(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
"assets/chr/chr_cubee/chr_cubeeLarge.png",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
load_texture_from_internal_data(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
"assets/chr/chr_cubee/chr_cubeeMedium.png",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
load_texture_from_internal_data(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
"assets/chr/chr_cubee/chr_cubeeSmall.png",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
];
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
position,
|
position,
|
||||||
velocity: na::Vector2::zeros(),
|
velocity: na::Vector2::zeros(),
|
||||||
size: 1.0,
|
size: 1.0,
|
||||||
|
active_texture: 0,
|
||||||
|
textures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@ pub struct PlayerConstants {
|
|||||||
|
|
||||||
/// Starting size of player in tiles
|
/// Starting size of player in tiles
|
||||||
pub start_size: f32,
|
pub start_size: f32,
|
||||||
|
|
||||||
|
/// Base melting speed in percent per second
|
||||||
|
pub melt_speed: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This structure is filled with the contents of `dist/project-constants.json` at runtime
|
/// This structure is filled with the contents of `dist/project-constants.json` at runtime
|
||||||
|
@ -60,18 +60,25 @@ impl PlayableScene {
|
|||||||
let game_soundtrack =
|
let game_soundtrack =
|
||||||
load_music_from_internal_data(thread, "assets/audio/gameSoundtrack.mp3").unwrap();
|
load_music_from_internal_data(thread, "assets/audio/gameSoundtrack.mp3").unwrap();
|
||||||
|
|
||||||
|
// Load the player
|
||||||
|
let player = Player::new(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
player_start_position,
|
||||||
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
has_updated_discord_rpc: false,
|
has_updated_discord_rpc: false,
|
||||||
player_start_position,
|
player_start_position,
|
||||||
player: Player::new(player_start_position),
|
|
||||||
world_map: map_renderer,
|
world_map: map_renderer,
|
||||||
|
player,
|
||||||
camera: raylib::camera::Camera2D {
|
camera: raylib::camera::Camera2D {
|
||||||
target: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
target: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
||||||
offset: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
offset: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
||||||
rotation: 0.0,
|
rotation: 0.0,
|
||||||
zoom: 1.0,
|
zoom: 1.0,
|
||||||
},
|
},
|
||||||
last_update: SystemTime::UNIX_EPOCH,
|
last_update: SystemTime::now(),
|
||||||
game_soundtrack,
|
game_soundtrack,
|
||||||
world_colliders,
|
world_colliders,
|
||||||
show_debug_info: false,
|
show_debug_info: false,
|
||||||
@ -127,13 +134,18 @@ impl PlayableScene {
|
|||||||
self.draw_ui(&mut draw, constants);
|
self.draw_ui(&mut draw, constants);
|
||||||
|
|
||||||
// NOTE: If you want to trigger a cutscene, do it here by using one of:
|
// NOTE: If you want to trigger a cutscene, do it here by using one of:
|
||||||
// return MenuStateSignal::DoMeltedDeathCutscene {
|
|
||||||
// playtime: Utc::now().signed_duration_since(self.play_start_time),
|
|
||||||
// };
|
|
||||||
// return MenuStateSignal::DoOceanCutscene {
|
// return MenuStateSignal::DoOceanCutscene {
|
||||||
// playtime: Utc::now().signed_duration_since(self.play_start_time),
|
// playtime: Utc::now().signed_duration_since(self.play_start_time),
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
// Handle Losing
|
||||||
|
if self.player.size < 0.15 {
|
||||||
|
return MenuStateSignal::DoMeltedDeathCutscene {
|
||||||
|
playtime: Utc::now().signed_duration_since(self.play_start_time),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Handle winning
|
// Handle winning
|
||||||
if self
|
if self
|
||||||
.world_map
|
.world_map
|
||||||
@ -181,6 +193,14 @@ impl PlayableScene {
|
|||||||
let mouse_x = draw.get_mouse_x();
|
let mouse_x = draw.get_mouse_x();
|
||||||
let mouse_y = draw.get_mouse_y();
|
let mouse_y = draw.get_mouse_y();
|
||||||
|
|
||||||
|
let current_temperature = self.world_map.sample_temperature_at(
|
||||||
|
self.player.position.component_mul(&na::Vector2::new(1.0, -1.0))
|
||||||
|
);
|
||||||
|
let mut current_temperature_val: f32 = -247.51879;
|
||||||
|
if let Some(val) = current_temperature {
|
||||||
|
current_temperature_val = val;
|
||||||
|
}
|
||||||
|
|
||||||
// Optionally display debug info
|
// Optionally display debug info
|
||||||
if draw.is_key_pressed(KeyboardKey::KEY_F3) {
|
if draw.is_key_pressed(KeyboardKey::KEY_F3) {
|
||||||
self.show_debug_info = !self.show_debug_info;
|
self.show_debug_info = !self.show_debug_info;
|
||||||
@ -224,6 +244,12 @@ impl PlayableScene {
|
|||||||
// 32,
|
// 32,
|
||||||
// Color::BLACK,
|
// Color::BLACK,
|
||||||
// );
|
// );
|
||||||
|
let melt_amount = (current_temperature_val)/(-247.51879);
|
||||||
|
|
||||||
|
draw.draw_text(
|
||||||
|
format!("Funny Temperature: ({})[{}]", current_temperature_val, melt_amount).as_str(),
|
||||||
|
10, 10, 20, Color::PAPAYAWHIP
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Physics
|
// Physics
|
||||||
@ -242,11 +268,11 @@ impl PlayableScene {
|
|||||||
|
|
||||||
let player = &mut self.player;
|
let player = &mut self.player;
|
||||||
|
|
||||||
// NOTE: This is how to check friction and temperature
|
|
||||||
let current_friction = self.world_map.sample_friction_at(player.position);
|
let current_friction = self.world_map.sample_friction_at(player.position);
|
||||||
let current_temperature = self.world_map.sample_temperature_at(player.position);
|
let current_temperature = self.world_map.sample_temperature_at(
|
||||||
|
player.position.component_mul(&na::Vector2::new(1.0, -1.0))
|
||||||
|
);
|
||||||
let map_size = self.world_map.get_map_size();
|
let map_size = self.world_map.get_map_size();
|
||||||
// TODO: You can access the colission list with: self.world_colliders
|
|
||||||
|
|
||||||
// Get input direction components
|
// Get input direction components
|
||||||
let h_axis = raylib.is_key_down(KeyboardKey::KEY_D) as i8
|
let h_axis = raylib.is_key_down(KeyboardKey::KEY_D) as i8
|
||||||
@ -347,6 +373,15 @@ impl PlayableScene {
|
|||||||
player.velocity.y = 0.0;
|
player.velocity.y = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut current_temperature_val: f32 = -247.51879;
|
||||||
|
if let Some(val) = current_temperature {
|
||||||
|
current_temperature_val = val - 273.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
let melt_amount = constants.player.melt_speed * (current_temperature_val)/(-247.51879);
|
||||||
|
|
||||||
|
player.size -= melt_amount * delta_time;
|
||||||
|
|
||||||
self.update_camera(raylib);
|
self.update_camera(raylib);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user