summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/Cargo.toml10
-rw-r--r--ui/resources/chess_board.pngbin0 -> 441 bytes
-rw-r--r--ui/resources/red_king.pngbin0 -> 3138 bytes
-rw-r--r--ui/resources/red_piece.pngbin0 -> 1597 bytes
-rw-r--r--ui/resources/white_king.pngbin0 -> 3710 bytes
-rw-r--r--ui/resources/white_piece.pngbin0 -> 2189 bytes
-rw-r--r--ui/src/main.rs90
7 files changed, 100 insertions, 0 deletions
diff --git a/ui/Cargo.toml b/ui/Cargo.toml
new file mode 100644
index 0000000..086a7de
--- /dev/null
+++ b/ui/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "ui"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+tetra = "0.6"
+model = {path = "../model"} \ No newline at end of file
diff --git a/ui/resources/chess_board.png b/ui/resources/chess_board.png
new file mode 100644
index 0000000..3e7f1da
--- /dev/null
+++ b/ui/resources/chess_board.png
Binary files differ
diff --git a/ui/resources/red_king.png b/ui/resources/red_king.png
new file mode 100644
index 0000000..8f8a6e8
--- /dev/null
+++ b/ui/resources/red_king.png
Binary files differ
diff --git a/ui/resources/red_piece.png b/ui/resources/red_piece.png
new file mode 100644
index 0000000..ea207bf
--- /dev/null
+++ b/ui/resources/red_piece.png
Binary files differ
diff --git a/ui/resources/white_king.png b/ui/resources/white_king.png
new file mode 100644
index 0000000..3eef6c2
--- /dev/null
+++ b/ui/resources/white_king.png
Binary files differ
diff --git a/ui/resources/white_piece.png b/ui/resources/white_piece.png
new file mode 100644
index 0000000..aff621a
--- /dev/null
+++ b/ui/resources/white_piece.png
Binary files differ
diff --git a/ui/src/main.rs b/ui/src/main.rs
new file mode 100644
index 0000000..166b1ae
--- /dev/null
+++ b/ui/src/main.rs
@@ -0,0 +1,90 @@
+use model::{CheckersBitBoard, PieceColor};
+use tetra::graphics::{self, Color, DrawParams, Texture};
+use tetra::math::Vec2;
+use tetra::{Context, ContextBuilder, State};
+
+const WINDOW_WIDTH: f32 = 640.0;
+const WINDOW_HEIGHT: f32 = 480.0;
+const DARK_SLATE_BLUE: Color = Color::rgb(0.2823529, 0.2392157, 0.5450980);
+
+struct GameState {
+ chess_board: Texture,
+ dark_piece: Texture,
+ light_piece: Texture,
+ dark_king: Texture,
+ light_king: Texture,
+ bit_board: CheckersBitBoard,
+}
+
+impl GameState {
+ fn new(ctx: &mut Context) -> tetra::Result<Self> {
+ Ok(GameState {
+ chess_board: Texture::new(ctx, "./ui/resources/chess_board.png")?,
+ dark_piece: Texture::new(ctx, "./ui/resources/red_piece.png")?,
+ light_piece: Texture::new(ctx, "./ui/resources/white_piece.png")?,
+ dark_king: Texture::new(ctx, "./ui/resources/red_king.png")?,
+ light_king: Texture::new(ctx, "./ui/resources/white_king.png")?,
+ bit_board: CheckersBitBoard::starting_position(),
+ })
+ }
+}
+
+impl State for GameState {
+ fn draw(&mut self, ctx: &mut Context) -> tetra::Result {
+ graphics::clear(ctx, DARK_SLATE_BLUE);
+
+ let board_draw_params = DrawParams::new()
+ .position(Vec2::new(120.0, 40.0))
+ .scale(Vec2::new(0.4938272, 0.4938272));
+
+ self.chess_board.draw(ctx, board_draw_params);
+
+ for row in 0..8 {
+ for col in 0..8 {
+ if let Some(piece) = self.bit_board.get_at_row_col(row, col) {
+ let piece_draw_params = DrawParams::new()
+ .position(Vec2::new(
+ 130.0 + (50.0 * col as f32),
+ 400.0 - (50.0 * row as f32),
+ ))
+ .scale(Vec2::new(0.3, 0.3));
+
+ match piece.color() {
+ PieceColor::Dark => {
+ if piece.is_king() {
+ self.dark_king.draw(ctx, piece_draw_params)
+ } else {
+ self.dark_piece.draw(ctx, piece_draw_params)
+ }
+ }
+ PieceColor::Light => {
+ if piece.is_king() {
+ self.light_king.draw(ctx, piece_draw_params)
+ } else {
+ self.light_piece.draw(ctx, piece_draw_params)
+ }
+ }
+ }
+ }
+ }
+ }
+
+ Ok(())
+ }
+}
+
+fn main() -> tetra::Result {
+ let title = "Checkers with Ampere";
+ let mut builder = ContextBuilder::new(title, WINDOW_WIDTH as i32, WINDOW_HEIGHT as i32);
+
+ builder.show_mouse(true);
+ builder.quit_on_escape(true);
+
+ if cfg!(debug_assertions) {
+ builder.debug_info(true);
+ } else {
+ builder.debug_info(false);
+ }
+
+ builder.build()?.run(GameState::new)
+}