face down top of deck card

main
Elijah Voigt 1 year ago
parent 1cdba9b75a
commit 5efbbd1ac9

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

Binary file not shown.

@ -134,7 +134,7 @@ impl Card {
assert!(num < 108, "Sprite index should be less than 108");
let size = UVec2 { x: 20, y: 32 };
let layout = TextureAtlasLayout::from_grid(size, 9, 12, None, None);
let layout = TextureAtlasLayout::from_grid(size, 9, 13, None, None);
("cards.png".into(), layout, num)
}

@ -19,7 +19,7 @@ impl Plugin for PlayPlugin {
pub(crate) struct Selected;
/// Where in the deck a card is
#[derive(Component)]
#[derive(Component, Clone, PartialEq)]
pub(crate) struct DeckOrder(pub u8);
/// Where on the board/table/play-space a card is

@ -33,7 +33,12 @@ pub(crate) struct AnimationStore {
}
/// Setup drawing our cards on the screen
pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
pub(crate) fn setup_cards(
mut commands: Commands,
deck: Res<Deck>,
mut layouts: ResMut<Assets<TextureAtlasLayout>>,
server: Res<AssetServer>,
) {
let animation_player = AnimationPlayer::default();
commands
.spawn((
@ -43,6 +48,29 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
animation_player,
))
.with_children(|parent| {
// Top of card pile is a "face down" card
{
let top_card_transform = Transform {
translation: Vec3::new(-400.0, -200.0, 1.0),
..default()
};
let top_card_sprite = Sprite {
custom_size: Some(Vec2::new(80.0, 128.0)),
texture_atlas: Some(TextureAtlas {
index: 108,
layout: layouts.add(TextureAtlasLayout::from_grid(
UVec2 { x: 20, y: 32 },
9,
13,
None,
None,
)),
}),
image: server.load("cards.png"),
..default()
};
parent.spawn((top_card_transform, top_card_sprite, Visibility::Inherited));
}
Deck::iter_shuffled()
.enumerate()
.for_each(|(i, this_card)| {
@ -53,7 +81,7 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
.clone();
let this_sprite = Sprite {
custom_size: Some(Vec2::new(80.0, 128.0)),
..this
..this.clone()
};
let order = play::DeckOrder(i as u8);
@ -69,31 +97,33 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
// Spawn card with a simple Transform parent so we can adjust the Z-axis for
// card ordering
parent.spawn(Transform::default()).with_children(|parent| {
let mut child = parent.spawn_empty();
let entity_id = child.id();
let animation_target = AnimationTarget {
id: animation_target_id,
player: entity_id,
};
child
.insert((
animation_player,
animation_target,
name,
order,
this_card,
this_sprite,
this_transform,
visibility,
))
.observe(play::place_card)
.observe(debug::set_debug_card)
.observe(debug::hide_debug_card)
.observe(play::play_selected_animation)
.observe(play::stop_selected_animation)
.observe(play::toggle_selected);
});
parent
.spawn((Transform::default(), Visibility::Inherited))
.with_children(|parent| {
let mut child = parent.spawn_empty();
let entity_id = child.id();
let animation_target = AnimationTarget {
id: animation_target_id,
player: entity_id,
};
child
.insert((
animation_player,
animation_target,
name,
order,
this_card,
this_sprite,
this_transform,
visibility,
))
.observe(play::place_card)
.observe(debug::set_debug_card)
.observe(debug::hide_debug_card)
.observe(play::play_selected_animation)
.observe(play::stop_selected_animation)
.observe(play::toggle_selected);
});
});
});
}

Loading…
Cancel
Save