Skip to content

Commit d09a92b

Browse files
committed
fix clock layers
1 parent c14bd72 commit d09a92b

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/game/movement.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bevy::prelude::*;
88
use super::{
99
assets::SfxKey,
1010
audio::sfx::PlaySfx,
11-
spawn::clock::{Clock, ClockController, Interactable, Positions},
11+
spawn::clock::{Clock, ClockController, ClockHandType, Interactable, Positions},
1212
};
1313
use crate::{
1414
screen::{PlayingState, Screen},
@@ -35,7 +35,15 @@ fn movement(
3535
mut commands: Commands,
3636
input: Res<ButtonInput<KeyCode>>,
3737
mut controller_query: Query<(&mut ClockController, &mut Transform), Without<Clock>>,
38-
mut clocks: Query<(Entity, &mut Transform, &mut Clock), With<Interactable>>,
38+
mut clocks: Query<(Entity, &mut Transform, &mut Clock, &Children), With<Interactable>>,
39+
clock_children: Query<
40+
&Transform,
41+
(
42+
With<ClockHandType>,
43+
Without<Clock>,
44+
Without<ClockController>,
45+
),
46+
>,
3947
positions: Res<Positions>,
4048
) {
4149
let mut intent = Vec2::ZERO;
@@ -73,15 +81,25 @@ fn movement(
7381
if controller.index != 0 {
7482
let clock_count = clocks
7583
.iter_mut()
76-
.filter(|(_, t, _)| t.translation.x == position.x)
84+
.filter(|(_, t, _, _)| t.translation.x == position.x)
7785
.count();
7886
if clock_count == 1 {
7987
let clock = clocks
8088
.iter_mut()
81-
.find(|(e, _, _)| *e == controller.held_clock.unwrap());
89+
.find(|(e, _, _, _)| *e == controller.held_clock.unwrap());
8290
if clock.is_some() {
8391
let mut clock = clock.unwrap();
8492
clock.1.translation.y = position.y;
93+
clock.1.translation.z = 300.0;
94+
95+
let hour = clock.3.first().unwrap();
96+
let mut hour_transform = *clock_children.get(*hour).unwrap();
97+
hour_transform.translation.z = 310.0;
98+
99+
let minute = clock.3.get(1).unwrap();
100+
let mut minute_transform = *clock_children.get(*minute).unwrap();
101+
minute_transform.translation.z = 310.0;
102+
85103
controller.held_clock = None;
86104
}
87105
}
@@ -99,10 +117,20 @@ fn movement(
99117
} else {
100118
let target_clock = clocks
101119
.iter_mut()
102-
.find(|(_, t, _)| t.translation.x == position.x);
120+
.find(|(_, t, _, _)| t.translation.x == position.x);
103121
if target_clock.is_some() {
104122
let mut clock = target_clock.unwrap();
105123
clock.1.translation.y = position.y + 30.0;
124+
clock.1.translation.z = 200.0;
125+
126+
let hour = clock.3.first().unwrap();
127+
let mut hour_transform = *clock_children.get(*hour).unwrap();
128+
hour_transform.translation.z = 210.0;
129+
130+
let minute = clock.3.get(1).unwrap();
131+
let mut minute_transform = *clock_children.get(*minute).unwrap();
132+
minute_transform.translation.z = 210.0;
133+
106134
controller.held_clock = Some(clock.0);
107135
}
108136
}
@@ -111,8 +139,8 @@ fn movement(
111139
// move and move held clock
112140
if controller.direction != Vec2::ZERO {
113141
transform.translation.x = position.x;
114-
let held_clock: Option<(Entity, Mut<Transform>, Mut<Clock>)> =
115-
clocks.iter_mut().find(|(e, _, _)| {
142+
let held_clock: Option<(Entity, Mut<Transform>, Mut<Clock>, &Children)> =
143+
clocks.iter_mut().find(|(e, _, _, _)| {
116144
if controller.held_clock.is_some() {
117145
return controller.held_clock.unwrap() == *e;
118146
}

src/game/spawn/clock.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct Clock {
8686
}
8787

8888
#[derive(Component)]
89-
enum ClockHandType {
89+
pub enum ClockHandType {
9090
Hour,
9191
Minute,
9292
}
@@ -319,7 +319,6 @@ fn score_clocks(
319319
let hour_diff = main_rotations.hour.angle_between(clock_rotation.hour);
320320
let minute_diff = main_rotations.minute.angle_between(clock_rotation.minute);
321321

322-
println!("Score! {} {}", hour_diff, minute_diff);
323322
if hour_diff < 0.1 && minute_diff < 0.1 {
324323
score.0 += 1.0 * time.delta_seconds();
325324
}
@@ -472,7 +471,7 @@ fn spawn_interact_clock(
472471
SpriteBundle {
473472
texture: image_handles[&ImageKey::Clock].clone_weak(),
474473
transform: Transform {
475-
translation: Vec3::new(translation.x, translation.y, 200.0),
474+
translation: Vec3::new(translation.x, translation.y, 300.0),
476475
..Default::default()
477476
},
478477
sprite: Sprite {
@@ -495,7 +494,7 @@ fn spawn_interact_clock(
495494
SpriteBundle {
496495
texture: image_handles[&ImageKey::ClockHour].clone_weak(),
497496
transform: Transform {
498-
translation: Vec3::new(0.0, 0.0, 300.0),
497+
translation: Vec3::new(0.0, 0.0, 10.0),
499498
..default()
500499
},
501500
sprite: Sprite {
@@ -511,7 +510,7 @@ fn spawn_interact_clock(
511510
SpriteBundle {
512511
texture: image_handles[&ImageKey::ClockMinute].clone_weak(),
513512
transform: Transform {
514-
translation: Vec3::new(0.0, 0.0, 350.0),
513+
translation: Vec3::new(0.0, 0.0, 10.0),
515514
..default()
516515
},
517516
sprite: Sprite {

src/game/spawn/level.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn spawn_oil(
122122
SpriteBundle {
123123
texture: image_handles[&ImageKey::OilCan].clone_weak(),
124124
transform: Transform {
125-
translation: positions.oil_can.extend(10.0),
125+
translation: positions.oil_can.extend(210.0),
126126
..default()
127127
},
128128
sprite: Sprite {

0 commit comments

Comments
 (0)