|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
@ -0,0 +1,34 @@
|
||||
use crate::{deck::*, *};
|
||||
use bevy::{prelude::*, utils::HashMap};
|
||||
|
||||
/// boot systems kick off the game
|
||||
pub struct BootPlugin;
|
||||
|
||||
impl Plugin for BootPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, (boot::load, boot::start_setup).chain());
|
||||
}
|
||||
}
|
||||
|
||||
/// loads assets for the game
|
||||
pub(crate) fn load(mut commands: Commands, server: Res<AssetServer>) {
|
||||
let cards: HashMap<Card, Sprite> = Deck::iter_cards()
|
||||
.map(|card| {
|
||||
let sprite = Sprite {
|
||||
image: server.load(card.sprite()),
|
||||
..default()
|
||||
};
|
||||
|
||||
(card, sprite)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let test_deck = Deck { cards };
|
||||
|
||||
commands.insert_resource(test_deck);
|
||||
}
|
||||
|
||||
/// Finish boot state by starting setup
|
||||
pub(crate) fn start_setup(mut game_state: ResMut<NextState<GameState>>) {
|
||||
game_state.set(GameState::Setup);
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
/// Debugging systems
|
||||
pub struct DebugPlugin;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
// Nothing yet!
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
use bevy::{prelude::*, utils::HashMap};
|
||||
|
||||
/// Deck and Cards
|
||||
pub struct DeckPlugin;
|
||||
|
||||
impl Plugin for DeckPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
// Nothing yet!
|
||||
}
|
||||
}
|
||||
|
||||
/// We expect 81 cards total
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct Deck {
|
||||
pub cards: HashMap<Card, Sprite>,
|
||||
}
|
||||
|
||||
impl Deck {
|
||||
pub(crate) fn iter_cards() -> impl Iterator<Item = Card> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
[ItemColor::Red, ItemColor::Green, ItemColor::Purple]
|
||||
.iter()
|
||||
.for_each(|&color| {
|
||||
[ItemShape::Oval, ItemShape::Diamond, ItemShape::Squiggle]
|
||||
.iter()
|
||||
.for_each(|&shape| {
|
||||
[ItemPattern::Open, ItemPattern::Solid, ItemPattern::Striped]
|
||||
.iter()
|
||||
.for_each(|&pattern| {
|
||||
[ItemNumber::One, ItemNumber::Two, ItemNumber::Three]
|
||||
.iter()
|
||||
.for_each(|&number| {
|
||||
v.push(Card {
|
||||
color,
|
||||
shape,
|
||||
pattern,
|
||||
number,
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
v.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// A card describes abstractly the contents of a card
|
||||
/// including color of items, number of items, pattern, and shape
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Component, Debug)]
|
||||
pub(crate) struct Card {
|
||||
pub color: ItemColor,
|
||||
pub number: ItemNumber,
|
||||
pub pattern: ItemPattern,
|
||||
pub shape: ItemShape,
|
||||
}
|
||||
|
||||
impl Card {
|
||||
pub(crate) fn sprite(&self) -> String {
|
||||
let col = match self.color {
|
||||
ItemColor::Red => "cr",
|
||||
ItemColor::Green => "cg",
|
||||
ItemColor::Purple => "cp",
|
||||
};
|
||||
let num = match self.number {
|
||||
ItemNumber::One => "n1",
|
||||
ItemNumber::Two => "n2",
|
||||
ItemNumber::Three => "n3",
|
||||
};
|
||||
let pat = match self.pattern {
|
||||
ItemPattern::Solid => "pso",
|
||||
ItemPattern::Striped => "pst",
|
||||
ItemPattern::Open => "pop",
|
||||
};
|
||||
let shape = match self.shape {
|
||||
ItemShape::Oval => "so",
|
||||
ItemShape::Diamond => "sd",
|
||||
ItemShape::Squiggle => "ss",
|
||||
};
|
||||
format!("{}_{}_{}_{}.png", col, num, pat, shape)
|
||||
}
|
||||
}
|
||||
|
||||
/// Item colors for the card may be red, green or purple
|
||||
/// All items must be the same color
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub(crate) enum ItemColor {
|
||||
Red,
|
||||
Green,
|
||||
Purple,
|
||||
}
|
||||
|
||||
/// A card may have 1 to 3 items
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub(crate) enum ItemNumber {
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
}
|
||||
|
||||
/// Each item can be solid, striped, or open
|
||||
/// a card has all of it's item as one pattern
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub(crate) enum ItemPattern {
|
||||
Solid,
|
||||
Striped,
|
||||
Open,
|
||||
}
|
||||
|
||||
/// Each item can be an oval, diamond, or squiggle
|
||||
/// All items on a card are one shape
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub(crate) enum ItemShape {
|
||||
Oval,
|
||||
Diamond,
|
||||
Squiggle,
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct PlayPlugin;
|
||||
|
||||
impl Plugin for PlayPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
// Nothing yet!
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
use crate::{deck::*, *};
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct SetupPlugin;
|
||||
|
||||
impl Plugin for SetupPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
OnEnter(GameState::Setup),
|
||||
(setup::setup_cards, setup::setup_camera, setup::start_play).chain(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Setup drawing our cards on the screen
|
||||
pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
|
||||
Deck::iter_cards().for_each(|this_card| {
|
||||
let this = deck
|
||||
.cards
|
||||
.get(&this_card)
|
||||
.expect(format!("fech card sprite {:?}", this_card).as_str())
|
||||
.clone();
|
||||
commands.spawn((this, this_card));
|
||||
});
|
||||
}
|
||||
|
||||
/// Setup our camera to view cardson the screen
|
||||
pub(crate) fn setup_camera(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Camera2d,
|
||||
Camera {
|
||||
hdr: true,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
/// Finish the setup state by progressing to the play state
|
||||
pub(crate) fn start_play(mut game_state: ResMut<NextState<GameState>>) {
|
||||
game_state.set(GameState::Play);
|
||||
}
|
||||