Working on collisions
This commit is contained in:
		
							parent
							
								
									a4b5a735ae
								
							
						
					
					
						commit
						89295b9283
					
				| @ -4,12 +4,12 @@ | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||||
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | ||||
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | ||||
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | ||||
| 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 | ||||
| 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 | ||||
| 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								assets/test-textures/mario.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/test-textures/mario.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 3.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								assets/test-textures/overworld-raw.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/test-textures/overworld-raw.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 74 KiB | 
							
								
								
									
										
											BIN
										
									
								
								assets/test-textures/overworld.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/test-textures/overworld.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 3.8 KiB | 
| @ -229,4 +229,8 @@ impl Drawable for Character { | ||||
|     fn position(&self) -> Vector2<f32> { | ||||
|         self.position | ||||
|     } | ||||
| 
 | ||||
|     fn origin(&self) -> Vector2<f32> { | ||||
|         Vector2::new(16.0, 16.0) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -234,6 +234,10 @@ impl Drawable for PositionedTile { | ||||
|     fn position(&self) -> Vector2<f32> { | ||||
|         self.position.into() | ||||
|     } | ||||
| 
 | ||||
|     fn origin(&self) -> Vector2<f32> { | ||||
|         Vector2::new(0.0, 0.0) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The map represents the tiles contained in a level.
 | ||||
| @ -363,8 +367,8 @@ impl Map { | ||||
|             // Find tile on x, y
 | ||||
|             if x > 0.0 && y > 0.0 { | ||||
| 
 | ||||
|                 let row = (y / 16.0) as usize + 2; | ||||
|                 let col = (x / 16.0) as usize + 1; | ||||
|                 let row = (y / 16.0) as usize; | ||||
|                 let col = (x / 16.0) as usize; | ||||
| 
 | ||||
|                 if let Some((tile, _)) = self.tiles.get((row, col)) { | ||||
|                     if tile.from_top { | ||||
|  | ||||
| @ -32,6 +32,9 @@ pub trait Drawable { | ||||
| 
 | ||||
|     /// Returns the position on which the drawable should be drawn.
 | ||||
|     fn position(&self) -> Vector2<f32>; | ||||
| 
 | ||||
|     /// Returns the origin of the sprite.
 | ||||
|     fn origin(&self) -> Vector2<f32>; | ||||
| } | ||||
| 
 | ||||
| /// The game window.
 | ||||
| @ -89,6 +92,7 @@ impl Renderer { | ||||
| 
 | ||||
|         use sfml::graphics::Transformable; | ||||
|         sprite.set_position(drawable.position()); | ||||
|         sprite.set_origin(drawable.origin()); | ||||
| 
 | ||||
|         self.window.draw(&sprite); | ||||
|     } | ||||
|  | ||||
| @ -57,7 +57,7 @@ macro_rules! make_textures { | ||||
| } | ||||
| 
 | ||||
| make_textures!( | ||||
|     Mario, mario, make_mario_texture, "../../../assets/textures/mario.png", | ||||
|     Mario, mario, make_mario_texture, "../../../assets/test-textures/mario.png", | ||||
|     Overworld, overworld, make_overworld_texture, "../../../assets/textures/overworld.png", | ||||
| ); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user