Do a rustfmt

This commit is contained in:
Sijmen 2018-07-29 22:59:33 +02:00
parent 46c288be8c
commit f4a352d5cd
2 changed files with 53 additions and 28 deletions

View File

@ -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<Tile>],
game_state: &mut GameState) {
fn render(
canvas: &mut WindowCanvas,
texture_manager: &TextureManager,
map: &[Vec<Tile>],
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();
}
}

View File

@ -15,11 +15,19 @@ pub struct TextureManager<'a> {
impl<'a> TextureManager<'a> {
pub fn new(texture_creator: &'a TextureCreator<WindowContext>) -> 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(),
}
}