make all powerable tiles also store a powered state that can be rendered
This commit is contained in:
parent
bf46a3e7c3
commit
12bd19a7f3
3 changed files with 152 additions and 144 deletions
|
@ -13,22 +13,28 @@ pub type MarbleValue = u32;
|
|||
pub enum Tile {
|
||||
#[default]
|
||||
Blank,
|
||||
Block,
|
||||
Comment(u8),
|
||||
Bag,
|
||||
Marble {
|
||||
value: MarbleValue,
|
||||
dir: Direction,
|
||||
},
|
||||
Trigger(bool),
|
||||
Digit(u8),
|
||||
Wire(WireType, bool),
|
||||
Gate(GateType),
|
||||
Print,
|
||||
Input,
|
||||
Flip,
|
||||
Math(MathOp),
|
||||
Mirror(MirrorType),
|
||||
Arrow(Direction),
|
||||
Powerable(PTile, bool),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum PTile {
|
||||
Wire(WireType),
|
||||
Gate(GateType),
|
||||
Math(MathOp),
|
||||
Bag,
|
||||
Flipper,
|
||||
Input,
|
||||
Output,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
@ -89,16 +95,17 @@ impl Tile {
|
|||
let right = x + size / 2 - 1;
|
||||
match self {
|
||||
Tile::Blank => (),
|
||||
Tile::Block => d.draw_rectangle(x - size / 2, y - size / 2, size, size, Color::DIMGRAY),
|
||||
Tile::Comment(c) => {
|
||||
d.draw_text(&format!("{}", *c as char), x - 10, y - 10, 20, Color::RED)
|
||||
d.draw_rectangle(x-size/2, y-size/2, size, size, Color::DIMGRAY);
|
||||
d.draw_text(&format!("{}", *c as char), x - 10, y - 10, 20, Color::WHITE);
|
||||
}
|
||||
Tile::Bag => d.draw_circle_lines(x, y, size as f32 * 0.4, Color::CYAN),
|
||||
Tile::Marble { value, dir } => {
|
||||
d.draw_circle(x, y, size as f32 * 0.35, Color::new(15, 15, 15, 255));
|
||||
d.draw_text(
|
||||
&format!("{value}"),
|
||||
x - size / 2,
|
||||
y - size / 2,
|
||||
x - size / 2 + 2,
|
||||
y - size / 2 + 2,
|
||||
20,
|
||||
Color::MAGENTA,
|
||||
);
|
||||
|
@ -110,24 +117,6 @@ impl Tile {
|
|||
Tile::Digit(n) => {
|
||||
d.draw_text(&String::from(*n as char), x - 10, y - 10, 20, Color::ORANGE)
|
||||
}
|
||||
Tile::Wire(wire, state) => {
|
||||
let color = if *state { Color::RED } else { Color::WHITE };
|
||||
let vertical = !matches!(wire, WireType::Horizontal);
|
||||
let horizontal = !matches!(wire, WireType::Vertical);
|
||||
if vertical {
|
||||
// d.draw_line(x, up, x, down, color);
|
||||
d.draw_rectangle(x - size / 8, y - size / 2, size / 4, size, color)
|
||||
}
|
||||
if horizontal {
|
||||
// d.draw_line(left, y, right, y, color);
|
||||
d.draw_rectangle(x - size / 2, y - size / 8, size, size / 4, color)
|
||||
}
|
||||
}
|
||||
// Tile::Gate(_) => todo!(),
|
||||
// Tile::Print => todo!(),
|
||||
// Tile::Input => todo!(),
|
||||
// Tile::Flip => todo!(),
|
||||
// Tile::Math(_) => todo!(),
|
||||
Tile::Mirror(mirror) => {
|
||||
let height = size as f32 * 1.25;
|
||||
let width = (size / 4) as f32;
|
||||
|
@ -156,7 +145,32 @@ impl Tile {
|
|||
};
|
||||
d.draw_triangle(v1, v2, v3, Color::CYAN);
|
||||
}
|
||||
_ => d.draw_rectangle(x - size / 2, y - size / 2, size, size, Color::YELLOW),
|
||||
Tile::Powerable(tile, state) => {
|
||||
let color = if *state { Color::RED } else { Color::LIGHTGRAY };
|
||||
match tile {
|
||||
PTile::Bag => {
|
||||
d.draw_circle(x, y, size as f32 * 0.4, color);
|
||||
d.draw_circle(x, y, size as f32 * 0.2, Color::GRAY);
|
||||
}
|
||||
PTile::Wire(wire) => {
|
||||
let vertical = !matches!(wire, WireType::Horizontal);
|
||||
let horizontal = !matches!(wire, WireType::Vertical);
|
||||
if vertical {
|
||||
d.draw_rectangle(x - size / 8, y - size / 2, size / 4, size, color)
|
||||
}
|
||||
if horizontal {
|
||||
d.draw_rectangle(x - size / 2, y - size / 8, size, size / 4, color)
|
||||
}
|
||||
}
|
||||
// PTile::Gate(_) => todo!(),
|
||||
// PTile::Math(_) => todo!(),
|
||||
// PTile::Print => todo!(),
|
||||
// PTile::Input => todo!(),
|
||||
// PTile::Flip => todo!(),
|
||||
_ => d.draw_rectangle(x - size / 2, y - size / 2, size, size, color),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue