Clean up some warnings.

This commit is contained in:
2016-06-07 23:54:15 +02:00
parent bdd3d4db3a
commit a4f31c0397
5 changed files with 6 additions and 61 deletions

View File

@@ -1,10 +1,9 @@
#[deny(trivial_casts, trivial_numeric_casts)]
extern crate sdl2; extern crate sdl2;
extern crate sdl2_image; extern crate sdl2_image;
use std::path::Path; use std::path::Path;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use sdl2_image::LoadTexture; use sdl2_image::LoadTexture;
use sdl2::rect::Rect; use sdl2::rect::Rect;
@@ -15,7 +14,6 @@ use sdl2::render::{Renderer, Texture};
use tile::Layer; use tile::Layer;
use camera::Camera; use camera::Camera;
// use player::Player;
use keyboard::KeyboardHandler; use keyboard::KeyboardHandler;
use sprite::{Sprite, StaticSprite, AnimatedSprite}; use sprite::{Sprite, StaticSprite, AnimatedSprite};
use timer::Timer; use timer::Timer;
@@ -24,11 +22,9 @@ use timer::Timer;
mod timer; mod timer;
mod tile; mod tile;
mod camera; mod camera;
mod player;
mod keyboard; mod keyboard;
mod sprite; mod sprite;
const SCREEN_WIDTH : u32 = 960; const SCREEN_WIDTH : u32 = 960;
const SCREEN_HEIGHT : u32 = 640; const SCREEN_HEIGHT : u32 = 640;
@@ -44,7 +40,6 @@ const PLAYER_ACCELERATION_X_START : f32 = 0.02;
const PLAYER_ACCELERATION_X_STOP : f32 = 0.15; const PLAYER_ACCELERATION_X_STOP : f32 = 0.15;
const PLAYER_ACCELERATION_X_CHANGE : f32 = 0.06; const PLAYER_ACCELERATION_X_CHANGE : f32 = 0.06;
struct GameObject<'a> { struct GameObject<'a> {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,
@@ -95,15 +90,13 @@ trait Renderable {
fn render(&self, &GameObject, f64, &mut Renderer, &Rect); fn render(&self, &GameObject, f64, &mut Renderer, &Rect);
} }
struct PlayerPhysicsComponent; struct PlayerPhysicsComponent;
impl Updatable for PlayerPhysicsComponent { impl Updatable for PlayerPhysicsComponent {
fn update(&self, object: &GameObject) { fn update(&self, _: &GameObject) {
} }
} }
struct PlayerGraphicsComponent<'a> { struct PlayerGraphicsComponent<'a> {
flip_horizontal: Cell<bool>, flip_horizontal: Cell<bool>,
sprite_standing: RefCell<StaticSprite<'a>>, sprite_standing: RefCell<StaticSprite<'a>>,
@@ -144,7 +137,6 @@ impl<'a> Renderable for PlayerGraphicsComponent<'a> {
} }
} }
#[derive(Clone)] #[derive(Clone)]
enum Tile<'a> { enum Tile<'a> {
Empty, Empty,
@@ -153,7 +145,6 @@ enum Tile<'a> {
Floor(Rect) Floor(Rect)
} }
fn main() { 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();
@@ -553,7 +544,5 @@ fn main() {
player.render(elapsed, &mut renderer, &player_rect); player.render(elapsed, &mut renderer, &player_rect);
renderer.present(); renderer.present();
// sleep(std::time::Duration::from_millis(5));
} }
} }

View File

@@ -1,42 +0,0 @@
use sdl2::rect::Rect;
pub struct Player {
pub x: f32,
pub y: f32,
pub w: u32,
pub h: u32,
pub dx: f32,
pub dy: f32,
pub gravity: f32,
pub on_ground: bool
}
impl Player {
pub fn new(x: f32, y: f32) -> Player {
Player {
x: x,
y: y,
w: 32,
h: 32,
dx: 0.0,
dy: 0.0,
gravity: 0.3,
on_ground: false
}
}
pub fn update(&mut self) {
self.dy += self.gravity;
if self.dy > 8.0 {
self.dy = 8.0;
} else if self.dy < -8.0 {
self.dy = -8.0;
}
}
pub fn to_rect(&self) -> Rect {
Rect::new(self.x as i32, self.y as i32, self.w, self.h)
}
}

View File

@@ -30,8 +30,8 @@ impl<'a> StaticSprite<'a> {
} }
impl<'a> Sprite for StaticSprite<'a> { impl<'a> Sprite for StaticSprite<'a> {
fn render(&self, elapsed: f64, drawer: &mut Renderer, destination: &Rect) { fn render(&self, _: f64, drawer: &mut Renderer, destination: &Rect) {
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); 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);
} }
} }
@@ -76,6 +76,6 @@ impl<'a> Sprite for AnimatedSprite<'a> {
let x = self.x + (*frame * 16) as i32; let x = self.x + (*frame * 16) as i32;
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);
} }
} }

View File

@@ -72,7 +72,6 @@ impl<T> Layer<T> where T: Clone {
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::Layer; use super::Layer;

View File

@@ -1,5 +1,4 @@
use std::time::{Duration, Instant}; use std::time::Instant;
pub struct Timer { pub struct Timer {
time: Instant time: Instant