Cleaning for clippy
This commit is contained in:
parent
2a4a6a7dc9
commit
c841d08d14
|
@ -68,7 +68,7 @@ fn main() {
|
||||||
let controls = if gamepads.is_empty() {
|
let controls = if gamepads.is_empty() {
|
||||||
Controls::default_keyboard()
|
Controls::default_keyboard()
|
||||||
} else {
|
} else {
|
||||||
gamepads[0].clone()
|
gamepads[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut character = Character::with_controls(controls);
|
let mut character = Character::with_controls(controls);
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl Character {
|
||||||
Character {
|
Character {
|
||||||
position: Vector2::new(0.0, 0.0),
|
position: Vector2::new(0.0, 0.0),
|
||||||
speed: Vector2::new(0.0, 0.0),
|
speed: Vector2::new(0.0, 0.0),
|
||||||
controls: controls,
|
controls,
|
||||||
side: Side::Right,
|
side: Side::Right,
|
||||||
jump_counter: 1,
|
jump_counter: 1,
|
||||||
max_jump: 1,
|
max_jump: 1,
|
||||||
|
@ -162,14 +162,10 @@ impl Updatable for Character {
|
||||||
|
|
||||||
let mut force: Vector2<f32> = Vector2::new(0.0, 0.0);
|
let mut force: Vector2<f32> = Vector2::new(0.0, 0.0);
|
||||||
|
|
||||||
match self.controls {
|
if let Some(ref controls) = self.controls {
|
||||||
Some(ref controls) => {
|
|
||||||
force += controls.direction();
|
force += controls.direction();
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(side) = Side::from_force(force) {
|
if let Some(side) = Side::from_force(force) {
|
||||||
|
|
||||||
self.side = side;
|
self.side = side;
|
||||||
|
|
|
@ -202,7 +202,7 @@ impl GamepadMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(GamepadMap {
|
Some(GamepadMap {
|
||||||
id: id,
|
id,
|
||||||
jump_button: 1,
|
jump_button: 1,
|
||||||
run_button: 0,
|
run_button: 0,
|
||||||
left_right_axis: Axis::X,
|
left_right_axis: Axis::X,
|
||||||
|
|
|
@ -26,16 +26,16 @@ pub enum CollisionAxis {
|
||||||
|
|
||||||
impl CollisionAxis {
|
impl CollisionAxis {
|
||||||
/// Returns true if the collision occured on X axis.
|
/// Returns true if the collision occured on X axis.
|
||||||
pub fn is_x(&self) -> bool {
|
pub fn is_x(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
CollisionAxis::Y => false,
|
CollisionAxis::Y => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the collision occured on Y axis.
|
/// Returns true if the collision occured on Y axis.
|
||||||
pub fn is_y(&self) -> bool {
|
pub fn is_y(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
CollisionAxis::X => false,
|
CollisionAxis::X => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
|
@ -120,32 +120,32 @@ pub enum GraphicTile {
|
||||||
impl GraphicTile {
|
impl GraphicTile {
|
||||||
|
|
||||||
/// Checks if a graphic tile has a top border.
|
/// Checks if a graphic tile has a top border.
|
||||||
pub fn is_top(&self) -> bool {
|
pub fn is_top(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
GraphicTile::TopLeft | GraphicTile::Top | GraphicTile::TopRight => true,
|
GraphicTile::TopLeft | GraphicTile::Top | GraphicTile::TopRight => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a graphic tile has a left border.
|
/// Checks if a graphic tile has a left border.
|
||||||
pub fn is_left(&self) -> bool {
|
pub fn is_left(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
GraphicTile::TopLeft | GraphicTile::Left | GraphicTile::BottomLeft => true,
|
GraphicTile::TopLeft | GraphicTile::Left | GraphicTile::BottomLeft => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a graphic tile has a right border.
|
/// Checks if a graphic tile has a right border.
|
||||||
pub fn is_right(&self) -> bool {
|
pub fn is_right(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
GraphicTile::TopRight | GraphicTile::Right | GraphicTile::BottomRight => true,
|
GraphicTile::TopRight | GraphicTile::Right | GraphicTile::BottomRight => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a graphic tile has a bottom border.
|
/// Checks if a graphic tile has a bottom border.
|
||||||
pub fn is_bottom(&self) -> bool {
|
pub fn is_bottom(self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
GraphicTile::BottomLeft | GraphicTile::Bottom | GraphicTile::BottomRight => true,
|
GraphicTile::BottomLeft | GraphicTile::Bottom | GraphicTile::BottomRight => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -178,10 +178,10 @@ impl GraphicTile {
|
||||||
bottom: Option<CollisionTile>) -> GraphicTile {
|
bottom: Option<CollisionTile>) -> GraphicTile {
|
||||||
|
|
||||||
GraphicTile::from_neighbours(
|
GraphicTile::from_neighbours(
|
||||||
top.unwrap_or(CollisionTile::full()),
|
top.unwrap_or_else(CollisionTile::full),
|
||||||
left.unwrap_or(CollisionTile::full()),
|
left.unwrap_or_else(CollisionTile::full),
|
||||||
right.unwrap_or(CollisionTile::full()),
|
right.unwrap_or_else(CollisionTile::full),
|
||||||
bottom.unwrap_or(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.
|
/// Returns the offset to the corresponding graphic tile in the texture.
|
||||||
pub fn offset(&self) -> (i32, i32) {
|
pub fn offset(self) -> (i32, i32) {
|
||||||
let vertical = match *self {
|
let vertical = match self {
|
||||||
GraphicTile::TopLeft | GraphicTile::Top | GraphicTile::TopRight => 0,
|
GraphicTile::TopLeft | GraphicTile::Top | GraphicTile::TopRight => 0,
|
||||||
GraphicTile::Left | GraphicTile::Center | GraphicTile::Right => 16,
|
GraphicTile::Left | GraphicTile::Center | GraphicTile::Right => 16,
|
||||||
GraphicTile::BottomLeft | GraphicTile::Bottom | GraphicTile::BottomRight => 32,
|
GraphicTile::BottomLeft | GraphicTile::Bottom | GraphicTile::BottomRight => 32,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let horizontal = match *self {
|
let horizontal = match self {
|
||||||
GraphicTile::TopLeft | GraphicTile::Left | GraphicTile::BottomLeft => 0,
|
GraphicTile::TopLeft | GraphicTile::Left | GraphicTile::BottomLeft => 0,
|
||||||
GraphicTile::Top | GraphicTile::Center | GraphicTile::Bottom => 16,
|
GraphicTile::Top | GraphicTile::Center | GraphicTile::Bottom => 16,
|
||||||
GraphicTile::TopRight | GraphicTile::Right | GraphicTile::BottomRight => 32,
|
GraphicTile::TopRight | GraphicTile::Right | GraphicTile::BottomRight => 32,
|
||||||
|
@ -351,10 +351,10 @@ impl Map {
|
||||||
let (i, j) = (i as isize, j as isize);
|
let (i, j) = (i as isize, j as isize);
|
||||||
|
|
||||||
GraphicTile::from_neighbour_options(
|
GraphicTile::from_neighbour_options(
|
||||||
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)).map(|x| *x),
|
tiles.get(((i-1) as usize, (j ) as usize)).cloned(),
|
||||||
tiles.get(((i+1) as usize, (j ) as usize)).map(|x| *x),
|
tiles.get(((i+1) as usize, (j ) as usize)).cloned(),
|
||||||
tiles.get(((i ) as usize, (j+1) as usize)).map(|x| *x),
|
tiles.get(((i ) as usize, (j+1) as usize)).cloned(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
GraphicTile::Hidden
|
GraphicTile::Hidden
|
||||||
|
@ -419,8 +419,8 @@ impl Map {
|
||||||
let mut new = new;
|
let mut new = new;
|
||||||
|
|
||||||
|
|
||||||
for col in min_col .. max_col + 1 {
|
for col in min_col ..= max_col {
|
||||||
for row in min_row .. max_row + 1 {
|
for row in min_row ..= max_row {
|
||||||
|
|
||||||
let tile_left = col as f32 * 16.0;
|
let tile_left = col as f32 * 16.0;
|
||||||
let tile_top = row as f32 * 16.0;
|
let tile_top = row as f32 * 16.0;
|
||||||
|
@ -432,61 +432,52 @@ impl Map {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collisions between feet and ground
|
// Collisions between feet and ground
|
||||||
if self.tiles[(row, col)].0.from_top {
|
if self.tiles[(row, col)].0.from_top &&
|
||||||
|
old.top + old.height <= tile_top &&
|
||||||
if old.top + old.height <= tile_top &&
|
|
||||||
new.top + new.height >= tile_top {
|
new.top + new.height >= tile_top {
|
||||||
|
|
||||||
collision_y = true;
|
collision_y = true;
|
||||||
new.top = tile_top - new.height;
|
new.top = tile_top - new.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ! overlap(new, tile) {
|
if ! overlap(new, tile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collisions between right and right wall
|
// 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 &&
|
||||||
if old.left + old.width <= tile_left &&
|
|
||||||
new.left + new.width >= tile_left {
|
new.left + new.width >= tile_left {
|
||||||
|
|
||||||
collision_x = true;
|
collision_x = true;
|
||||||
new.left = tile_left - new.width;
|
new.left = tile_left - new.width;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ! overlap(new, tile) {
|
if ! overlap(new, tile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collisions between left and left wall
|
// 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 &&
|
||||||
if old.left >= tile_left + 16.0 &&
|
|
||||||
new.left <= tile_left + 16.0 {
|
new.left <= tile_left + 16.0 {
|
||||||
|
|
||||||
collision_x = true;
|
collision_x = true;
|
||||||
new.left = tile_left + 16.0;
|
new.left = tile_left + 16.0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ! overlap(new, tile) {
|
if ! overlap(new, tile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collisions between head and roof
|
// 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 &&
|
||||||
if old.top >= tile_top + 16.0 &&
|
|
||||||
new.top <= tile_top + 16.0 {
|
new.top <= tile_top + 16.0 {
|
||||||
|
|
||||||
collision_y = true;
|
collision_y = true;
|
||||||
new.top = tile_top + 16.0;
|
new.top = tile_top + 16.0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ impl<T> Matrix<T> where T: Clone {
|
||||||
/// Creates a matrix from an element and duplicates it.
|
/// Creates a matrix from an element and duplicates it.
|
||||||
pub fn from_size(rows: usize, cols: usize, element: T) -> Matrix<T> {
|
pub fn from_size(rows: usize, cols: usize, element: T) -> Matrix<T> {
|
||||||
Matrix {
|
Matrix {
|
||||||
rows: rows,
|
rows,
|
||||||
cols: cols,
|
cols,
|
||||||
data: vec![element; rows * cols],
|
data: vec![element; rows * cols],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl Renderer {
|
||||||
window.set_framerate_limit(60);
|
window.set_framerate_limit(60);
|
||||||
|
|
||||||
Renderer {
|
Renderer {
|
||||||
window: window,
|
window,
|
||||||
texture_manager: TextureManager::new(),
|
texture_manager: TextureManager::new(),
|
||||||
started: Instant::now(),
|
started: Instant::now(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue