Debug info, rotating cards, fixed backgrounds

main
Elijah Voigt 2 years ago
parent 5c1de3525f
commit 0e492ea7df

BIN
assets/filled_circle_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_circle_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_circle_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_diamond_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_diamond_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_diamond_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_squiggle_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_squiggle_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/filled_squiggle_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_circle_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_circle_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_circle_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_diamond_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_diamond_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_diamond_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_squiggle_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_squiggle_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/open_squiggle_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_circle_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_circle_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_circle_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_diamond_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_diamond_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_diamond_red.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_squiggle_green.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_squiggle_purple.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/shaded_squiggle_red.png (Stored with Git LFS)

Binary file not shown.

@ -1,10 +1,73 @@
use bevy::prelude::*; use bevy::prelude::*;
use crate::deck::Card;
/// Debugging systems /// Debugging systems
pub struct DebugPlugin; pub struct DebugPlugin;
impl Plugin for DebugPlugin { impl Plugin for DebugPlugin {
fn build(&self, _app: &mut App) { fn build(&self, app: &mut App) {
// Nothing yet! app.add_observer(track_card_info)
.add_systems(Startup, init_ui);
}
}
#[derive(Component)]
pub(crate) struct DebugText;
fn init_ui(mut commands: Commands) {
commands
.spawn((
Sprite::from_color(Color::BLACK.with_alpha(0.9), [100.0, 100.0].into()),
DebugText,
Visibility::Hidden,
Transform::default().with_translation(Vec3::new(0.0, 0.0, 1.0)),
PickingBehavior::IGNORE,
))
.with_children(|parent| {
parent.spawn((
Text2d("...".to_string()),
DebugText,
Transform::default().with_translation(Vec3::new(0.0, 0.0, 2.0)),
PickingBehavior::IGNORE,
));
});
} }
fn track_card_info(
trigger: Trigger<Pointer<Move>>,
mut transforms: Query<&mut Transform, (With<DebugText>, With<Sprite>)>,
window: Query<&Window>,
) {
let p = trigger.pointer_location.position;
transforms.iter_mut().for_each(|mut t| {
let offset = window.single().resolution.size() / 2.0;
let pos = p - offset + Vec2::new(-50.0, 50.0);
t.translation.x = pos.x;
t.translation.y = -pos.y;
});
}
pub(crate) fn set_debug_card(
trigger: Trigger<Pointer<Over>>,
cards: Query<&Card>,
mut vis: Query<&mut Visibility, With<DebugText>>,
mut debug_text: Query<&mut Text2d, With<DebugText>>,
) {
let card = cards.get(trigger.entity()).unwrap();
debug_text.iter_mut().for_each(|mut text| {
text.0 = format!("{}", card);
});
vis.iter_mut().for_each(|mut v| {
*v = Visibility::Inherited;
});
}
pub(crate) fn hide_debug_card(
_trigger: Trigger<Pointer<Out>>,
mut vis: Query<&mut Visibility, With<DebugText>>,
) {
vis.iter_mut().for_each(|mut v| {
*v = Visibility::Hidden;
});
} }

