From 1f065361baea1c7b6bfd3c3a5443fe7d4363e68a Mon Sep 17 00:00:00 2001 From: Elias Stepanik Date: Tue, 22 Oct 2024 23:37:35 +0200 Subject: [PATCH] Working 2 --- src/components/player.rs | 28 +++++++++++++++++--- src/components/tilemap.rs | 6 ++--- src/components/ui.rs | 15 ++++++++--- src/components/world.rs | 55 ++++++++++++++++++++++++++++++++------- 4 files changed, 85 insertions(+), 19 deletions(-) diff --git a/src/components/player.rs b/src/components/player.rs index 3b68f38..386e530 100644 --- a/src/components/player.rs +++ b/src/components/player.rs @@ -1,7 +1,9 @@ use bevy::input::ButtonInput; +use bevy::input::mouse::MouseWheel; use bevy::log::info; -use bevy::prelude::{Camera, Camera2dBundle, Commands, Component, GlobalTransform, KeyCode, Query, Res, Time, Transform, Vec3, With, Without}; +use bevy::prelude::{Camera, Camera2dBundle, Commands, Component, EventReader, GlobalTransform, KeyCode, Query, Res, Time, Transform, Vec3, With, Without}; use bevy::utils::default; +use crate::components::world::{CAMERA_SCALE, PLAYER_SPEED}; #[derive(Component)] pub struct Player { @@ -20,7 +22,7 @@ pub fn setup(mut commands: Commands) { info!("Adding Camera"); commands.spawn(Camera2dBundle { transform: Transform { - scale: Vec3::splat(0.5), // Zoom in by reducing the scale (smaller scale means a larger view) + scale: Vec3::splat(CAMERA_SCALE), // Zoom in by reducing the scale (smaller scale means a larger view) ..default() }, ..default() @@ -30,7 +32,7 @@ pub fn setup(mut commands: Commands) { // Setup player with initial position info!("Spawning player"); commands.spawn(( - Player::new(500.0, Vec3::new(0.0, 0.0, 0.0)), // Initial player speed and position + Player::new(PLAYER_SPEED, Vec3::new(0.0, 0.0, 0.0)), // Initial player speed and position Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)), GlobalTransform::default(), )); @@ -38,6 +40,7 @@ pub fn setup(mut commands: Commands) { pub fn update_movement( keyboard_input: Res>, + mut mouse_wheel_events: EventReader, time: Res