Drawing a simple board
This commit is contained in:
parent
8650bbe9b2
commit
aac66bffb5
3 changed files with 56 additions and 18 deletions
30
src/app.rs
30
src/app.rs
|
|
@ -1,13 +1,39 @@
|
||||||
|
|
||||||
|
use graphics::*;
|
||||||
use piston::*;
|
use piston::*;
|
||||||
|
|
||||||
pub struct App;
|
use board::Board;
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
board: Board,
|
||||||
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new() -> App {
|
pub fn new() -> App {
|
||||||
App
|
App {
|
||||||
|
board: Board::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game for App {
|
impl Game for App {
|
||||||
|
fn render(&self, c: &Context, gl: &mut Gl) {
|
||||||
|
self.board.render(c, gl);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, _dt: f64, _asset_store: &mut AssetStore) {}
|
||||||
|
|
||||||
|
fn load(&mut self, _asset_store: &mut AssetStore) {}
|
||||||
|
|
||||||
|
fn key_press(
|
||||||
|
&mut self,
|
||||||
|
_key: keyboard::Key,
|
||||||
|
_asset_store: &mut AssetStore
|
||||||
|
) {}
|
||||||
|
|
||||||
|
fn key_release(
|
||||||
|
&mut self,
|
||||||
|
_key: keyboard::Key,
|
||||||
|
_asset_store: &mut AssetStore
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ extern crate piston;
|
||||||
use piston::*;
|
use piston::*;
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
mod board;
|
||||||
mod settings;
|
mod settings;
|
||||||
|
|
||||||
type GameWindowBackEnd = GameWindowSDL2;
|
type GameWindowBackEnd = GameWindowSDL2;
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,46 @@
|
||||||
|
|
||||||
pub static ASSET_FOLDER: &'static str = "assets";
|
pub static ASSET_FOLDER: &'static str = "assets";
|
||||||
|
|
||||||
pub static WINDOW_SIZE: [u32, ..2] = [400, 400];
|
pub static WINDOW_SIZE: [u32, ..2] = [
|
||||||
|
(BOARD_PADDING * 2.0 + BOARD_SIZE[0]) as u32,
|
||||||
|
(BOARD_PADDING * 2.0 + BOARD_SIZE[1] + BOARD_OFFSET_Y) as u32,
|
||||||
|
];
|
||||||
pub static WINDOW_BACKGROUND_COLOR: [f32, ..4] = [250.0 / 255.0, 248.0 / 255.0, 239.0 / 255.0, 1.0];
|
pub static WINDOW_BACKGROUND_COLOR: [f32, ..4] = [250.0 / 255.0, 248.0 / 255.0, 239.0 / 255.0, 1.0];
|
||||||
pub static WINDOW_PADDING: f64 = 12.0;
|
|
||||||
|
|
||||||
pub static TILE_SIZE: [f64, ..2] = [72.0, 72.0];
|
pub static BOARD_PADDING: f64 = 12.0;
|
||||||
pub static TILE_PADDING: f64 = 12.0;
|
pub static BOARD_SIZE: [f64, ..2] = [
|
||||||
|
TILE_SIZE * TILE_WIDTH as f64 + TILE_PADDING * (TILE_WIDTH + 1) as f64,
|
||||||
|
TILE_SIZE * TILE_HEIGHT as f64 + TILE_PADDING * (TILE_HEIGHT + 1) as f64,
|
||||||
|
];
|
||||||
|
pub static BOARD_OFFSET_Y: f64 = 128.0;
|
||||||
|
|
||||||
|
pub static TILE_WIDTH: uint = 4;
|
||||||
|
pub static TILE_HEIGHT: uint = 4;
|
||||||
|
pub static TILE_SIZE: f64 = 96.0;
|
||||||
|
pub static TILE_PADDING: f64 = 16.0;
|
||||||
pub static TILE_BACKGROUND_COLOR: [f32, ..4] = [187.0 / 255.0, 173.0 / 255.0, 160.0 / 255.0, 1.0];
|
pub static TILE_BACKGROUND_COLOR: [f32, ..4] = [187.0 / 255.0, 173.0 / 255.0, 160.0 / 255.0, 1.0];
|
||||||
pub static TILES_COLOR: [[f32, ..4], ..12] = [
|
pub static TILES_COLOR: [[f32, ..4], ..10] = [
|
||||||
/// empty color
|
// empty color
|
||||||
[204.0 / 255.0, 192.0 / 255.0, 179.0 / 255.0, 1.0],
|
[204.0 / 255.0, 192.0 / 255.0, 179.0 / 255.0, 1.0],
|
||||||
/// 2 color
|
// 2 color
|
||||||
[238.0 / 255.0, 228.0 / 255.0, 218.0 / 255.0, 1.0],
|
[238.0 / 255.0, 228.0 / 255.0, 218.0 / 255.0, 1.0],
|
||||||
/// 4 color
|
// 4 color
|
||||||
[237.0 / 255.0, 224.0 / 255.0, 200.0 / 255.0, 1.0],
|
[237.0 / 255.0, 224.0 / 255.0, 200.0 / 255.0, 1.0],
|
||||||
/// 8 color
|
// 8 color
|
||||||
[242.0 / 255.0, 177.0 / 255.0, 121.0 / 255.0, 1.0],
|
[242.0 / 255.0, 177.0 / 255.0, 121.0 / 255.0, 1.0],
|
||||||
/// 16 color
|
// 16 color
|
||||||
[245.0 / 255.0, 149.0 / 255.0, 99.0 / 255.0, 1.0],
|
[245.0 / 255.0, 149.0 / 255.0, 99.0 / 255.0, 1.0],
|
||||||
/// 32 color
|
// 32 color
|
||||||
[246.0 / 255.0, 124.0 / 255.0, 95.0 / 255.0, 1.0],
|
[246.0 / 255.0, 124.0 / 255.0, 95.0 / 255.0, 1.0],
|
||||||
/// 64 color
|
// 64 color
|
||||||
[246.0 / 255.0, 94.0 / 255.0, 59.0 / 255.0, 1.0],
|
[246.0 / 255.0, 94.0 / 255.0, 59.0 / 255.0, 1.0],
|
||||||
/// 128 color
|
// 128 color
|
||||||
[237.0 / 255.0, 207.0 / 255.0, 114.0 / 255.0, 1.0],
|
[237.0 / 255.0, 207.0 / 255.0, 114.0 / 255.0, 1.0],
|
||||||
/// 256 color
|
// 256 color
|
||||||
[237.0 / 255.0, 204.0 / 255.0, 97.0 / 255.0, 1.0],
|
[237.0 / 255.0, 204.0 / 255.0, 97.0 / 255.0, 1.0],
|
||||||
/// 512 color
|
// 512 color
|
||||||
[237.0 / 255.0, 200.0 / 255.0, 80.0 / 255.0, 1.0],
|
[237.0 / 255.0, 200.0 / 255.0, 80.0 / 255.0, 1.0],
|
||||||
]
|
];
|
||||||
|
|
||||||
pub static LABEL_COLOR: [f32, ..4] = [187.0 / 255.0, 173.0 / 255.0, 160.0 / 255.0, 1.0];
|
pub static LABEL_COLOR: [f32, ..4] = [187.0 / 255.0, 173.0 / 255.0, 160.0 / 255.0, 1.0];
|
||||||
pub static BUTTON_COLOR: [f32, ..4] = [142.0 / 255.0, 122.0 / 255.0, 102.0 / 255.0, 1.0];
|
pub static BUTTON_COLOR: [f32, ..4] = [142.0 / 255.0, 122.0 / 255.0, 102.0 / 255.0, 1.0];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue