Skip to content

Commit

Permalink
start migrate bevy 0.14
Browse files Browse the repository at this point in the history
Signed-off-by: Agustín Ramiro Díaz <agustin.ramiro.diaz@gmail.com>
  • Loading branch information
AgustinRamiroDiaz committed Aug 24, 2024
1 parent 58e72d6 commit 77fa5bb
Show file tree
Hide file tree
Showing 9 changed files with 1,747 additions and 995 deletions.
2,668 changes: 1,706 additions & 962 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.12.0"
bevy = "0.14.1"
rand = "0.8.5"
bevy_egui = "0.23"
leafwing-input-manager = "0.11.2"
bevy_egui = "0.29"
leafwing-input-manager = "0.15"


# Enable a small amount of optimization in debug mode
Expand Down
19 changes: 11 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>🐍</title>
<link data-trunk rel="copy-dir" href="assets/" />
</head>

<head>
<meta charset="UTF-8" />
<title>🐍</title>
<link data-trunk rel="copy-dir" href="assets/" />
</head>

</html>

<body></body>
<style>
html,
body {
/* html, */
/* body {
width: 100%;
height: 100%;
margin: 0;
}
} */
</style>
4 changes: 2 additions & 2 deletions src/blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn blink_tick(
) {
if timer.0.tick(time.delta()).just_finished() {
for mut sprite in blinking.iter_mut() {
let current_alpha = sprite.color.a();
sprite.color.set_a(1.0 - current_alpha);
let current_alpha = sprite.color.alpha();
sprite.color.set_alpha(1.0 - current_alpha);
}
}
}
4 changes: 2 additions & 2 deletions src/game_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub(crate) struct GameStatePlugin;

impl Plugin for GameStatePlugin {
fn build(&self, app: &mut App) {
app.add_state::<AppState>()
app.init_state::<AppState>()
.add_systems(Update, game_state_transition);
}
}

fn game_state_transition(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
app_state: Res<State<AppState>>,
mut app_state_next_state: ResMut<NextState<AppState>>,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn winner_text(
..default()
},
) // Set the alignment of the Text
.with_text_alignment(TextAlignment::Center)
.with_text_justify(JustifyText::Center)
// Set the style of the TextBundle itself.
.with_style(Style {
position_type: PositionType::Absolute,
Expand Down
25 changes: 15 additions & 10 deletions src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ fn add_snake_input_handler(
];

let player_keys = match snake.player_number.0 {
1 => [KeyCode::Left, KeyCode::Down, KeyCode::Up, KeyCode::Right],
2 => [KeyCode::A, KeyCode::S, KeyCode::W, KeyCode::D],
3 => [KeyCode::J, KeyCode::K, KeyCode::I, KeyCode::L],
1 => [
KeyCode::ArrowLeft,
KeyCode::ArrowDown,
KeyCode::ArrowUp,
KeyCode::ArrowRight,
],
2 => [KeyCode::KeyA, KeyCode::KeyS, KeyCode::KeyW, KeyCode::KeyD],
3 => [KeyCode::KeyJ, KeyCode::KeyK, KeyCode::KeyI, KeyCode::KeyL],
4 => [
KeyCode::Numpad4,
KeyCode::Numpad5,
Expand Down Expand Up @@ -126,14 +131,14 @@ fn add_snake_input_handler(
let mut input_map = InputMap::default();

for (player_controls, direction) in std::iter::zip(player_keys, directions) {
input_map.insert(player_controls, direction);
input_map.insert(direction, player_controls);
}

for (player_controls, direction) in std::iter::zip(player_gamepad, directions) {
input_map.insert_many_to_one(player_controls, direction);
input_map.insert_one_to_many(direction, player_controls);
}

input_map = input_map.set_gamepad(Gamepad { id: 0 }).build();
input_map.set_gamepad(Gamepad { id: 0 });

entity.insert(InputManagerBundle::<Direction> {
// Stores "which actions are currently pressed"
Expand Down Expand Up @@ -172,13 +177,13 @@ fn input_snake_direction(
mut propose_direction: EventWriter<ProposeDirection>,
) {
for (snake, direction) in query.iter_mut().filter(|(snake, _)| !snake.input_blocked) {
let direction = if direction.just_pressed(Direction::Left) {
let direction = if direction.just_pressed(&Direction::Left) {
Some(Direction::Left)
} else if direction.just_pressed(Direction::Right) {
} else if direction.just_pressed(&Direction::Right) {
Some(Direction::Right)
} else if direction.just_pressed(Direction::Up) {
} else if direction.just_pressed(&Direction::Up) {
Some(Direction::Up)
} else if direction.just_pressed(Direction::Down) {
} else if direction.just_pressed(&Direction::Down) {
Some(Direction::Down)
} else {
None
Expand Down
12 changes: 6 additions & 6 deletions src/snake.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::VecDeque;

use bevy::prelude::*;
use bevy::{color::palettes::css, prelude::*};

use crate::{
apple::AppleEaten, coordinate::Coordinate, direction::Direction, game_state::AppState,
Expand Down Expand Up @@ -46,7 +46,7 @@ fn setup_grid_and_camera(mut commands: Commands) {
SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2 { x: SIZE, y: SIZE }),
color: Color::DARK_GRAY,
color: Color::Srgba(css::DARK_SLATE_GRAY),
..Default::default()
},
..Default::default()
Expand Down Expand Up @@ -99,28 +99,28 @@ fn spawn_snakes(mut commands: Commands, number_of_players: Res<NumberOfPlayersSe
Id(1),
Coordinate::from((-3.0, -3.0)),
Direction::Right,
MyColor(Color::LIME_GREEN),
MyColor(Color::Srgba(css::LIMEGREEN)),
"Ninja".to_string(),
),
(
Id(2),
Coordinate::from((3.0, 3.0)),
Direction::Left,
MyColor(Color::PINK),
MyColor(Color::Srgba(css::PINK)),
"Panther".to_string(),
),
(
Id(3),
Coordinate::from((-3.0, 3.0)),
Direction::Down,
MyColor(Color::SALMON),
MyColor(Color::Srgba(css::SALMON)),
"Sushi".to_string(),
),
(
Id(4),
Coordinate::from((3.0, -3.0)),
Direction::Up,
MyColor(Color::TURQUOISE),
MyColor(Color::Srgba(css::TURQUOISE)),
"Sonic".to_string(),
),
];
Expand Down
2 changes: 1 addition & 1 deletion src/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn setup(mut commands: Commands) {
..default()
},
) // Set the alignment of the Text
.with_text_alignment(TextAlignment::Center)
.with_text_justify(JustifyText::Center)
// Set the style of the TextBundle itself.
.with_style(Style {
position_type: PositionType::Absolute,
Expand Down

0 comments on commit 77fa5bb

Please sign in to comment.