Small refactor
This commit is contained in:
parent
c433a25a05
commit
5dc1faad63
1 changed files with 14 additions and 6 deletions
20
src/main.rs
20
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<Vec<Tile>>,
|
||||
fn render(canvas: &mut WindowCanvas, texture_manager: &TextureManager, map: &[Vec<Tile>],
|
||||
game_state: &mut GameState) {
|
||||
canvas.clear();
|
||||
|
||||
|
@ -81,11 +89,11 @@ fn generate_map() -> Vec<Vec<Tile>> {
|
|||
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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue