Update SDL2 and SDL2 Image.

This commit is contained in:
2016-06-08 00:33:27 +02:00
parent 9926aa177c
commit 19a1f4b8f9
4 changed files with 102 additions and 62 deletions

139
Cargo.lock generated
View File

@@ -2,102 +2,137 @@
name = "super-matte-bros" name = "super-matte-bros"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"sdl2 0.16.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.16.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 = "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)",
] ]
[[package]] [[package]]
name = "bitflags" 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" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "0.1.16" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.1.10" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "num" name = "num"
version = "0.1.27" version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "num-bigint 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (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]] [[package]]
name = "rand" name = "num-bigint"
version = "0.3.11" version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.4 (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]] [[package]]
name = "rustc-serialize" name = "rustc-serialize"
version = "0.3.16" version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "sdl2" name = "sdl2"
version = "0.16.1" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.1.16 (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.2 (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.27 (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.11 (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.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "sdl2-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "sdl2-sys" name = "sdl2-sys"
version = "0.8.1" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ 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]] [[package]]
name = "sdl2_image" name = "sdl2_image"
version = "0.16.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "sdl2 0.19.0 (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.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.8.1 (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"

View File

@@ -4,8 +4,8 @@ version = "0.0.1"
authors = ["logaritmisk <anders.e.olsson@gmail.com>"] authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
[dependencies] [dependencies]
sdl2 = "0.16.0" sdl2 = "0.19.0"
sdl2_image = "0.16.0" sdl2_image = "0.19.0"
[[bin]] [[bin]]
name = "super-matte-bros" name = "super-matte-bros"

View File

@@ -53,7 +53,7 @@ fn main() {
let sdl_context = sdl2::init().unwrap(); let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().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 window = video_subsystem.window("Super Matte Bros", SCREEN_WIDTH, SCREEN_HEIGHT).position_centered().build().unwrap();
let mut renderer = window.renderer().software().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(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(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(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(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))); 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 mut camera = Camera::new(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, layer.to_rect());
let previous = timer.current_time(); let mut previous = timer.current_time();
let mut previous : f64 = 0.0;
let mut lag = 0.0; let mut lag = 0.0;
let mut event_pump = sdl_context.event_pump().unwrap(); let mut event_pump = sdl_context.event_pump().unwrap();

View File

@@ -17,7 +17,8 @@ impl Updatable for PlayerPhysicsComponent {
pub struct PlayerGraphicsComponent<'a> { pub struct PlayerGraphicsComponent<'a> {
flip_horizontal: Cell<bool>, flip_horizontal: Cell<bool>,
sprite_standing: RefCell<StaticSprite<'a>>, sprite_standing: RefCell<StaticSprite<'a>>,
sprite_running: RefCell<AnimatedSprite<'a>> sprite_running: RefCell<AnimatedSprite<'a>>,
sprite_jumping: RefCell<StaticSprite<'a>>
} }
impl<'a> PlayerGraphicsComponent<'a> { impl<'a> PlayerGraphicsComponent<'a> {
@@ -25,14 +26,21 @@ impl<'a> PlayerGraphicsComponent<'a> {
PlayerGraphicsComponent { PlayerGraphicsComponent {
flip_horizontal: Cell::new(false), flip_horizontal: Cell::new(false),
sprite_standing: RefCell::new(StaticSprite::new(&texture, 80, 32)), 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> { impl<'a> Renderable for PlayerGraphicsComponent<'a> {
fn render(&self, object: &GameObject, elapsed: f64, renderer: &mut Renderer, destination: &Rect) { 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(); let mut sprite = self.sprite_standing.borrow_mut();
sprite.flip_horizontal = self.flip_horizontal.get(); sprite.flip_horizontal = self.flip_horizontal.get();