game_toolkit_platformer/sim/surface.rs
1//! [`Surface`]: what kind of ground or wall the character touches: ice, a conveyor belt, a
2//! wall too smooth to climb, a bouncy pad. A [`Terrain`](super::Terrain) answers it in
3//! [`Terrain::surface`](super::Terrain::surface); by default everything is
4//! [`Surface::DEFAULT`] and the [`Tuning`](super::Tuning) alone sets the feel.
5//!
6//! `docs/surfaces.md` has the recipe.
7
8/// The kind of a surface. Each field's default leaves the tuning's feel as it is.
9#[derive(Clone, Copy, Debug, PartialEq)]
10pub struct Surface {
11 /// Scales running's acceleration, braking and turning on this ground: `1.0` as tuned,
12 /// below for ice (`0.1` slides a long way), above for sticky ground.
13 pub friction: f32,
14 /// Whether the character may grab and climb this wall. Wall slides and wall jumps
15 /// still work on a wall that isn't climbable.
16 pub climbable: bool,
17 /// A conveyor belt: carries what stands on it sideways at this speed, units/s
18 /// (positive right). A jump off it keeps the speed, as off moving ground.
19 pub belt: f32,
20 /// Bounciness: a landing faster than [`Surface::BOUNCE_MIN`] bounces back up at this
21 /// share of its downward speed (`0.0`: none, `1.0`: as fast as it came down).
22 pub bounce: f32,
23}
24
25impl Surface {
26 /// Plain ground: the tuning's feel, climbable, still, not bouncy.
27 pub const DEFAULT: Surface = Surface {
28 friction: 1.0,
29 climbable: true,
30 belt: 0.0,
31 bounce: 0.0,
32 };
33
34 /// The slowest landing (units/s down) a bouncy surface bounces back.
35 pub const BOUNCE_MIN: f32 = 40.0;
36}
37
38impl Default for Surface {
39 fn default() -> Self {
40 Self::DEFAULT
41 }
42}