From 686dae95bf1fe96311028e95fd538dabc644c0b3 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Tue, 9 May 2023 18:58:07 +0200 Subject: [PATCH] Start placing phse --- resources/mainmenu.xml | 8 ++ src/board.rs | 30 +++-- src/game.rs | 267 +++++++++++++++++++++++++++++++++++++---- src/main.rs | 6 + src/simple_ai.rs | 48 ++++++++ 5 files changed, 324 insertions(+), 35 deletions(-) create mode 100644 resources/mainmenu.xml create mode 100644 src/simple_ai.rs diff --git a/resources/mainmenu.xml b/resources/mainmenu.xml new file mode 100644 index 0000000..62b49b3 --- /dev/null +++ b/resources/mainmenu.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/src/board.rs b/src/board.rs index edb2b25..fa92d8b 100644 --- a/src/board.rs +++ b/src/board.rs @@ -98,10 +98,10 @@ impl Default for BoardSlotState { } pub struct Board { - board: Entity, + _board: Entity, center: Vector3, - connection_lines: Vec, + _connection_lines: Vec, slots: [[[BoardSlot; 3]; 3]; 3], white_start_slots: [Vector2; 9], @@ -109,7 +109,7 @@ pub struct Board { } impl Board { - pub fn new(engine: &Arc, scene: &mut SceneHandle) -> Result> { + pub fn new(engine: &Arc, scene: &mut SceneHandle) -> Result { let mut board_entity = engine.assets().empty_entity(); let meshes = vec![Self::create_board_base(&engine)?]; @@ -209,16 +209,16 @@ impl Board { vec2(16.0, -distance), ]; - Ok(Arc::new(Self { - board: board.unwrap(), + Ok(Self { + _board: board.unwrap(), center: vec3(0.0, 0.0, 0.0), - connection_lines: Self::create_connection_lines(scene, Color::Black)?, + _connection_lines: Self::create_connection_lines(scene, Color::Black)?, slots: slots.unwrap(), white_start_slots, black_start_slots, - })) + }) } pub fn center(&self) -> Vector3 { @@ -233,22 +233,26 @@ impl Board { &self.black_start_slots } - pub fn close_to_marker(&self, position: Vector2) -> bool { + pub fn slots(&mut self) -> &mut [[[BoardSlot; 3]; 3]; 3] { + &mut self.slots + } + + pub fn close_to_marker(&mut self, position: Vector2) -> Option<&mut BoardSlot> { const DISTANCE: f32 = 1.25; - for outer in self.slots.iter() { - for inner in outer.iter() { - for slot in inner.iter() { + for outer in self.slots.iter_mut() { + for inner in outer.iter_mut() { + for slot in inner.iter_mut() { if slot.state != BoardSlotState::Invalid { if (slot.position - position).magnitude() <= DISTANCE { - return true; + return Some(slot); } } } } } - false + None } } diff --git a/src/game.rs b/src/game.rs index ea74713..b5a4e34 100644 --- a/src/game.rs +++ b/src/game.rs @@ -4,24 +4,74 @@ use std::sync::{ }; use anyhow::Result; +use assetpath::AssetPath; use engine::prelude::{cgmath::vec3, *}; -use crate::{board::Board, objects::Objects}; +use crate::{ + board::{Board, BoardSlot, BoardSlotState}, + objects::Objects, + simple_ai::SimpleAI, +}; + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] +pub enum StoneState { + ReadyToBePlaced, + Placed, + Dead, +} + +pub struct Stone { + pub stone: Entity, + pub state: StoneState, +} + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] +pub enum GameState { + Placing, + Main, +} + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] +pub enum PlayerColor { + White, + Black, +} + +impl PlayerColor { + pub fn swap(&mut self) { + *self = match *self { + PlayerColor::White => PlayerColor::Black, + PlayerColor::Black => PlayerColor::White, + } + } +} pub struct MillGame { - board: Arc, - white_stones: [Entity; 9], - black_stones: [Entity; 9], + board: Arc>, + white_stones: Mutex<[Stone; 9]>, + black_stones: Mutex<[Stone; 9]>, + + state: Mutex, + current_player: Mutex, scene: Mutex, camera_controls: Mutex, mouse_x: AtomicU32, mouse_y: AtomicU32, + + simple_ai: SimpleAI, + + white_player_label: Arc