add function for minimap

master
Fabien Freling 2021-11-15 13:58:34 +01:00
parent acd5ad1399
commit 70951c34c6
2 changed files with 15 additions and 8 deletions

View File

@ -173,7 +173,17 @@ impl Engine {
}
}
pub fn render(&mut self, buffer: &mut Vec<u32>) {
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<u32>) {
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<u32>) {}
pub fn load_level(&mut self, level: Level) {
self.level = level;
}

View File

@ -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);