From 6b321e034fbd20298957092770b9ea40f262b513 Mon Sep 17 00:00:00 2001 From: cool-mist Date: Mon, 24 Mar 2025 00:19:34 +0530 Subject: [PATCH] Add buttons, refactor, make it more mouse friendly --- src/game.rs | 499 +++++++++++++++++++++++++++++++++++++++++++++ src/game/button.rs | 74 +++++++ src/main.rs | 464 +---------------------------------------- 3 files changed, 577 insertions(+), 460 deletions(-) create mode 100644 src/game/button.rs diff --git a/src/game.rs b/src/game.rs index 0daf88a..129d023 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1 +1,500 @@ +use std::fmt::{self, Display, Formatter}; + +use button::{Button, ButtonAction}; +use macroquad::prelude::*; +use sol_chess::{ + board::{Board, BoardState}, + generator, +}; +use texture::PieceTexture; + +pub mod button; pub mod texture; + +pub struct Game { + // The generated puzzle. We keep a copy of this to reset the game. + original_board: Board, + + // What is shown to the user + board: Board, + + // Constants througout the game + texture_res: Texture2D, + num_squares: usize, + heading_font_size: f32, + heading_text: String, + + // Update below on handle input + state: GameState, + debug: bool, + + // Update below on window resize + // Used for drawing the state + square_width: f32, + window_height: f32, + window_width: f32, + squares: Vec, + heading_rect: Rect, + btns: Vec