diff --git a/Cargo.lock b/Cargo.lock index d1d6abd..24c80d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,16 +44,6 @@ name = "autocfg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bincode" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bitflags" version = "1.0.4" @@ -554,11 +544,9 @@ dependencies = [ name = "rusty" version = "0.1.0" dependencies = [ - "bincode 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "imageproc 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "sfml 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -577,24 +565,6 @@ name = "scopeguard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "serde" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sfml" version = "0.14.0" @@ -705,7 +675,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum bincode 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3efe0b4c8eaeed8600549c29f538a6a11bf422858d0ed435b1d70ec4ab101190" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" @@ -767,8 +736,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum safe-transmute 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9604873ffe1980bc1f179103704a65c8aca141c248d9e52b7af95ff10578166e" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" -"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" "checksum sfml 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47b06f9db4d3f8b936d232d92bfbd6335060ae51ddcf1be2e79361aeb5c8fef1" "checksum sfml-build 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff35ae173aff95bc967d1b4f0e131a8aec384c317fd057738da4b0f71c8cf841" "checksum stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "69b7df505db8e81d54ff8be4693421e5b543e08214bd8d99eb761fcb4d5668ba" diff --git a/Cargo.toml b/Cargo.toml index 34b31fa..2d3ef3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,6 @@ edition = "2018" [dependencies] clap = "2.32.0" sfml = "0.14.0" -serde = { version = "1.0.89", features = ["derive"] } -bincode = "1.1.2" [build-dependencies] image = { version = "0.21.0" } @@ -18,6 +16,3 @@ imageproc = "0.18.0" name = "rusty-maker" path = "src/app/game.rs" -[[bin]] -name = "rusty-editor" -path = "src/app/editor/main.rs" diff --git a/assets/levels/level1.lvl b/assets/levels/level1.lvl index e579fd8..a09ce43 100644 Binary files a/assets/levels/level1.lvl and b/assets/levels/level1.lvl differ diff --git a/assets/levels/level2.lvl b/assets/levels/level2.lvl index 08e6acb..2e96908 100644 Binary files a/assets/levels/level2.lvl and b/assets/levels/level2.lvl differ diff --git a/assets/textures/rusty-walking.png b/assets/textures/rusty-walking.png new file mode 100644 index 0000000..45a1a4b Binary files /dev/null and b/assets/textures/rusty-walking.png differ diff --git a/assets/textures/rusty.png b/assets/textures/rusty.png new file mode 100644 index 0000000..6805f4f Binary files /dev/null and b/assets/textures/rusty.png differ diff --git a/build.rs b/build.rs index 7768444..29e2fbb 100644 --- a/build.rs +++ b/build.rs @@ -1,13 +1,13 @@ use std::fs::create_dir_all; -use image::{RgbaImage, GenericImage}; -use image::imageops::{rotate90, rotate180, rotate270}; +use image::imageops::{rotate180, rotate270, rotate90}; +use image::{GenericImage, RgbaImage}; fn superpose(image: &RgbaImage, superposition: &RgbaImage) -> RgbaImage { let mut clone = image.clone(); - for i in 0 .. image.width() { - for j in 0 .. image.height() { + for i in 0..image.width() { + for j in 0..image.height() { let new_pixel = superposition.get_pixel(i, j); if new_pixel[3] > 0 { *clone.get_pixel_mut(i, j) = *new_pixel; @@ -23,9 +23,9 @@ fn main() { let mut texture = image::open("assets/textures/grass.png").unwrap().to_rgba(); let background = texture.sub_image(0, 0, 32, 32).to_image(); let border = texture.sub_image(32, 0, 32, 32).to_image(); - let corner_horiz = texture.sub_image(32 * 2 , 0, 32, 32).to_image(); - let corner_vert = texture.sub_image(32 * 3, 0, 32, 32).to_image(); - let corner_inside = texture.sub_image(32 * 4, 0, 32, 32).to_image(); + let corner_horiz = texture.sub_image(32 * 2, 0, 32, 32).to_image(); + let corner_vert = texture.sub_image(32 * 3, 0, 32, 32).to_image(); + let corner_inside = texture.sub_image(32 * 4, 0, 32, 32).to_image(); let corner_outside = texture.sub_image(32 * 5, 0, 32, 32).to_image(); let mut background_color = texture.sub_image(32 * 6, 0, 32, 32); let background_color = background_color.get_pixel_mut(0, 0); @@ -68,7 +68,13 @@ fn main() { let image_29 = superpose(&image_1, &image_28); vec.push(&image_29); - let image_31 = superpose(&superpose(&border, &superpose(&rotate90(&border), &rotate90(&corner_inside))), &corner_horiz); + let image_31 = superpose( + &superpose( + &border, + &superpose(&rotate90(&border), &rotate90(&corner_inside)), + ), + &corner_horiz, + ); let image_31 = superpose(&image_31, &rotate180(&corner_vert)); vec.push(&image_31); @@ -132,8 +138,17 @@ fn main() { let image_125 = superpose(&image_1, &image_124); vec.push(&image_125); - let image_127 = superpose(&superpose(&border, &superpose(&rotate90(&border), &rotate90(&corner_inside))), &corner_horiz); - let image_127 = superpose(&superpose(&image_127, &rotate180(&corner_inside)), &rotate180(&border)); + let image_127 = superpose( + &superpose( + &border, + &superpose(&rotate90(&border), &rotate90(&corner_inside)), + ), + &corner_horiz, + ); + let image_127 = superpose( + &superpose(&image_127, &rotate180(&corner_inside)), + &rotate180(&border), + ); let image_127 = superpose(&image_127, &rotate270(&corner_vert)); vec.push(&image_127); @@ -173,7 +188,13 @@ fn main() { let image_253 = rotate180(&image_223); vec.push(&image_253); - let image_255 = superpose(&border, &superpose(&rotate90(&border), &superpose(&rotate180(&border), &rotate270(&border)))); + let image_255 = superpose( + &border, + &superpose( + &rotate90(&border), + &superpose(&rotate180(&border), &rotate270(&border)), + ), + ); let image_255 = superpose(&image_255, &corner_inside); let image_255 = superpose(&image_255, &rotate90(&corner_inside)); let image_255 = superpose(&image_255, &rotate180(&corner_inside)); @@ -182,8 +203,8 @@ fn main() { let mut output = RgbaImage::new(32 * 47, 32); for (index, image) in vec.into_iter().enumerate() { - for y in 0 .. image.width() { - for x in 0 .. image.height() { + for y in 0..image.width() { + for x in 0..image.height() { let new_pixel = image.get_pixel(x, y); if new_pixel != background_color { *output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y); @@ -197,5 +218,3 @@ fn main() { output.save("assets/textures-generated/grass.png").unwrap(); } - - diff --git a/src/app/editor/main.rs b/src/app/editor/main.rs deleted file mode 100644 index 84481f4..0000000 --- a/src/app/editor/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -use clap::{App, crate_version}; - -use rusty::app::editor::Editor; - -fn main() { - let _ = App::new("Rusty Editor") - .version(crate_version!()) - .get_matches(); - - Editor::new().run(); -} diff --git a/src/app/editor/mod.rs b/src/app/editor/mod.rs deleted file mode 100644 index cb7f713..0000000 --- a/src/app/editor/mod.rs +++ /dev/null @@ -1,230 +0,0 @@ -use sfml::system::Vector2; -use sfml::window::{Event, Key, mouse::Button as MouseButton}; -use sfml::graphics::{Color, RectangleShape, RenderTarget, Transformable, Shape}; - -use crate::engine::renderer::Renderer; -use crate::engine::map::{CollisionTile, Map}; -use crate::engine::texture::SPRITE_SIZE_I32; -use crate::engine::font::Font; -use crate::Result; - -/// An action caused by a button. -#[derive(Copy, Clone)] -pub enum Action { - /// Saves the level. - Save, -} - -/// A button that can be clicked. -pub struct Button { - /// The label of the button. - pub label: String, - - /// The position of the button. - pub position: Vector2, - - /// The size of the button. - pub size: Vector2, - - /// The action of the button. - action: Action, -} - -impl Button { - /// Creates a new button. - pub fn new(label: &str, action: Action, x: f32, y: f32, w: f32, h: f32) -> Button { - Button { - action, - label: label.to_owned(), - position: Vector2::new(x, y), - size: Vector2::new(w, h), - } - } - - /// Returns the shape of the button. - pub fn shape(&self) -> RectangleShape { - let mut shape = RectangleShape::new(); - shape.set_position(self.position + 0.1 * self.size); - shape.set_size(self.size - 0.2 * self.size); - shape.set_fill_color(&Color::rgb(255, 255, 255)); - shape - } - - /// Draws the button on the renderer. - pub fn render_on(&self, renderer: &mut Renderer) { - renderer.window_mut().draw(&self.shape()); - renderer.draw_text( - &self.label, - Font::Sansation, - self.size.y as u32 / 2, - &Color::rgb(0, 0, 0) - ); - } - - /// Returns true if the coordinates fall inside the shape of the button. - pub fn contains(&self, x: f32, y: f32) -> bool { - let shape = self.shape(); - x > shape.position().x && x < shape.position().x + shape.size().x && - y > shape.position().y && y < shape.position().y + shape.size().y - } -} - -/// Represents a level editor. -pub struct Editor { - /// The renderer used by the editor. - renderer: Renderer, - - /// The map being currently edited. - map: Map, - - /// Indicates whether the editor is running or not. - running: bool, - - /// The size of the left panel. - left_panel_size: Vector2, - - /// The size of the top panel. - top_panel_size: Vector2, - - /// The buttons of the menu bar. - menu_bar: Vec