initial map generation

This commit is contained in:
AmadeusWM
2025-04-06 16:58:05 +02:00
parent f538c597f7
commit 8cce001672
14 changed files with 395 additions and 73 deletions

View File

@@ -64,7 +64,7 @@ pub struct FlashlightButtonAnimation {
impl Default for FlashlightButtonAnimation {
fn default() -> Self {
Self {
timer: Timer::from_seconds(0.20, TimerMode::Once),
timer: Timer::from_seconds(0.20, TimerMode::Once),
is_pressed: false,
}
}
@@ -78,8 +78,8 @@ pub fn plugin(app: &mut App) {
Update,
(
move_camera,
handle_input,
apply_head_bob,
handle_input,
apply_head_bob,
on_resize_system,
handle_flashlight,
update_flashlight_button_animation,
@@ -138,8 +138,6 @@ pub fn init_player(
},
RenderLayers::layer(STATIC_LAYER),
));
// pitslamp sprite
let window = window.single();
let transform = flashlight_base_transform(window.width(), window.height());
parent.spawn((
@@ -149,14 +147,14 @@ pub fn init_player(
RenderLayers::layer(STATIC_LAYER),
FlashlightButtonAnimation::default(),
));
// feitelijke pitslamp
parent.spawn((
Flashlight,
SpotLight {
intensity: 0.0,
intensity: 0.0,
color: Color::WHITE,
range: 4.0,
range: 4.0,
outer_angle: 30.0_f32.to_radians(), // wide cone for flashlight
inner_angle: 10.0_f32.to_radians(), // narrower inner cone
shadows_enabled: false, // (set to true for realism)
@@ -184,12 +182,12 @@ fn on_resize_system(
fn flashlight_base_transform(window_width: f32, window_height: f32) -> BaseTransform {
let window_size = Vec2::new(window_width, window_height);
let sprite_size = Vec2::new(101.0, 101.0);
let scale = window_width / 600.0;
let sprite_size = Vec2::new(404.0, 404.0);
let scale = window_width / 2400.0;
let world_size = sprite_size * scale;
let xoffset = window_size.x / 4.0 - 40.0;
let yoffset = 15.0;
let mut transform = Transform::from_translation(
Vec3::new(window_size.x / 2.0 - world_size.x / 2.0 - xoffset, -window_size.y / 2.0 + world_size.y / 2.0 - yoffset, 0.0)
);
@@ -240,7 +238,7 @@ pub fn handle_input(
mut query: Query<(&Transform, &mut PlayerInput, &mut PlayerAction, &mut Player), With<Player>>,
) {
for (transform, mut input, mut action, mut player) in query.iter_mut() {
*action = PlayerAction::Move;
*action = PlayerAction::Move;
let forward = transform.forward();
let right = transform.right();
@@ -267,7 +265,7 @@ pub fn handle_input(
} else if keyboard_input.pressed(KeyCode::ControlLeft) {
player.speed_factor = 0.65;
} else {
player.speed_factor = 1.0;
player.speed_factor = 1.0;
}
if keyboard_input.just_pressed(KeyCode::KeyE) {
*action = PlayerAction::Interact
@@ -297,7 +295,7 @@ pub fn apply_player_movement(mut player_query: Query<(&PlayerInput, &mut Velocit
if input.movement_direction.y > 0.0 {
velocity.linvel.y = JUMP_FORCE;
}
}
}
}
@@ -325,7 +323,7 @@ pub fn apply_head_bob(
if let Some(camera_transform) = camera_query.iter_mut().next() {
let current_offset = camera_transform.translation.y;
if current_offset.abs() < 0.005 {
// cancel out so head_bob.time_offset
// cancel out so head_bob.time_offset
offset = -head_bob.time_offset;
}
}
@@ -336,7 +334,7 @@ pub fn apply_head_bob(
// calculate vertical and horizontal offsets using sine and cosine
let vertical_offset = head_bob.intensity * f32::sin(head_bob.time_offset);
let horizontal_offset = (head_bob.intensity * 0.5) * f32::cos(head_bob.time_offset * 0.5);
// apply
for mut transform in camera_query.iter_mut() {
transform.translation.y = vertical_offset;
@@ -347,15 +345,15 @@ pub fn apply_head_bob(
transform.translation.x *= 0.8;
}
}
// apply offsets to flashlight
for (mut transform, _sprite, base_transform) in sprite_query.iter_mut() {
let scale_factor = 40.0 * player.speed_factor;
if is_moving {
transform.translation.x = base_transform.0.translation.x + horizontal_offset * scale_factor;
transform.translation.y = base_transform.0.translation.y + vertical_offset * scale_factor;
transform.rotation = Quat::from_euler(
EulerRot::XYZ,
0.0,
@@ -369,10 +367,9 @@ pub fn apply_head_bob(
}
}
}
pub fn handle_flashlight(
player_query: Query<&PlayerAction, With<Player>>,
mut flashlight_query: Query<&mut SpotLight, With<Flashlight>>,
mut flashlight_query: Query<&mut SpotLight, With<Flashlight>>,
mut flashlight_sprite_query: Query<&mut FlashlightButtonAnimation>,
audio_assets: Res<AudioAssets>,
audio: Res<Audio>,
@@ -390,9 +387,9 @@ pub fn handle_flashlight(
if let Ok(mut spotlight) = flashlight_query.get_single_mut() {
audio.play(audio_assets.flash_click.clone());
spotlight.intensity = if spotlight.intensity > 0.0 {
0.0
} else {
spotlight.intensity = if spotlight.intensity > 0.0 {
0.0
} else {
300_000.0
};
}
@@ -414,4 +411,4 @@ pub fn update_flashlight_button_animation(
}
}
}
}
}