From 11ac199dd1760fce2f1e9f4d9d0c0c83700171f9 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Tue, 21 Apr 2020 19:29:24 +0200 Subject: [PATCH] Bringing back things together --- Cargo.lock | 33 ----- Cargo.toml | 5 - assets/levels/level1.lvl | Bin 10040 -> 630 bytes assets/levels/level2.lvl | Bin 24040 -> 2906 bytes assets/textures/rusty-walking.png | Bin 0 -> 1008 bytes assets/textures/rusty.png | Bin 0 -> 2051 bytes build.rs | 49 +++++-- src/app/editor/main.rs | 11 -- src/app/editor/mod.rs | 230 ------------------------------ src/app/game.rs | 48 ++++--- src/app/mod.rs | 2 - src/engine/character/mod.rs | 41 +++--- src/engine/font/mod.rs | 3 +- src/engine/map/mod.rs | 185 +++++++++++++----------- src/engine/math/mod.rs | 8 +- src/engine/renderer/mod.rs | 10 +- src/engine/scene/mod.rs | 7 +- src/engine/texture/mod.rs | 60 ++++---- src/lib.rs | 13 +- 19 files changed, 231 insertions(+), 474 deletions(-) create mode 100644 assets/textures/rusty-walking.png create mode 100644 assets/textures/rusty.png delete mode 100644 src/app/editor/main.rs delete mode 100644 src/app/editor/mod.rs delete mode 100644 src/app/mod.rs 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 e579fd8f999c99603ced147423e3ee76ae7a6f45..a09ce43fb0ea5ee18203cac2015c7d9d4e47a0f1 100644 GIT binary patch literal 630 zcmXpsRxmQ*GEg814ybxV1w(Y#;&l(H>am0bUh|1nkHsA@e_%DARP|Wg0XH9H7BLWF Oh9MU*YC&qqRSy72r(vD| literal 10040 zcmeIwF%AMT5ClO8c?=2v4|y0M6K!Z$fKXpz`J`=mdiH)<-}QSw#`(N`e;gjy_jiam z9v5#AjME_E4T4dQWk9$TjQXgLxdZLhG_rpeE(K#h!I~6r5R7uv$J~MTY8u(U3zvei zpI}XjHwZ>K>SOLedo_*h--S!T*iWz~f8hchDdr1}sR9iu*+OF^m+VbL+_!?_fs`VbZ!=Vcw&2;lpTwF&%yA6&*UI$~^H_{V0amM2<;L^*%x4Uo1N1PSb=hnlIKm7D=2>i} zlHEKkaj}n=!T77)CHSj(2x~-6^{@AmpUS`*cx)R(--Z2NBNQPIKZ8W2=Y+uUD3g6D dgRFmzL88*G*s`|$EBteDw7L$@fnDBCVcfZR#2x?u literal 24040 zcmeI3TW*9f3`IMAS6xAWy1Fj1%PY5F$%959CC=c4!%vE)7~e-66K1|1=Hs%A-^=*3 zjK81DAA=5;>3E*7X?$_xpm6_jf_GGPXCI?4`i{Z?^?6>GM$vPP1AWnV?TMbx@iTtz z*}v=D@iTs2d!pxa{EVOP;a~Yoduke<8s1RxGd%D6JYK;Y#(?Mb$o)y5M~%LUvo$aL zeU8Taw#?s;3N<~RTfF(tBk?Nk7S9!sHZRp}w|LX%E$WqzdyD7Iq#J(d^NQBjcx-`J zd6)R7XS^kRf;Xn06pveVqjrjx#&4x>EuL1_XT__$O6t)bPnq$S)Fbd-Gtf$3#jWw9 z&nt5M_Hi@y8_KIieb0*b+J$jv;En4yTGZECrTsj4pMvRJW9{L66IpL+^J;ZHcv~@> zBd+vqv7XeTQ(o2=JWj!Ms&Ujq_^ggb_8VFG0&mRvi@rG+IHR9!-H7b3a;QlbFwi#x zsz=s8wR~@$g(Y8qc`nPMN?ac38^>kFNYdB(iJI>TWW+{JFaQJRVnFrG`Y-mc#?xN% zvR^lzu7>E0`da_RevY|-5e8u3NCs4gt&cj(K9<#Co`a8cUfI3zYZ-4`m4gBNn?nb( zfPqK`nAeeP5-S@6XY{x2Kc3}%H_t`cW*zy!01UvuJ_CMz=6&csU%mZ@^tFD3-!Js0 M-hRI5JO5te55VgR&;S4c diff --git a/assets/textures/rusty-walking.png b/assets/textures/rusty-walking.png new file mode 100644 index 0000000000000000000000000000000000000000..45a1a4b4c6e622f942f173bed136b8d0481300f9 GIT binary patch literal 1008 zcmVljA6vxja5~TxESrAJW7Sv>6g3V$;LPD(s3tRI6%94$VF7yKgiM2yVCd`Dynn)dB zz)Lr(4jpI*1_q;d?TcOxpX2|X9T(+!X%hSVe)sO(`QG2Ji2;vEnihjBOQ;!ro*u88 zVSZ@8ha7N2*Jv!nLV$5^yWpO2Po>e;0ob^&=ly%X>?NT?vCso@TnU1WNyGGcDF7UJ zO+r8(kN~~W=08Ed_VdgnFW*D=gf3%1jWM|I1GfR3C^*&1*f3e9_*iK2TG}WzQ1MFBMGSBdGJxs>st>3>p!EYB185%L z#tys?&236owtirB^#LhPbfOPPal!{czauIMGz(l0l<5QL^o#wv+QJ^-n`r$2 zc|z+4nkZs`gHZJWyWWpBXXX9+{{`;qru75JThr)GsT3(t*EjYwth@jBJw@S#NcDlT zq?Em)^#fWzp!EYtQrgH$cr68r)v2K9^!2@6j;|_cIw@fAWxuF45WFF2vW6gdKj6~| e5N&`w@D~}#KD|)LQ854j002ovPDHLkV1fXiqs2P_ literal 0 HcmV?d00001 diff --git a/assets/textures/rusty.png b/assets/textures/rusty.png new file mode 100644 index 0000000000000000000000000000000000000000..6805f4fc44f294548aa04e5d5443c862298612d7 GIT binary patch literal 2051 zcmX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_XB*iKY&OgglUJ;D#P-5`_4%`$T3|8EU8I{P%#{z9IN zJoYF8$#72p=%0WpqJ^E)vwg2@N%1%1kw5%J^j45Tq_2z%C^lh zb?EU}swvWeXtBwCo=Y{PR2*LJZDpS=ip^J%MQaU;?+%-F1P$tQNqY5PDdG-$Uos_H zRVw`5?3K%l8LyZR4Sh6NxdE&+#?Y(LfBssKWr>>Og^w^HxuMS+k83w1;UBb?Q~z~+ zyEgU*ua-myFpJvSPKASid0XvHc0n7y!i{7cNibh)!*GC{1&AWT;TuFzDW(^qsGW&i zg{R_xpP}**&f%)md0+N0rs3b~KXkRuHVhy@;nx9W13K_Sl9kUHwHCv_Y=^0X#>L8U zR)-kD!|G3aBCoh*2~fET%Lw8`IOA7Y(rhPc-DB^xUbpMW*GnQWsyHcqg#y*Ftet7Ua}DQ~yEYSFe(TG&51d@BdDj<$ec5wc6a_T6I= zk~I8y%0{!v@`AU&pyJlKimi?CJH>hIPbCE_9dAC?BUIq+x)p5n*!(N6HTX&{eLQ>o zy)mkU;Wg<5S063!AqMh z5H=WX`g8r4gX=n@bHOE1@96FIw8%dL0uJ$`bq?1hHP85<(_1E`LiU_95$jD zILD>XtBz+vSbblMet7C<052@GB(WP#TuK*@9Xx;%A@%7X-*y%L!Idf<@wt%+?dj{)q#DLD&%Q5kM5RhY8GVnG3{S zGG=ih)|MKzv35KrnKc6F%%Jr#f}-ga0m_$i$N?7lK)(1*5r4}Z&h~oa+U&aZL+Gy# N5S(3|*hhVD{2%8)(#!w= literal 0 HcmV?d00001 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