mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
feat: add getting clicked field
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
|
||||||
|
use log::info;
|
||||||
use macroquad::{
|
use macroquad::{
|
||||||
color::{BLACK, Color, GREEN, ORANGE, RED, WHITE},
|
color::{BLACK, Color, GREEN, ORANGE, RED, WHITE},
|
||||||
input::{is_mouse_button_pressed, mouse_position},
|
input::{is_mouse_button_pressed, mouse_position},
|
||||||
@@ -111,6 +112,12 @@ impl Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self) {
|
||||||
|
if let Some(clicked_field) = self.get_clicked_field() {
|
||||||
|
info!("Field: {} was clicked!", clicked_field.pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_board_view(&mut self, board_view: BoardView) {
|
pub fn update_board_view(&mut self, board_view: BoardView) {
|
||||||
self.board_view = board_view;
|
self.board_view = board_view;
|
||||||
}
|
}
|
||||||
@@ -202,6 +209,20 @@ impl Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_clicked_field(&self) -> Option<&GuiField> {
|
||||||
|
let (mouse_x, mouse_y) = mouse_position();
|
||||||
|
let mouse_point = vec2(mouse_x, mouse_y);
|
||||||
|
|
||||||
|
if is_mouse_button_pressed(macroquad::input::MouseButton::Left) {
|
||||||
|
for field in &self.fields {
|
||||||
|
if field.rect.contains(mouse_point) {
|
||||||
|
return Some(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn highlight_current_moves(&mut self) {
|
fn highlight_current_moves(&mut self) {
|
||||||
let mut from: Vec<Position> = vec![];
|
let mut from: Vec<Position> = vec![];
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,10 @@ impl GameClient {
|
|||||||
|
|
||||||
match self.game_state {
|
match self.game_state {
|
||||||
ServerStage::Lobby => self.update_lobby(),
|
ServerStage::Lobby => self.update_lobby(),
|
||||||
ServerStage::Game => {}
|
|
||||||
|
ServerStage::Game => {
|
||||||
|
self.board.update();
|
||||||
|
}
|
||||||
|
|
||||||
ServerStage::End => todo!(),
|
ServerStage::End => todo!(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user