Skip to content

Commit

Permalink
feat: better textures
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed Apr 27, 2024
1 parent e1f19ae commit 1455049
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Binary file added gui/assets/ataxx-board.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gui/assets/ataxx-border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui/assets/ataxx-square.png
Binary file not shown.
33 changes: 18 additions & 15 deletions gui/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,22 @@ impl<'a> Drawer<'a> {
fn draw_board(&mut self) {
self.drawer.clear_background(Color::BLACK);

self.drawer.draw_texture_ex(
&self.gui.textures.board,
Vector2::new(
self.gui.width as f32 / 2.0
- self.gui.textures.board.width() as f32 * self.gui.scale / 2.0,
self.gui.height as f32 / 2.0
- self.gui.textures.board.height() as f32 * self.gui.scale / 2.0,
),
0.0,
self.gui.scale,
Color::WHITE,
);

for rank in Rank::iter().rev() {
for file in File::iter() {
self.draw_square(Square::new(file, rank));
self.draw_piece(Square::new(file, rank));
}
}

Expand Down Expand Up @@ -123,12 +136,12 @@ impl<'a> Drawer<'a> {
);
}

fn draw_square(&mut self, sq: Square) {
fn draw_piece(&mut self, sq: Square) {
let pc = self.gui.board.at(sq);
let a = match pc {
ataxx::Color::White => 0.0,
ataxx::Color::Black => 1.0,
ataxx::Color::None => 0.0, // unused
ataxx::Color::None => return,
};

let top_left = Vector2::new(
Expand All @@ -138,7 +151,6 @@ impl<'a> Drawer<'a> {
+ sq.rank() as u32 as f32 * (SQUARE_SIZE - 1.0) * self.gui.scale,
);

let sq_src_rec = Rectangle::new(0.0, 0.0, SQUARE_SIZE, SQUARE_SIZE);
let pc_src_rec = Rectangle::new(a * SQUARE_SIZE, 0.0, SQUARE_SIZE, SQUARE_SIZE);

let dst_rec = Rectangle::new(
Expand All @@ -148,15 +160,6 @@ impl<'a> Drawer<'a> {
SQUARE_SIZE * self.gui.scale,
);

self.drawer.draw_texture_pro(
&self.gui.textures.square,
sq_src_rec,
dst_rec,
Vector2::new(0.0, 0.0),
0.0,
Color::WHITE,
);

if pc == ataxx::Color::None {
// No piece to draw.
return;
Expand All @@ -174,8 +177,8 @@ impl<'a> Drawer<'a> {
}

struct Textures {
board: Texture2D,
pieces: Texture2D,
square: Texture2D,
border: Texture2D,
}

Expand All @@ -190,8 +193,8 @@ macro_rules! load_png_texture {
impl Textures {
fn load(rl: &mut RaylibHandle, thread: &RaylibThread) -> Textures {
Textures {
board: load_png_texture!(rl, thread, "../assets/ataxx-board.png"),
pieces: load_png_texture!(rl, thread, "../assets/ataxx-pieces.png"),
square: load_png_texture!(rl, thread, "../assets/ataxx-square.png"),
border: load_png_texture!(rl, thread, "../assets/ataxx-border.png"),
}
}
Expand Down

0 comments on commit 1455049

Please sign in to comment.