Simple board with ascii debugging system
parent
2c84c1cef8
commit
d5adb6955d
@ -1,3 +1,173 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_fmod::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
App::new()
|
||||||
|
.add_plugins((
|
||||||
|
DefaultPlugins,
|
||||||
|
FmodPlugin {
|
||||||
|
audio_banks_paths: &[
|
||||||
|
"./assets/audio/Martian Chess/Build/Desktop/Master.bank",
|
||||||
|
"./assets/audio/Martian Chess/Build/Desktop/Master.strings.bank",
|
||||||
|
"./assets/audio/Martian Chess/Build/Desktop/Music.bank",
|
||||||
|
"./assets/audio/Martian Chess/Build/Desktop/SFX.bank",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.add_systems(Startup, setup_board)
|
||||||
|
.add_systems(PostStartup, display_board)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Component)]
|
||||||
|
enum Piece {
|
||||||
|
Pawn,
|
||||||
|
Drone,
|
||||||
|
Queen,
|
||||||
|
}
|
||||||
|
|
||||||
|
// manually for the type.
|
||||||
|
impl std::fmt::Display for Piece {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Piece::Queen => write!(f, "@"),
|
||||||
|
Piece::Drone => write!(f, "^"),
|
||||||
|
Piece::Pawn => write!(f, "*"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The board is setup like this:
|
||||||
|
/// ```text
|
||||||
|
/// 0 1 2 3 4 5 6 7
|
||||||
|
/// +--+--+--+--+--+--+--+--+
|
||||||
|
/// a | | | | I | d| Q| Q|
|
||||||
|
/// +--+--+--+--+--+--+--+--+
|
||||||
|
/// b |d |p |p | I | p| d| Q|
|
||||||
|
/// +--+--+--+--+--+--+--+--+
|
||||||
|
/// c |Q |d |p | I | p| p| d|
|
||||||
|
/// +--+--+--+--+--+--+--+--+
|
||||||
|
/// d |Q |Q |d | I | | | |
|
||||||
|
/// +--+--+--+--+--+--+--+--+
|
||||||
|
/// ````
|
||||||
|
#[derive(Debug, Resource)]
|
||||||
|
struct Board {
|
||||||
|
inner: Vec<Vec<Option<Entity>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_board(mut commands: Commands) {
|
||||||
|
let a5d = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
||||||
|
.id();
|
||||||
|
let a6q = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
||||||
|
.id();
|
||||||
|
let a7q = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
||||||
|
.id();
|
||||||
|
let b0d = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
||||||
|
.id();
|
||||||
|
let b1p = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
||||||
|
.id();
|
||||||
|
let b2p = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
||||||
|
.id();
|
||||||
|
let c5p = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
||||||
|
.id();
|
||||||
|
let b5p = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
||||||
|
.id();
|
||||||
|
let b6d = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
||||||
|
.id();
|
||||||
|
let b7q = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
||||||
|
.id();
|
||||||
|
let c0q = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
||||||
|
.id();
|
||||||
|
let c1d = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
||||||
|
.id();
|
||||||
|
let c2p = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
||||||
|
.id();
|
||||||
|
let c6p = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
||||||
|
.id();
|
||||||
|
let c7d = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
||||||
|
.id();
|
||||||
|
let d0q = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
||||||
|
.id();
|
||||||
|
let d1q = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
||||||
|
.id();
|
||||||
|
let d2d = commands
|
||||||
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
||||||
|
.id();
|
||||||
|
|
||||||
|
commands.insert_resource(Board {
|
||||||
|
inner: vec![
|
||||||
|
vec![
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(a5d),
|
||||||
|
Some(a6q),
|
||||||
|
Some(a7q),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
Some(b0d),
|
||||||
|
Some(b1p),
|
||||||
|
Some(b2p),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(b5p),
|
||||||
|
Some(b6d),
|
||||||
|
Some(b7q),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
Some(c0q),
|
||||||
|
Some(c1d),
|
||||||
|
Some(c2p),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(c5p),
|
||||||
|
Some(c6p),
|
||||||
|
Some(c7d),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
Some(d0q),
|
||||||
|
Some(d1q),
|
||||||
|
Some(d2d),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_board(board: Res<Board>, pieces: Query<&Piece>) {
|
||||||
|
board.inner.iter().for_each(|row| {
|
||||||
|
print!("+--+--+--+--+--+--+--+--+\n");
|
||||||
|
print!("|");
|
||||||
|
row.iter()
|
||||||
|
.map(|piece| piece.and_then(|p| pieces.get(p).ok()))
|
||||||
|
.for_each(|piece| match piece {
|
||||||
|
Some(p) => print!("{} |", p),
|
||||||
|
None => print!(" |"),
|
||||||
|
});
|
||||||
|
print!("\n");
|
||||||
|
});
|
||||||
|
print!("+--+--+--+--+--+--+--+--+\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue