Implement automatic tile creation

This commit is contained in:
2019-04-02 20:27:05 +02:00
parent c296c8cd08
commit 7bab06b2b6
6 changed files with 207 additions and 175 deletions
+10 -6
View File
@@ -6,7 +6,8 @@ use sfml::window::mouse::Button;
use sfml::graphics::{RectangleShape, RenderTarget, Transformable, Color, Shape};
use rusty::engine::renderer::Renderer;
use rusty::engine::map::{GraphicTile, CollisionTile, Map};
use rusty::engine::map::{CollisionTile, Map};
use rusty::engine::texture::SPRITE_SIZE_I32;
fn main() {
let _ = App::new("Rusty Editor")
@@ -17,7 +18,7 @@ fn main() {
let mut running = true;
let mut map = Map::load("./assets/levels/level2.lvl").unwrap();
let mut map = Map::new(50, 50);//;Map::load("./assets/levels/level2.lvl").unwrap();
loop {
let top_panel_size = Vector2::new(renderer.window().size().x as f32, 50.0);
@@ -39,8 +40,8 @@ fn main() {
button: Button::Left, x, y,
} => {
if x as f32 >= left_panel_size.x && y as f32 >= top_panel_size.y {
let x = ((x - left_panel_size.x as i32) / 16) as usize;
let y = ((y - top_panel_size.y as i32) / 16) as usize;
let x = ((x - left_panel_size.x as i32) / SPRITE_SIZE_I32) as usize;
let y = ((y - top_panel_size.y as i32) / SPRITE_SIZE_I32) as usize;
if let Some(tile) = map.tile(y, x) {
if tile == CollisionTile::empty() {
@@ -74,7 +75,7 @@ fn main() {
for i in 0 .. map.rows() {
for j in 0 .. map.cols() {
let tile = map.at(i, j);
if tile.graphic != GraphicTile::Hidden {
if tile.graphic.is_visible() {
renderer.translate_and_draw(&tile, (left_panel_size.x, top_panel_size.y));
}
}
@@ -82,7 +83,10 @@ fn main() {
// Draw the border of the map
let mut border = RectangleShape::new();
border.set_size(((map.cols() * 16) as f32, (map.rows() * 16) as f32));
border.set_size(((
map.cols() * SPRITE_SIZE_I32 as usize) as f32,
(map.rows() * SPRITE_SIZE_I32 as usize) as f32
));
border.set_position((left_panel_size.x, top_panel_size.y));
border.set_fill_color(&Color::rgba(0, 0, 0, 0));
border.set_outline_color(&Color::rgb(0, 0, 0));