From f4a352d5cded708f4fe16e305e3856056bd7667c Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Sun, 29 Jul 2018 22:59:33 +0200 Subject: [PATCH] Do a rustfmt --- src/main.rs | 65 ++++++++++++++++++++++++++---------------- src/texture_manager.rs | 16 ++++++++--- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6b24a3b..9303035 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,22 @@ -extern crate sdl2; extern crate perlin_noise; +extern crate sdl2; -mod texture_manager; mod canvas_copy_at; +mod texture_manager; mod tile; -use sdl2::EventPump; use sdl2::event::Event; +use sdl2::image::INIT_PNG; use sdl2::keyboard::Keycode; +use sdl2::mouse::MouseButton; use sdl2::pixels::Color; use sdl2::render::WindowCanvas; -use sdl2::image::INIT_PNG; -use sdl2::mouse::MouseButton; +use sdl2::EventPump; use perlin_noise::PerlinNoise; -use texture_manager::TextureManager; use canvas_copy_at::CopyAt; +use texture_manager::TextureManager; use tile::Tile; struct GameState { @@ -51,41 +51,56 @@ fn update(event_pump: &mut EventPump, game_state: &mut GameState) -> bool { for event in event_pump.poll_iter() { match event { Event::Quit { .. } => return true, - Event::KeyDown { keycode: Some(keycode), .. } => { + Event::KeyDown { + keycode: Some(keycode), + .. + } => { match keycode { Keycode::Escape => return true, - Keycode::Up => game_state.camera_y -= 8, - Keycode::Down => game_state.camera_y += 8, - Keycode::Left => game_state.camera_x -= 8, + Keycode::Up => game_state.camera_y -= 8, + Keycode::Down => game_state.camera_y += 8, + Keycode::Left => game_state.camera_x -= 8, Keycode::Right => game_state.camera_x += 8, _ => {} }; - }, + } - Event::MouseButtonDown { mouse_btn: MouseButton::Right, .. } => { + Event::MouseButtonDown { + mouse_btn: MouseButton::Right, + .. + } => { game_state.camera_panning = true; - }, - Event::MouseButtonUp { mouse_btn: MouseButton::Right, .. } => { + } + Event::MouseButtonUp { + mouse_btn: MouseButton::Right, + .. + } => { game_state.camera_panning = false; - }, - Event::MouseMotion { xrel: x, yrel: y, .. } => { + } + Event::MouseMotion { + xrel: x, yrel: y, .. + } => { if game_state.camera_panning { game_state.camera_x -= x; game_state.camera_y -= y; } } - _ => {}, + _ => {} }; } false } -fn render(canvas: &mut WindowCanvas, texture_manager: &TextureManager, map: &[Vec], - game_state: &mut GameState) { +fn render( + canvas: &mut WindowCanvas, + texture_manager: &TextureManager, + map: &[Vec], + game_state: &mut GameState, +) { canvas.clear(); for (y, row) in map.iter().enumerate() { @@ -93,11 +108,13 @@ fn render(canvas: &mut WindowCanvas, texture_manager: &TextureManager, map: &[Ve let texture = &texture_manager[tile.type_]; let (screen_x, screen_y) = world_to_screen(x as i32, y as i32, tile.height); - canvas.copy_at( - texture, - screen_x - game_state.camera_x, - screen_y - game_state.camera_y - ).unwrap(); + canvas + .copy_at( + texture, + screen_x - game_state.camera_x, + screen_y - game_state.camera_y, + ) + .unwrap(); } } diff --git a/src/texture_manager.rs b/src/texture_manager.rs index dceadaf..74e7154 100644 --- a/src/texture_manager.rs +++ b/src/texture_manager.rs @@ -15,11 +15,19 @@ pub struct TextureManager<'a> { impl<'a> TextureManager<'a> { pub fn new(texture_creator: &'a TextureCreator) -> TextureManager<'a> { TextureManager { - bridge_east: texture_creator.load_texture("data/png/bridgeEast.png").unwrap(), - bridge_north: texture_creator.load_texture("data/png/bridgeNorth.png").unwrap(), - crossroad:texture_creator.load_texture("data/png/crossroad.png").unwrap(), + bridge_east: texture_creator + .load_texture("data/png/bridgeEast.png") + .unwrap(), + bridge_north: texture_creator + .load_texture("data/png/bridgeNorth.png") + .unwrap(), + crossroad: texture_creator + .load_texture("data/png/crossroad.png") + .unwrap(), dirt: texture_creator.load_texture("data/png/dirt.png").unwrap(), - dirt_high: texture_creator.load_texture("data/png/dirtHigh.png").unwrap(), + dirt_high: texture_creator + .load_texture("data/png/dirtHigh.png") + .unwrap(), grass: texture_creator.load_texture("data/png/grass.png").unwrap(), } }