add function for minimap
This commit is contained in:
		
							parent
							
								
									acd5ad1399
								
							
						
					
					
						commit
						70951c34c6
					
				
					 2 changed files with 15 additions and 8 deletions
				
			
		| 
						 | 
					@ -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;
 | 
					        let half = buffer.len() / 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Ceiling
 | 
					        // Ceiling
 | 
				
			||||||
| 
						 | 
					@ -201,13 +211,7 @@ impl Engine {
 | 
				
			||||||
            let distance = self.player.player_space_distance(pos);
 | 
					            let distance = self.player.player_space_distance(pos);
 | 
				
			||||||
            if tile == Tile::Wall {
 | 
					            if tile == Tile::Wall {
 | 
				
			||||||
                let wall_height = (self.h / (distance * 3.0)).min(self.h);
 | 
					                let wall_height = (self.h / (distance * 3.0)).min(self.h);
 | 
				
			||||||
                let wall_color = match pos {
 | 
					                let wall_color = self.color_for_tile_pos(&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,
 | 
					 | 
				
			||||||
                };
 | 
					 | 
				
			||||||
                println!(
 | 
					                println!(
 | 
				
			||||||
                    "ray: {}, angle: {}, wall at {:?}, distance: {}",
 | 
					                    "ray: {}, angle: {}, wall at {:?}, distance: {}",
 | 
				
			||||||
                    n, ray_angle, pos, distance
 | 
					                    n, ray_angle, pos, distance
 | 
				
			||||||
| 
						 | 
					@ -226,6 +230,8 @@ impl Engine {
 | 
				
			||||||
        //std::process::exit(0);
 | 
					        //std::process::exit(0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn render_minimap(&self, framebuffer: &mut Vec<u32>) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn load_level(&mut self, level: Level) {
 | 
					    pub fn load_level(&mut self, level: Level) {
 | 
				
			||||||
        self.level = level;
 | 
					        self.level = level;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,6 +53,7 @@ fn main() {
 | 
				
			||||||
        // };
 | 
					        // };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        engine.render(&mut buffer);
 | 
					        engine.render(&mut buffer);
 | 
				
			||||||
 | 
					        engine.render_minimap(&mut buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if let Some(args) = event.update_args() {
 | 
					        // if let Some(args) = event.update_args() {
 | 
				
			||||||
        //     engine.update(args.dt);
 | 
					        //     engine.update(args.dt);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue