Entrance of a level

This commit is contained in:
Thomas Forgione 2018-10-06 21:28:26 +02:00
parent 5c54974159
commit 93d1678955
4 changed files with 27 additions and 2 deletions

View File

@ -191,6 +191,10 @@ impl Updatable for Character {
self.speed.x *= physics::GROUND_FRICTION.x;
self.speed += accel * duration + force * 64.0;
if self.speed.y > physics::MAXIMUM_VERTICAL_SPEED {
self.speed.y = physics::MAXIMUM_VERTICAL_SPEED;
}
// Compute position
self.position += self.speed * duration;

View File

@ -274,6 +274,9 @@ impl Drawable for PositionedTile {
/// The map represents the tiles contained in a level.
pub struct Map {
/// The entrace point of the character in the map.
entrance: (usize, usize),
/// The tiles contained in the level.
tiles: Matrix<(CollisionTile, GraphicTile)>,
@ -359,10 +362,21 @@ impl Map {
}
Map {
entrance: Map::find_entrance(&matrix),
tiles: matrix,
}
}
/// Finds a possible entrance.
pub fn find_entrance(tiles: &Matrix<(CollisionTile, GraphicTile)>) -> (usize, usize) {
(tiles.rows() - 5, 1)
}
/// Returns the entrance of the map.
pub fn entrance(&self) -> (usize, usize) {
self.entrance
}
/// Returns an iterator to the positioned tiles.
pub fn at(&self, row: usize, col: usize) -> PositionedTile {
PositionedTile {

View File

@ -1,10 +1,13 @@
use sfml::system::Vector2;
/// The gravity force.
pub const G: Vector2<f32> = Vector2 { x: 0.0, y: 50.0 * 32.0 };
pub const G: Vector2<f32> = Vector2 { x: 0.0, y: 25.0 * 32.0 };
/// The friction with the ground.
pub const GROUND_FRICTION: Vector2<f32> = Vector2 { x: 0.5, y: 1.0 };
/// The speed of a jump.
pub const JUMP_SPEED: Vector2<f32> = Vector2 { x: 0.0, y: -600.0 };
pub const JUMP_SPEED: Vector2<f32> = Vector2 { x: 0.0, y: -12.5 * 32.0 };
/// The maximum vertical speed.
pub const MAXIMUM_VERTICAL_SPEED: f32 = 10.0 * 32.0;

View File

@ -30,6 +30,10 @@ impl Scene {
/// Adds a character to the scene.
pub fn add(&mut self, character: Character) {
let mut character = character;
character.position.x = self.map.entrance().1 as f32 * 16.0;
character.position.y = self.map.entrance().0 as f32 * 16.0;
self.characters.push(character);
}