Cleaning for clippy

This commit is contained in:
Thomas Forgione 2018-11-19 15:21:02 +01:00
parent 2a4a6a7dc9
commit c841d08d14
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
6 changed files with 53 additions and 66 deletions

View File

@ -68,7 +68,7 @@ fn main() {
let controls = if gamepads.is_empty() {
Controls::default_keyboard()
} else {
gamepads[0].clone()
gamepads[0]
};
let mut character = Character::with_controls(controls);

View File

@ -97,7 +97,7 @@ impl Character {
Character {
position: Vector2::new(0.0, 0.0),
speed: Vector2::new(0.0, 0.0),
controls: controls,
controls,
side: Side::Right,
jump_counter: 1,
max_jump: 1,
@ -162,12 +162,8 @@ impl Updatable for Character {
let mut force: Vector2<f32> = Vector2::new(0.0, 0.0);
match self.controls {
Some(ref controls) => {
force += controls.direction();
}
_ => (),
if let Some(ref controls) = self.controls {
force += controls.direction();
}
if let Some(side) = Side::from_force(force) {

View File

@ -202,7 +202,7 @@ impl GamepadMap {
}
Some(GamepadMap {
id: id,
id,
jump_button: 1,
run_button: 0,
left_right_axis: Axis::X,

View File

@ -26,16 +26,16 @@ pub enum CollisionAxis {
impl CollisionAxis {
/// Returns true if the collision occured on X axis.
pub fn is_x(&self) -> bool {
match *self {
pub fn is_x(self) -> bool {
match self {
CollisionAxis::Y => false,
_ => true,
}
}
/// Returns true if the collision occured on Y axis.
pub fn is_y(&self) -> bool {
match *self {
pub fn is_y(self) -> bool {
match self {
CollisionAxis::X => false,
_ => true,
}
@ -120,32 +120,32 @@ pub enum GraphicTile {
impl GraphicTile {
/// Checks if a graphic tile has a top border.
pub fn is_top(&self) -> bool {
match *self {
pub fn is_top(self) -> bool {
match self {
GraphicTile::TopLeft | GraphicTile::Top | GraphicTile::TopRight => true,
_ => false,
}
}
/// Checks if a graphic tile has a left border.
pub fn is_left(&self) -> bool {
match *self {
pub fn is_left(self) -> bool {
match self {
GraphicTile::TopLeft | GraphicTile::Left | GraphicTile::BottomLeft => true,
_ => false,
}
}
/// Checks if a graphic tile has a right border.
pub fn is_right(&self) -> bool {
match *self {
pub fn is_right(self) -> bool {
match self {
GraphicTile::TopRight | GraphicTile::Right | GraphicTile::BottomRight => true,
_ => false,
}
}
/// Checks if a graphic tile has a bottom border.
pub fn is_bottom(&self) -> bool {
match *self {
pub fn is_bottom(self) -> bool {
match self {
GraphicTile::BottomLeft | GraphicTile::Bottom | GraphicTile::BottomRight => true,
_ => false,
}
@ -178,10 +178,10 @@ impl GraphicTile {
bottom: Option<CollisionTile>) -> GraphicTile {
GraphicTile::from_neighbours(
top.unwrap_or(CollisionTile::full()),
left.unwrap_or(CollisionTile::full()),
right.unwrap_or(CollisionTile::full()),
bottom.unwrap_or(CollisionTile::full()),
top.unwrap_or_else(CollisionTile::full),
left.unwrap_or_else(CollisionTile::full),
right.unwrap_or_else(CollisionTile::full),
bottom.unwrap_or_else(CollisionTile::full),
)
}
@ -227,15 +227,15 @@ impl GraphicTile {
}
/// Returns the offset to the corresponding graphic tile in the texture.
pub fn offset(&self) -> (i32, i32) {
let vertical = match *self {
pub fn offset(self) -> (i32, i32) {
let vertical = match self {
GraphicTile::TopLeft | GraphicTile::Top | GraphicTile::TopRight => 0,
GraphicTile::Left | GraphicTile::Center | GraphicTile::Right => 16,
GraphicTile::BottomLeft | GraphicTile::Bottom | GraphicTile::BottomRight => 32,
_ => 0,
};
let horizontal = match *self {
let horizontal = match self {
GraphicTile::TopLeft | GraphicTile::Left | GraphicTile::BottomLeft => 0,
GraphicTile::Top | GraphicTile::Center | GraphicTile::Bottom => 16,
GraphicTile::TopRight | GraphicTile::Right | GraphicTile::BottomRight => 32,
@ -351,10 +351,10 @@ impl Map {
let (i, j) = (i as isize, j as isize);
GraphicTile::from_neighbour_options(
tiles.get(((i ) as usize, (j-1) as usize)).map(|x| *x),
tiles.get(((i-1) as usize, (j ) as usize)).map(|x| *x),
tiles.get(((i+1) as usize, (j ) as usize)).map(|x| *x),
tiles.get(((i ) as usize, (j+1) as usize)).map(|x| *x),
tiles.get(((i ) as usize, (j-1) as usize)).cloned(),
tiles.get(((i-1) as usize, (j ) as usize)).cloned(),
tiles.get(((i+1) as usize, (j ) as usize)).cloned(),
tiles.get(((i ) as usize, (j+1) as usize)).cloned(),
)
} else {
GraphicTile::Hidden
@ -419,8 +419,8 @@ impl Map {
let mut new = new;
for col in min_col .. max_col + 1 {
for row in min_row .. max_row + 1 {
for col in min_col ..= max_col {
for row in min_row ..= max_row {
let tile_left = col as f32 * 16.0;
let tile_top = row as f32 * 16.0;
@ -432,15 +432,12 @@ impl Map {
}
// Collisions between feet and ground
if self.tiles[(row, col)].0.from_top {
if old.top + old.height <= tile_top &&
new.top + new.height >= tile_top {
collision_y = true;
new.top = tile_top - new.height;
}
if self.tiles[(row, col)].0.from_top &&
old.top + old.height <= tile_top &&
new.top + new.height >= tile_top {
collision_y = true;
new.top = tile_top - new.height;
}
if ! overlap(new, tile) {
@ -448,14 +445,12 @@ impl Map {
}
// Collisions between right and right wall
if self.tiles[(row, col)].0.from_left {
if self.tiles[(row, col)].0.from_left &&
old.left + old.width <= tile_left &&
new.left + new.width >= tile_left {
if old.left + old.width <= tile_left &&
new.left + new.width >= tile_left {
collision_x = true;
new.left = tile_left - new.width;
}
collision_x = true;
new.left = tile_left - new.width;
}
if ! overlap(new, tile) {
@ -463,14 +458,12 @@ impl Map {
}
// Collisions between left and left wall
if self.tiles[(row, col)].0.from_right {
if self.tiles[(row, col)].0.from_right &&
old.left >= tile_left + 16.0 &&
new.left <= tile_left + 16.0 {
if old.left >= tile_left + 16.0 &&
new.left <= tile_left + 16.0 {
collision_x = true;
new.left = tile_left + 16.0;
}
collision_x = true;
new.left = tile_left + 16.0;
}
if ! overlap(new, tile) {
@ -478,14 +471,12 @@ impl Map {
}
// Collisions between head and roof
if self.tiles[(row, col)].0.from_bottom {
if self.tiles[(row, col)].0.from_bottom &&
old.top >= tile_top + 16.0 &&
new.top <= tile_top + 16.0 {
if old.top >= tile_top + 16.0 &&
new.top <= tile_top + 16.0 {
collision_y = true;
new.top = tile_top + 16.0;
}
collision_y = true;
new.top = tile_top + 16.0;
}
}

View File

@ -46,8 +46,8 @@ impl<T> Matrix<T> where T: Clone {
/// Creates a matrix from an element and duplicates it.
pub fn from_size(rows: usize, cols: usize, element: T) -> Matrix<T> {
Matrix {
rows: rows,
cols: cols,
rows,
cols,
data: vec![element; rows * cols],
}
}

View File

@ -62,7 +62,7 @@ impl Renderer {
window.set_framerate_limit(60);
Renderer {
window: window,
window,
texture_manager: TextureManager::new(),
started: Instant::now(),
}