|
@@ -6,6 +6,23 @@ use std::path::Path;
|
|
|
/// we only care about 16x16 tilesets
|
|
|
const TILE_SIZE: f32 = 1.0 / 16.0;
|
|
|
|
|
|
+#[derive(Eq, PartialEq, Debug, Copy, Clone)]
|
|
|
+pub enum Color {
|
|
|
+ Red,
|
|
|
+ Green,
|
|
|
+ Blue,
|
|
|
+}
|
|
|
+
|
|
|
+impl From<Color> for ggez::graphics::Color {
|
|
|
+ fn from(color: Color) -> ggez::graphics::Color {
|
|
|
+ match color {
|
|
|
+ Color::Red => [1.0, 0.0, 0.0, 1.0].into(),
|
|
|
+ Color::Green => [0.0, 1.0, 0.0, 1.0].into(),
|
|
|
+ Color::Blue => [0.0, 0.0, 1.0, 1.0].into(),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
pub struct Board {
|
|
|
size: Size,
|
|
|
contents: Vec<(u8, SpriteIdx)>,
|
|
@@ -93,6 +110,16 @@ impl Board {
|
|
|
self.tileset.batch.set(self.contents[idx].1, param).unwrap();
|
|
|
}
|
|
|
|
|
|
+ pub fn set_with_color(&mut self, at: impl Into<Coord>, ch: u8, color: impl Into<ggez::graphics::Color>) {
|
|
|
+ let at = at.into();
|
|
|
+ let idx = at.x + at.y * self.size.width;
|
|
|
+ let param = DrawParam::new()
|
|
|
+ .src(Board::sprite_location(ch).into())
|
|
|
+ .dest(self.tileset.to_screen(at))
|
|
|
+ .color(color.into());
|
|
|
+ self.tileset.batch.set(self.contents[idx].1, param).unwrap();
|
|
|
+ }
|
|
|
+
|
|
|
pub fn get(&mut self, at: impl Into<Coord>) -> u8 {
|
|
|
let at = at.into();
|
|
|
let idx = at.x + at.y * self.size.width;
|