diff --git a/src/main.rs b/src/main.rs index c745442..5868494 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,14 @@ use tile::Tile; struct GameState { camera_x: i32, camera_y: i32, + +impl GameState { + fn new() -> Self { + Self { + camera_x: 0, + camera_y: 0, + } + } } fn world_to_screen(x: i32, y: i32, z: i32) -> (i32, i32) { @@ -54,10 +62,10 @@ fn update(event_pump: &mut EventPump, game_state: &mut GameState) -> bool { }; } - return false; + false } -fn render(canvas: &mut WindowCanvas, texture_manager: &TextureManager, map: &Vec>, +fn render(canvas: &mut WindowCanvas, texture_manager: &TextureManager, map: &[Vec], game_state: &mut GameState) { canvas.clear(); @@ -81,11 +89,11 @@ fn generate_map() -> Vec> { let perlin = PerlinNoise::new(); let mut map = vec![vec![Tile::new(6, 0); 128]; 128]; - for y in 0..128 { - for x in 0..128 { + for (y, row) in map.iter_mut().enumerate() { + for (x, tile) in row.iter_mut().enumerate() { let height = perlin.get2d([x as f64 / 16.0, y as f64 / 16.0]) * 320.0; println!("({}, {}) = {}", x, y, height); - map[y][x].height = height as i32; + tile.height = height as i32; } } @@ -116,7 +124,7 @@ pub fn main() { let texture_manager = TextureManager::new(&texture_creator); let map = generate_map(); - let mut game_state = GameState { camera_x: 0, camera_y: 0 }; + let mut game_state = GameState::new(); canvas.set_draw_color(Color::RGB(48, 48, 48));