Skip to content

Commit

Permalink
Added camera zoom, big world and fixed texture bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac8668 committed Dec 31, 2023
1 parent 78b248b commit 73d43b2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ pub fn move_y(chunk_manager: &mut ChunkManager, actor: &mut Actor, dir: i32) ->
pub struct ActorsPlugin;
impl Plugin for ActorsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, update_actors.after(update_player));
app.add_systems(Update, update_actors.before(chunk_manager_update));
}
}
4 changes: 2 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const ATOM_SIZE: usize = 3;
pub const GRAVITY: u8 = 1;
pub const TERM_VEL: u8 = 10;
pub const FRAMES_SLEEP: u8 = 4;
pub const CHUNKS_WIDTH: usize = 8;
pub const CHUNKS_HEIGHT: usize = 6;
pub const CHUNKS_WIDTH: usize = 32;
pub const CHUNKS_HEIGHT: usize = 32;

pub const _CAMERA_SPEED: f32 = 10.;
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mod prelude {
debug::*, geom_tools::*, manager_api::*, player::*,
};
pub use bevy::math::{ivec2, ivec3, uvec2, uvec3, vec2, vec3};
pub use bevy::input::mouse::MouseWheel;
pub use bevy::input::mouse::MouseScrollUnit;
pub use bevy::prelude::*;
pub use std::collections::{HashMap, HashSet};
}
Expand Down
21 changes: 15 additions & 6 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn player_setup(

/// Updates player
pub fn update_player(
input: (Res<Input<MouseButton>>, ResMut<Input<KeyCode>>),
input: (Res<Input<MouseButton>>, ResMut<Input<KeyCode>>, EventReader<MouseWheel>,),
window: Query<&Window>,
mut player: Query<(
&mut Actor,
Expand All @@ -86,13 +86,13 @@ pub fn update_player(
&mut AnimationIndices,
)>,
mut tool: Query<(&mut Transform, &GlobalTransform, &mut Sprite, &mut Tool)>,
camera_q: Query<(&Camera, &GlobalTransform)>,
mut camera_q: Query<(&Camera, &GlobalTransform, &mut Transform), Without<Tool>>,
mut chunk_manager: Query<&mut ChunkManager>,
mut dirty_rects: Query<&mut DirtyRects>,
) {
let (mut actor, mut player, mut textatlas_sprite, mut anim_idxs) = player.single_mut();
let (mut tool_transform, tool_gtransform, mut tool_sprite, mut tool) = tool.single_mut();
let (mouse, keys) = input;
let (mouse, keys, mut scroll_evr) = input;
let mut chunk_manager = chunk_manager.single_mut();

// Gravity
Expand Down Expand Up @@ -150,11 +150,11 @@ pub fn update_player(
}

// Tool
let (camera, camera_transform) = camera_q.single();
let (camera, camera_gtransform, mut camera_transform) = camera_q.single_mut();
let window = window.single();
if let Some(world_position) = window
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
.and_then(|cursor| camera.viewport_to_world(camera_gtransform, cursor))
.map(|ray| ray.origin.truncate())
{
//Rotate and move sprite
Expand Down Expand Up @@ -228,6 +228,15 @@ pub fn update_player(
update_dirty_rects(&mut dirty_rects.render, pos);
}
}

for ev in scroll_evr.read() {
match ev.unit {

Check failure on line 233 in src/player.rs

View workflow job for this annotation

GitHub Actions / 🔧 Clippy correctness checks (x86_64-unknown-linux-gnu, target)

you seem to be trying to use `match` for an equality check. Consider using `if`
MouseScrollUnit::Line => {
camera_transform.scale *= 0.9_f32.powi(ev.y as i32);
}
_ => {}
}
}
}

pub fn update_player_sprite(
Expand Down Expand Up @@ -258,7 +267,7 @@ impl Plugin for PlayerPlugin {
app.add_systems(
Update,
(
update_player.before(chunk_manager_update),
update_player.after(chunk_manager_update),
update_player_sprite.after(update_actors),
),
)
Expand Down

0 comments on commit 73d43b2

Please sign in to comment.