@ -81,12 +81,23 @@ impl Card {
ItemNumber::Two => 1, ItemNumber::Two => 1,
ItemNumber::Three => 2, ItemNumber::Three => 2,
}; };
let layout = TextureAtlasLayout::from_grid(UVec2 { x: 20, y: 32 }, 3, 1, None, None); let size = UVec2 { x: 20, y: 32 };
let layout = TextureAtlasLayout::from_grid(size, 3, 1, None, None);
(fname, layout, num) (fname, layout, num)
} }
} }
impl std::fmt::Display for Card {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{}\n{}\n{}\n{}",
self.number, self.pattern, self.color, self.shape
)
}
}
/// Item colors for the card may be red, green or purple /// Item colors for the card may be red, green or purple
/// All items must be the same color /// All items must be the same color
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
@ -96,6 +107,17 @@ pub(crate) enum ItemColor {
Purple, Purple,
} }
impl std::fmt::Display for ItemColor {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let color = match self {
ItemColor::Red => "red",
ItemColor::Green => "green",
ItemColor::Purple => "purple",
};
write!(f, "{}", color)
}
}
/// A card may have 1 to 3 items /// A card may have 1 to 3 items
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub(crate) enum ItemNumber { pub(crate) enum ItemNumber {
@ -104,6 +126,17 @@ pub(crate) enum ItemNumber {
Three, Three,
} }
impl std::fmt::Display for ItemNumber {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let num = match self {
ItemNumber::One => 1,
ItemNumber::Two => 2,
ItemNumber::Three => 3,
};
write!(f, "{}", num)
}
}
/// Each item can be solid, striped, or open /// Each item can be solid, striped, or open
/// a card has all of it's item as one pattern /// a card has all of it's item as one pattern
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
@ -113,6 +146,17 @@ pub(crate) enum ItemPattern {
Open, Open,
} }
impl std::fmt::Display for ItemPattern {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let fill = match self {
ItemPattern::Open => "empty",
ItemPattern::Striped => "shaded",
ItemPattern::Solid => "solid",
};
write!(f, "{}", fill)
}
}
/// Each item can be an oval, diamond, or squiggle /// Each item can be an oval, diamond, or squiggle
/// All items on a card are one shape /// All items on a card are one shape
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
@ -121,3 +165,14 @@ pub(crate) enum ItemShape {
Diamond, Diamond,
Squiggle, Squiggle,
} }
impl std::fmt::Display for ItemShape {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let shape = match self {
ItemShape::Oval => "oval",
ItemShape::Diamond => "diamond",
ItemShape::Squiggle => "squiggle",
};
write!(f, "{}", shape)
}
}

@ -11,10 +11,10 @@ fn main() {
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(( .add_plugins((
deck::DeckPlugin, deck::DeckPlugin,
debug::DebugPlugin,
boot::BootPlugin, boot::BootPlugin,
setup::SetupPlugin, setup::SetupPlugin,
play::PlayPlugin, play::PlayPlugin,
debug::DebugPlugin,
)) ))
.init_state::<GameState>() .init_state::<GameState>()
.run(); .run();

@ -1,9 +1,18 @@
use bevy::prelude::*; use bevy::prelude::*;
use crate::deck::Card;
pub struct PlayPlugin; pub struct PlayPlugin;
impl Plugin for PlayPlugin { impl Plugin for PlayPlugin {
fn build(&self, _app: &mut App) { fn build(&self, app: &mut App) {
// Nothing yet! app.add_systems(Update, rotate_cards);
}
} }
fn rotate_cards(mut query: Query<&mut Transform, With<Card>>, time: Res<Time>) {
let dt = time.delta().as_secs_f32();
query.iter_mut().for_each(|mut t| {
t.rotate_z(dt * 0.5);
});
} }

@ -1,5 +1,5 @@
use crate::{deck::*, *}; use crate::{deck::*, *};
use bevy::prelude::*; use bevy::{prelude::*, sprite::AlphaMode2d};
pub struct SetupPlugin; pub struct SetupPlugin;
@ -22,7 +22,7 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
.unwrap_or_else(|| panic!("fech card sprite {:?}", this_card)) .unwrap_or_else(|| panic!("fech card sprite {:?}", this_card))
.clone(); .clone();
let new_this = Sprite { let new_this = Sprite {
custom_size: Some(Vec2::new(size, size)), custom_size: Some(Vec2::new(40.0, 64.0)),
..this ..this
}; };
// for a 9x9 grid we want x to wrap every 9 and y to increment every 9 // for a 9x9 grid we want x to wrap every 9 and y to increment every 9
@ -33,7 +33,10 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
let x_off = -(size / 2.0) * 9.0; let x_off = -(size / 2.0) * 9.0;
let y_off = -(size / 2.0) * 8.0; let y_off = -(size / 2.0) * 8.0;
let t = Transform::from_xyz(l * (x as f32) + x_off, l * (y as f32) + y_off, 0.0); let t = Transform::from_xyz(l * (x as f32) + x_off, l * (y as f32) + y_off, 0.0);
commands.spawn((new_this, this_card, t)); commands
.spawn((new_this, this_card, t))
.observe(debug::set_debug_card)
.observe(debug::hide_debug_card);
}); });
} }

Loading…
Cancel
Save