diff --git a/src/engine.rs b/src/engine.rs index 39d662f..44ec4b2 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -173,7 +173,17 @@ impl Engine { } } - pub fn render(&mut self, buffer: &mut Vec) { + fn color_for_tile_pos(&self, pos: &Position) -> u32 { + return match pos { + p if (p.x.trunc() + p.y.trunc()) % 4.0 == 0.0 => 0x3333ee, //[0.2, 0.2, 0.9, 1.0], + p if (p.x.trunc() + p.y.trunc()) % 4.0 == 1.0 => 0x6666ee, //[0.4, 0.4, 0.9, 1.0], + p if (p.x.trunc() + p.y.trunc()) % 4.0 == 2.0 => 0x9999ee, //[0.6, 0.6, 0.9, 1.0], + p if (p.x.trunc() + p.y.trunc()) % 4.0 == 3.0 => 0xaa55ee, //[0.7, 0.3, 0.9, 1.0], + _ => 0xff0000, + }; + } + + pub fn render(&self, buffer: &mut Vec) { let half = buffer.len() / 2; // Ceiling @@ -201,13 +211,7 @@ impl Engine { let distance = self.player.player_space_distance(pos); if tile == Tile::Wall { let wall_height = (self.h / (distance * 3.0)).min(self.h); - let wall_color = match pos { - p if (p.x.trunc() + p.y.trunc()) % 4.0 == 0.0 => 0x3333ee, //[0.2, 0.2, 0.9, 1.0], - p if (p.x.trunc() + p.y.trunc()) % 4.0 == 1.0 => 0x6666ee, //[0.4, 0.4, 0.9, 1.0], - p if (p.x.trunc() + p.y.trunc()) % 4.0 == 2.0 => 0x9999ee, //[0.6, 0.6, 0.9, 1.0], - p if (p.x.trunc() + p.y.trunc()) % 4.0 == 3.0 => 0xaa55ee, //[0.7, 0.3, 0.9, 1.0], - _ => 0xff0000, - }; + let wall_color = self.color_for_tile_pos(&pos); println!( "ray: {}, angle: {}, wall at {:?}, distance: {}", n, ray_angle, pos, distance @@ -226,6 +230,8 @@ impl Engine { //std::process::exit(0); } + pub fn render_minimap(&self, framebuffer: &mut Vec) {} + pub fn load_level(&mut self, level: Level) { self.level = level; } diff --git a/src/main.rs b/src/main.rs index 5f9d2c1..ecaecc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,6 +53,7 @@ fn main() { // }; engine.render(&mut buffer); + engine.render_minimap(&mut buffer); // if let Some(args) = event.update_args() { // engine.update(args.dt);