Update crates.

Fmt.
Clippy.
This commit is contained in:
2017-11-21 09:50:59 +01:00
parent ec42cb33e0
commit ac57e9ee38
13 changed files with 320 additions and 194 deletions

View File

@@ -1,14 +1,16 @@
use std::cell::RefCell;
use sdl2::render::{Texture, Renderer};
use sdl2::render::{Canvas, Texture};
use sdl2::video::Window;
use sdl2::rect::Rect;
pub trait Sprite {
fn render(&self, f64, &mut Renderer, &Rect);
fn render(&self, f64, &mut Canvas<Window>, &Rect);
}
pub struct StaticSprite<'a> {
texture: &'a Texture,
texture: &'a Texture<'a>,
x: i32,
y: i32,
pub flip_horizontal: bool,
@@ -28,19 +30,21 @@ impl<'a> StaticSprite<'a> {
}
impl<'a> Sprite for StaticSprite<'a> {
fn render(&self, _: f64, drawer: &mut Renderer, destination: &Rect) {
let _ = drawer.copy_ex(self.texture,
Some(Rect::new(self.x, self.y, 16, 16)),
Some(*destination),
0.0,
None,
self.flip_horizontal,
self.flip_vertical);
fn render(&self, _: f64, drawer: &mut Canvas<Window>, destination: &Rect) {
let _ = drawer.copy_ex(
self.texture,
Some(Rect::new(self.x, self.y, 16, 16)),
Some(*destination),
0.0,
None,
self.flip_horizontal,
self.flip_vertical,
);
}
}
pub struct AnimatedSprite<'a> {
texture: &'a Texture,
texture: &'a Texture<'a>,
x: i32,
y: i32,
pub flip_horizontal: bool,
@@ -68,7 +72,7 @@ impl<'a> AnimatedSprite<'a> {
}
impl<'a> Sprite for AnimatedSprite<'a> {
fn render(&self, elapsed: f64, drawer: &mut Renderer, destination: &Rect) {
fn render(&self, elapsed: f64, drawer: &mut Canvas<Window>, destination: &Rect) {
let mut time = self.time.borrow_mut();
let mut frame = self.frame.borrow_mut();
@@ -79,12 +83,14 @@ impl<'a> Sprite for AnimatedSprite<'a> {
let x = self.x + (*frame * 16) as i32;
let _ = drawer.copy_ex(self.texture,
Some(Rect::new(x, self.y, 16, 16)),
Some(*destination),
0.0,
None,
self.flip_horizontal,
self.flip_vertical);
let _ = drawer.copy_ex(
self.texture,
Some(Rect::new(x, self.y, 16, 16)),
Some(*destination),
0.0,
None,
self.flip_horizontal,
self.flip_vertical,
);
}
}