Compare commits
No commits in common. "1061ae6ce0379823c0705b519014f72429b9a864" and "654d6ccf1a9f90c3571f9baf617e32e3f50c2a47" have entirely different histories.
1061ae6ce0
...
654d6ccf1a
5 changed files with 35 additions and 39 deletions
Binary file not shown.
Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 187 B |
Binary file not shown.
Before Width: | Height: | Size: 342 B After Width: | Height: | Size: 189 B |
|
@ -444,20 +444,23 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) {
|
pub fn draw(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) {
|
||||||
d.clear_background(BG_WORLD);
|
d.clear_background(gray(48));
|
||||||
|
|
||||||
if self.draw_overlay && self.zoom >= 0.5 {
|
if self.draw_overlay && self.zoom >= 1. {
|
||||||
let tile_size = TILE_TEXTURE_SIZE * self.zoom;
|
let tile_size = (TILE_TEXTURE_SIZE * self.zoom) as f32;
|
||||||
let grid_spill_x = (self.view_offset.x).rem(tile_size) - tile_size;
|
let grid_spill_x = (self.view_offset.x).rem(tile_size) - tile_size;
|
||||||
let grid_spill_y = (self.view_offset.y).rem(tile_size) - tile_size;
|
let grid_spill_y = (self.view_offset.y).rem(tile_size) - tile_size;
|
||||||
for y in 0..=(d.get_screen_height() / tile_size as i32) {
|
d.gui_grid(
|
||||||
let y = y * tile_size as i32 + grid_spill_y as i32;
|
Rectangle::new(
|
||||||
d.draw_line(0, y, d.get_screen_width(), y, FG_GRID);
|
grid_spill_x,
|
||||||
}
|
grid_spill_y,
|
||||||
for x in 0..=(d.get_screen_width() / tile_size as i32) {
|
d.get_screen_width() as f32 * 2.,
|
||||||
let x = x * tile_size as i32 + grid_spill_x as i32;
|
d.get_screen_height() as f32 * 2.,
|
||||||
d.draw_line(x, 0, x, d.get_screen_height(), FG_GRID);
|
),
|
||||||
}
|
None,
|
||||||
|
tile_size,
|
||||||
|
1,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.draw_board(d, textures);
|
self.draw_board(d, textures);
|
||||||
|
|
|
@ -179,6 +179,25 @@ impl Machine {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for &(pos, _val, _dir) in &new_marbles {
|
||||||
|
let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
*claim = match claim {
|
||||||
|
Claim::Free => Claim::Claimed,
|
||||||
|
Claim::Claimed | Claim::Blocked => Claim::Blocked,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// new marbles are past old_marbles index, so will not move this step
|
||||||
|
for (pos, value, dir) in new_marbles {
|
||||||
|
let Some(Tile::Open(OpenTile::Blank, Claim::Claimed)) = self.board.get_mut(pos) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
self.board.set(pos, Tile::Marble { value, dir });
|
||||||
|
self.marbles.push(pos);
|
||||||
|
}
|
||||||
|
|
||||||
// old wires have to be reset after machine processing,
|
// old wires have to be reset after machine processing,
|
||||||
// so they can figure out which directions they are powered from
|
// so they can figure out which directions they are powered from
|
||||||
for &p in &self.powered {
|
for &p in &self.powered {
|
||||||
|
@ -201,7 +220,7 @@ impl Machine {
|
||||||
Multiple,
|
Multiple,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #### find all direct bounces ####
|
// find all direct bounces
|
||||||
let mut will_reverse_direction = vec![false; self.marbles.len()];
|
let mut will_reverse_direction = vec![false; self.marbles.len()];
|
||||||
// todo store in tile to remove search through self.marbles
|
// todo store in tile to remove search through self.marbles
|
||||||
let mut influenced_direction = vec![DirInfluence::None; self.marbles.len()];
|
let mut influenced_direction = vec![DirInfluence::None; self.marbles.len()];
|
||||||
|
@ -242,7 +261,7 @@ impl Machine {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #### apply all direct bounces ####
|
// apply all direct bounces
|
||||||
for (i, &pos) in self.marbles.iter().enumerate() {
|
for (i, &pos) in self.marbles.iter().enumerate() {
|
||||||
let Some(Tile::Marble { value: _, dir }) = self.board.get_mut(pos) else {
|
let Some(Tile::Marble { value: _, dir }) = self.board.get_mut(pos) else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
@ -254,29 +273,6 @@ impl Machine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #### new marbles ####
|
|
||||||
// prepare creating the new marbles
|
|
||||||
for &(pos, _val, _dir) in &new_marbles {
|
|
||||||
let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
*claim = match claim {
|
|
||||||
Claim::Free => Claim::Claimed,
|
|
||||||
Claim::Claimed | Claim::Blocked => Claim::Blocked,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// create new marbles
|
|
||||||
// new marbles are past old_marbles index, so will not move this step
|
|
||||||
for (pos, value, dir) in new_marbles {
|
|
||||||
let Some(Tile::Open(OpenTile::Blank, Claim::Claimed)) = self.board.get_mut(pos) else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
self.board.set(pos, Tile::Marble { value, dir });
|
|
||||||
self.marbles.push(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// #### movement ####
|
|
||||||
let mut claim_positions = Vec::new();
|
let mut claim_positions = Vec::new();
|
||||||
// mark claims to figure out what spaces can be moved to
|
// mark claims to figure out what spaces can be moved to
|
||||||
for &pos in &self.marbles[..old_marbles] {
|
for &pos in &self.marbles[..old_marbles] {
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
pub const BG_WORLD: Color = gray(48);
|
|
||||||
pub const FG_GRID: Color = gray(64);
|
|
||||||
|
|
||||||
pub const BG_DARK: Color = gray(32);
|
pub const BG_DARK: Color = gray(32);
|
||||||
pub const BG_MEDIUM: Color = gray(48);
|
pub const BG_MEDIUM: Color = gray(48);
|
||||||
pub const BG_LIGHT: Color = gray(64);
|
pub const BG_LIGHT: Color = gray(64);
|
||||||
|
|
Loading…
Add table
Reference in a new issue