multiple colors for walls

wip
Fabien Freling 2020-04-06 23:45:40 +02:00
parent eee63a7350
commit 4620f647ad
1 changed files with 7 additions and 4 deletions

View File

@ -35,8 +35,8 @@ impl Player {
let dy = other.y - self.pos.y;
let x = dx * rad.cos();
let y = dy * rad.sin();
let distance = x + y;
println!("angle: {}, dx: {}, dy: {}, x; {}, y: {}", self.angle, dx, dy, x, y);
let distance = (x + y).abs();
// println!("angle: {}, dx: {}, dy: {}, x; {}, y: {}", self.angle, dx, dy, x, y);
assert!(distance.is_sign_positive());
distance
}
@ -205,8 +205,11 @@ impl Engine {
if tile == Tile::Wall {
let wall_height = (self.h / (distance * 3.0)).min(self.h);
let wall_color = match pos {
p if p.x.fract() == 0.0 => [0.2, 0.2, 0.9, 1.0],
_ => [0.2, 0.9, 0.2, 1.0],
p if (p.x.trunc() + p.y.trunc()) % 4.0 == 0.0 => [0.2, 0.2, 0.9, 1.0],
p if (p.x.trunc() + p.y.trunc()) % 4.0 == 1.0 => [0.4, 0.4, 0.9, 1.0],
p if (p.x.trunc() + p.y.trunc()) % 4.0 == 2.0 => [0.6, 0.6, 0.9, 1.0],
p if (p.x.trunc() + p.y.trunc()) % 4.0 == 3.0 => [0.7, 0.3, 0.9, 1.0],
_ => [1.0, 0.0, 0.0, 1.0],
};
println!("ray: {}, angle: {}, wall at {:?}, distance: {}", n, ray_angle, pos, distance);
rectangle(wall_color,