From 19a1f4b8f9bfa865f859c054ac4312d6b85aa925 Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Wed, 8 Jun 2016 00:33:27 +0200 Subject: [PATCH] Update SDL2 and SDL2 Image. --- Cargo.lock | 139 ++++++++++++++++++++++++--------------- Cargo.toml | 4 +- src/main.rs | 7 +- src/player_components.rs | 14 +++- 4 files changed, 102 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b2a306..5d0f305 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,102 +2,137 @@ name = "super-matte-bros" version = "0.0.1" dependencies = [ - "sdl2 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sdl2_image 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "advapi32-sys" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2_image 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" -version = "0.3.2" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "bitflags" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "0.1.16" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.2" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "num" -version = "0.1.27" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "num-bigint 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-complex 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "rand" -version = "0.3.11" +name = "num-bigint" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-complex" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-rational" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-bigint 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-serialize" -version = "0.3.16" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "sdl2" -version = "0.16.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", - "sdl2-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sdl2-sys" -version = "0.8.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sdl2_image" -version = "0.16.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "sdl2 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sdl2-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "winapi" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - diff --git a/Cargo.toml b/Cargo.toml index 474c5e1..1774661 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ version = "0.0.1" authors = ["logaritmisk "] [dependencies] -sdl2 = "0.16.0" -sdl2_image = "0.16.0" +sdl2 = "0.19.0" +sdl2_image = "0.19.0" [[bin]] name = "super-matte-bros" diff --git a/src/main.rs b/src/main.rs index 1fd678a..61a5f62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,7 @@ fn main() { let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); - let _image_context = sdl2_image::init(sdl2_image::INIT_PNG).unwrap(); + let _ = sdl2_image::init(sdl2_image::INIT_PNG).unwrap(); let window = video_subsystem.window("Super Matte Bros", SCREEN_WIDTH, SCREEN_HEIGHT).position_centered().build().unwrap(); let mut renderer = window.renderer().software().build().unwrap(); @@ -85,7 +85,6 @@ fn main() { layer.set_tile(3, 17, Tile::Background(Rect::new(16 * 8, 16 * 9, 16, 16))); layer.set_tile(4, 17, Tile::Background(Rect::new(16 * 10, 16 * 8, 16, 16))); - layer.set_tile(11, 17, Tile::Background(Rect::new(16 * 11, 16 * 9, 16, 16))); layer.set_tile(12, 17, Tile::Background(Rect::new(16 * 12, 16 * 9, 16, 16))); layer.set_tile(13, 17, Tile::Background(Rect::new(16 * 12, 16 * 9, 16, 16))); @@ -164,9 +163,7 @@ fn main() { let mut camera = Camera::new(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, layer.to_rect()); - let previous = timer.current_time(); - - let mut previous : f64 = 0.0; + let mut previous = timer.current_time(); let mut lag = 0.0; let mut event_pump = sdl_context.event_pump().unwrap(); diff --git a/src/player_components.rs b/src/player_components.rs index 7e28aec..aa23422 100644 --- a/src/player_components.rs +++ b/src/player_components.rs @@ -17,7 +17,8 @@ impl Updatable for PlayerPhysicsComponent { pub struct PlayerGraphicsComponent<'a> { flip_horizontal: Cell, sprite_standing: RefCell>, - sprite_running: RefCell> + sprite_running: RefCell>, + sprite_jumping: RefCell> } impl<'a> PlayerGraphicsComponent<'a> { @@ -25,14 +26,21 @@ impl<'a> PlayerGraphicsComponent<'a> { PlayerGraphicsComponent { flip_horizontal: Cell::new(false), sprite_standing: RefCell::new(StaticSprite::new(&texture, 80, 32)), - sprite_running: RefCell::new(AnimatedSprite::new(&texture, 96, 32, 3, 10.0)) + sprite_running: RefCell::new(AnimatedSprite::new(&texture, 96, 32, 3, 10.0)), + sprite_jumping: RefCell::new(StaticSprite::new(&texture, 160, 32)) } } } impl<'a> Renderable for PlayerGraphicsComponent<'a> { fn render(&self, object: &GameObject, elapsed: f64, renderer: &mut Renderer, destination: &Rect) { - if object.dx == 0.0 { + if !object.on_ground { + let mut sprite = self.sprite_jumping.borrow_mut(); + + sprite.flip_horizontal = self.flip_horizontal.get(); + + sprite.render(elapsed, renderer, destination); + } else if object.dx == 0.0 { let mut sprite = self.sprite_standing.borrow_mut(); sprite.flip_horizontal = self.flip_horizontal.get();