basic tile drawing
This commit is contained in:
parent
1257388168
commit
a0f11b60fb
3 changed files with 43 additions and 5 deletions
35
src/main.rs
35
src/main.rs
|
@ -41,13 +41,18 @@ enum SimState {
|
|||
Stepping,
|
||||
}
|
||||
|
||||
fn load_textures_from(folder: &str, rl: &mut RaylibHandle, thread:&RaylibThread,textures:&mut HashMap<String,Texture2D>){
|
||||
fn load_textures_from(
|
||||
folder: &str,
|
||||
rl: &mut RaylibHandle,
|
||||
thread: &RaylibThread,
|
||||
textures: &mut HashMap<String, Texture2D>,
|
||||
) {
|
||||
for d in read_dir(folder).unwrap().flatten() {
|
||||
let path = d.path();
|
||||
if path.is_file() {
|
||||
let name = path.file_stem().unwrap().to_string_lossy();
|
||||
let texture = rl
|
||||
.load_texture(&thread, &format!("{folder}/{name}.png"))
|
||||
.load_texture(thread, &format!("{folder}/{name}.png"))
|
||||
.unwrap();
|
||||
textures.insert(name.to_string(), texture);
|
||||
}
|
||||
|
@ -233,8 +238,8 @@ impl Game {
|
|||
border,
|
||||
);
|
||||
};
|
||||
tool_button((0, -1), "", Tool::None);
|
||||
tool_button((1, -1), "eraser", Tool::SetTile(tile_to_char(' ')));
|
||||
tool_button((0, -1), "eraser", Tool::SetTile(tile_to_char(' ')));
|
||||
tool_button((1, -1), "", Tool::None);
|
||||
|
||||
tool_button((0, 0), "block", Tool::SetTile(tile_to_char('#')));
|
||||
tool_button((0, 1), "bag_off", Tool::SetTile(tile_to_char('B')));
|
||||
|
@ -251,5 +256,27 @@ impl Game {
|
|||
Tool::SetTile(tile_to_char('|')),
|
||||
);
|
||||
tool_button((1, 2), "wire_cross_off", Tool::SetTile(tile_to_char('+')));
|
||||
|
||||
let mouse_pos = d.get_mouse_position();
|
||||
if self.sim_state == SimState::Editing && mouse_pos.y < footer_top {
|
||||
let tile_pos = (mouse_pos - self.view_offset) / (16 << self.zoom) as f32;
|
||||
let tile_pos = Vector2::new(tile_pos.x.floor(), tile_pos.y.floor());
|
||||
|
||||
let tile_screen_pos = tile_pos * (16 << self.zoom) as f32 + self.view_offset;
|
||||
|
||||
if let Tool::SetTile(tile) = self.active_tool {
|
||||
d.draw_texture_ex(
|
||||
textures.get("selection").unwrap(),
|
||||
tile_screen_pos,
|
||||
0.,
|
||||
(1 << self.zoom) as f32,
|
||||
Color::new(255, 255, 255, 150),
|
||||
);
|
||||
|
||||
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
|
||||
self.source_board.set(tile_pos.into(), tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue