Base implementation of space to skip piece to end

It is buggy, but it is something...
main
Elijah Voigt 1 day ago
parent 21ad8763e4
commit a73f5ddb05

@ -42,13 +42,13 @@ fn main() {
add_piece add_piece
.run_if(not(any_with_component::<Shape>)) .run_if(not(any_with_component::<Shape>))
.after(update_next_shapes), .after(update_next_shapes),
update_shape_blocks
.run_if(any_component_added::<Shape>.or(any_component_changed::<Shape>)),
falling falling
.run_if(in_state(GameState::Falling)) .run_if(in_state(GameState::Falling))
.run_if(clock_cycle(1.0)), .run_if(clock_cycle(1.0)),
update_position.run_if(any_component_changed::<GridPosition>), update_position.run_if(any_component_changed::<GridPosition>),
deactivate_shape.run_if(any_component_removed::<Shape>), update_shape_blocks
.run_if(any_component_added::<Shape>.or(any_component_changed::<Shape>)).after(update_position),
deactivate_shape.run_if(any_component_removed::<Shape>).after(update_shape_blocks),
check_line_removal, check_line_removal,
// Clearing lines systems // Clearing lines systems
clear_line.run_if(any_component_changed::<LineBlocks>), clear_line.run_if(any_component_changed::<LineBlocks>),
@ -565,6 +565,9 @@ fn kb_input(
KeyCode::ArrowRight => { KeyCode::ArrowRight => {
commands.entity(e).trigger(Movement::Right); commands.entity(e).trigger(Movement::Right);
} }
KeyCode::Space => {
commands.entity(e).trigger(Movement::Skip);
}
KeyCode::Escape => next.set(match curr.get() { KeyCode::Escape => next.set(match curr.get() {
GameState::Falling => GameState::Pause, GameState::Falling => GameState::Pause,
GameState::Pause => GameState::Falling, GameState::Pause => GameState::Falling,
@ -705,6 +708,7 @@ enum Movement {
Left, Left,
Right, Right,
Rotate, Rotate,
Skip,
} }
// TODO: When out of bounds left/right, try to move piece away from wall // TODO: When out of bounds left/right, try to move piece away from wall
@ -719,57 +723,66 @@ fn movement(
shape.get_mut(trigger.target()), shape.get_mut(trigger.target()),
grid_positions.get(trigger.target()), grid_positions.get(trigger.target()),
) { ) {
let (new_center, new_shape) = match trigger.event() { let new_positions = match trigger.event() {
Movement::Down => (center.with_offset(0, -1), *this_shape), Movement::Down => vec![center.with_offset(0, -1)],
Movement::Left => (center.with_offset(-1, 0), *this_shape), Movement::Left => vec![center.with_offset(-1, 0)],
Movement::Right => (center.with_offset(1, 0), *this_shape), Movement::Right => vec![center.with_offset(1, 0)],
Movement::Rotate => (Ok(*center), this_shape.rotated()), Movement::Rotate => vec![Ok(*center)],
Movement::Skip => (1..20).map(|i| center.with_offset(0, -i)).collect(),
};
let new_shape = match trigger.event() {
Movement::Down | Movement::Left | Movement::Right | Movement::Skip => *this_shape,
Movement::Rotate => this_shape.rotated(),
}; };
debug!( debug!(
"Proposed change: {:?}\n{}", "Proposed change: {:?}\n{}",
new_center, new_positions,
new_shape.as_ascii() new_shape.as_ascii()
); );
match new_center { for position in new_positions {
Err(GameError::OutOfBoundsLeft) | Err(GameError::OutOfBoundsRight) => (), // Do nothing match position {
Err(GameError::OutOfBoundsDown) => { Err(GameError::OutOfBoundsLeft) | Err(GameError::OutOfBoundsRight) => (), // Do nothing
commands.entity(trigger.target()).remove::<Shape>(); Err(GameError::OutOfBoundsDown) => {
} commands.entity(trigger.target()).remove::<Shape>();
Err(GameError::Collision) => panic!("This shouldn't happen!"), }
Ok(new_center) => { Err(GameError::Collision) => panic!("This shouldn't happen!"),
let new_blocks = new_shape.coordinates(&new_center); Ok(new_center) => {
for block_gp in new_blocks { let new_blocks = new_shape.coordinates(&new_center);
match block_gp { for block_gp in new_blocks {
Err(GameError::OutOfBoundsLeft) | Err(GameError::OutOfBoundsRight) => { match block_gp {
return; Err(GameError::OutOfBoundsLeft) | Err(GameError::OutOfBoundsRight) => {
} // Do nothing return;
Err(GameError::OutOfBoundsDown) => { } // Do nothing
commands.entity(trigger.target()).remove::<Shape>(); Err(GameError::OutOfBoundsDown) => {
return; commands.entity(trigger.target()).remove::<Shape>();
} return;
Err(GameError::Collision) => panic!("This shouldn't happen!"), }
Ok(gp) => { Err(GameError::Collision) => panic!("This shouldn't happen!"),
for other_gp in inactive.iter() { Ok(gp) => {
// If there would be a collision between blocks for other_gp in inactive.iter() {
if gp == *other_gp { // If there would be a collision between blocks
// And we are moving down if gp == *other_gp {
if *trigger.event() == Movement::Down { // And we are moving down
// De-activate this piece if *trigger.event() == Movement::Down {
commands.entity(trigger.target()).remove::<Shape>(); // De-activate this piece
commands.entity(trigger.target()).remove::<Shape>();
}
// Regardless, cancel the move
return;
} }
// Regardless, cancel the move
return;
} }
} }
} }
} }
info!("Checks passed for {position:?}, committing change");
// Update center
let mut gp = grid_positions.get_mut(trigger.target()).unwrap();
*gp = new_center;
// Update shape/rotation
let mut s = shape.get_mut(trigger.target()).unwrap();
*s = new_shape;
} }
// Update center
let mut gp = grid_positions.get_mut(trigger.target()).unwrap();
*gp = new_center;
// Update shape/rotation
let mut s = shape.get_mut(trigger.target()).unwrap();
*s = new_shape;
} }
} }
} else { } else {

Loading…
Cancel
Save