summaryrefslogtreecommitdiff
path: root/src/controllable/player.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllable/player.rs')
-rw-r--r--src/controllable/player.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/controllable/player.rs b/src/controllable/player.rs
index fdc110e..91f3d5a 100644
--- a/src/controllable/player.rs
+++ b/src/controllable/player.rs
@@ -1,7 +1,7 @@
use avian2d::prelude::*;
use bevy::prelude::*;
-use crate::lunar::DestPlanet;
+use crate::{lunar::DestPlanet, Stickable, TouchdownGoal};
#[derive(Component)]
pub struct Player {
@@ -27,13 +27,14 @@ fn map_key_to_movement(key: &KeyCode) -> Direction {
}
}
pub fn check_transition_level(
- mut commands: Commands,
+ mut has_touched_down: ResMut<TouchdownGoal>,
player_transform: Query<&Transform, (With<Player>, Without<DestPlanet>)>,
moon_transform: Query<(Entity, &DestPlanet, &Transform), (With<DestPlanet>, Without<Player>)>
) {
+ if has_touched_down.reached {return;}
let (moon_e, moon, moon_t) = moon_transform.single();
let player_t = player_transform.single();
- let shroud_padding = 1. + moon.radius;
+ let shroud_padding = 0.1 + moon.radius;
let bounds = (
Vec2 {
x: moon_t.translation.x - shroud_padding,
@@ -49,13 +50,16 @@ pub fn check_transition_level(
player_t.translation.y > bounds.0.y &&
player_t.translation.y < bounds.1.y {
info!("CAN TRANSITION TO NEXT LEVEL");
- commands.entity(moon_e).despawn();
+ // has_touched_down.reached = true;
+ // commands.entity(moon_e).despawn();
}
}
pub fn camera_follow_player(
+ goal: Res<TouchdownGoal>,
mut camera_transform: Query<&mut Transform, (With<Camera2d>, Without<Player>)>,
player_transform: Query<&Transform, (With<Player>, Without<Camera>)>,
) {
+ if goal.reached {return;}
let mut camera_t = camera_transform.single_mut();
let player_t = player_transform.single();
camera_t.translation = player_t.translation;
@@ -63,8 +67,10 @@ pub fn camera_follow_player(
pub fn player_movements(
time: Res<Time>,
input: Res<ButtonInput<KeyCode>>,
+ goal: Res<TouchdownGoal>,
mut ps: Query<(&Player, &Sprite, &mut ExternalForce), (With<Player>)>,
) {
+ if goal.reached { return; }
let movements: Vec<Direction> = input.get_pressed().map(map_key_to_movement).collect();
for (p, s, mut propulsion) in &mut ps {
let mut pvel_vec = Vec2 { x: 0., y: 0. };
@@ -89,6 +95,7 @@ pub fn setup_player_with_controls(mut commands: Commands) {
},
RigidBody::Dynamic,
Transform::from_xyz(0., 70., 0.),
+ Stickable {},
ExternalForce::ZERO.with_persistence(false),
Sprite::from_color(Color::BLACK, Vec2 { x: 10., y: 10. }),
Collider::rectangle(10., 10.),