guimcaballero / bevy_chess Goto Github PK
View Code? Open in Web Editor NEWChess demo in Bevy
Home Page: https://caballerocoll.com/blog/bevy-chess-tutorial/
License: MIT License
Chess demo in Bevy
Home Page: https://caballerocoll.com/blog/bevy-chess-tutorial/
License: MIT License
While following along, I had to do these updates to have the code working:
Section: Displaying the current turn
code block: first
function: init_next_move_text
description: When creating the TextStyle
, it now takes another property: alignment: TextAlignment
, I fixed mine by adding ..Default::default()
to the block
After this, I went until the end of the tutorial and it is all working nicely.
While follow the tutorial, when doing the "Implementing available squares" section I came across a compilation error.
cannot borrow `pieces_query` as mutable more than once at a time
This happens in the last code block in the section above. In there, it says to add the pieces_vec
inside the if let Ok
section, but you actually have to add it before that section.
Note: In theory this should work by just creating 4 materials and replacing the handles in the squares, but there's a bug in Bevy that makes that not work.
Links to bevyengine/bevy#858 which has been resolved via bevyengine/bevy#877 (this comment confirms it).
Easy as that! We're deriving Default so that when the plugin is initialized it starts with a None value, but we could provide an initial value in case we wanted by implementing FromResources. You can see how it works in this Bevy example.
The liked example in the last sentence states
Registered components must implement the
Properties
andFromResources
traits.`
Aren't our resources missing Properties
? Do we need it? If not, why not?
Throughout the Bevy engine chess tutorial there are a number of places where the program will not function as described by the tutorial because code required for error-free execution (i.e. variable declarations) was not introduced at the step it should have been.
Piece
in this scope.In the tutorial after the paragraph: "We now need to implement something to change the unit positions. We'll change the select_square system to also move the pieces for now, and we'll refactor it into something neater later:" the following code is displayed:
fn select_square(
pick_state: Res<PickState>,
mouse_button_inputs: Res<Input<MouseButton>>,
mut selected_square: ResMut<SelectedSquare>,
mut selected_piece: ResMut<SelectedPiece>,
squares_query: Query<&Square>,
mut pieces_query: Query<(Entity, &mut Piece)>,
) {
At this point, you will receive the error "Cannot find type Piece
in this scope.".
Solution: change the PieceColor, PieceType, and Piece structs to all be public and add use crate::pieces::*
to the top of board.rs. The tutorial shows neither of these steps, but the final code does.
pieces_vec
in this scope.In the tutorial after the paragraph: "Finally, we just need to call the function before moving a piece to check that the move is valid:" the following code is displayed:
fn select_square(
[...]
// Move the selected piece to the selected square
if let Ok((_piece_entity, mut piece)) = pieces_query.get_mut(selected_piece_entity)
{
if piece.is_move_valid((square.x, square.y), pieces_vec) {
piece.x = square.x;
piece.y = square.y;
}
}
[...]
}
At this point, you will receive the error "Cannot find value pieces_vec
in this scope.".
Solution: add let pieces_vec = pieces_query.iter_mut().map(|(_, piece)| *piece).collect();
under the line if let Ok((_piece_entity, mut piece)) = pieces_query.get_mut(selected_piece_entity)
.
Note: The tuple inside the .map(| |)
closure and Ok(())
lines only contains two arguments as the children
argument has not been introduced by this point in the tutorial.
0
of struct bevy::prelude::Children
is privateIn the tutorial after the paragraph: "Here's the new function that also takes care of despawning a piece after it's taken:" the following code is displayed:
...
let pieces_entity_vec: Vec<(Entity, Piece, Vec<Entity>)> = pieces_query
.iter_mut()
.map(|(entity, piece, children)| {
(
entity,
*piece,
children.0.iter().map(|entity| *entity).collect(),
)
})
.collect();
...
At this point, you will receive the error "field 0
of struct bevy::prelude::Children
is private" on the children.0.iter()...
line.
Solution: Change children.0.iter()
to children.iter()
.
This solution I don't understand as much since I just got it from tubotinatub on the Discord.
That is all. Let me know if I was mistaken or if you need help understanding any of these issues.
Thanks again for the great tutorial. It's really helped me grasp Bevy.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.