MCPcopy
hub / github.com/4ian/GDevelop / OnFloor

Class OnFloor

Extensions/PlatformBehavior/platformerobjectruntimebehavior.ts:1923–2234  ·  view source on GitHub ↗

* The object is on the floor standing or walking. * * Also see ./README.md

Source from the content-addressed store, hash-verified

1921 * Also see {@link ./README.md}
1922 */
1923 class OnFloor implements State {
1924 private _behavior: PlatformerObjectRuntimeBehavior;
1925 private _floorPlatform: gdjs.PlatformRuntimeBehavior | null = null;
1926 private _floorPolygon: gdjs.Polygon | null = null;
1927 private _floorLastX: float = 0;
1928 private _floorLastY: float = 0;
1929 _oldHeight: float = 0;
1930
1931 constructor(behavior: PlatformerObjectRuntimeBehavior) {
1932 this._behavior = behavior;
1933 }
1934
1935 getFloorPlatform() {
1936 return this._floorPlatform;
1937 }
1938
1939 getFloorPolygon() {
1940 return this._floorPolygon;
1941 }
1942
1943 enter(
1944 floorPlatform: gdjs.PlatformRuntimeBehavior,
1945 floorPolygon: gdjs.Polygon
1946 ) {
1947 this._floorPlatform = floorPlatform;
1948 this._floorPolygon = floorPolygon;
1949 this.updateFloorPosition();
1950 this._behavior._canJump = true;
1951 this._behavior._currentFallSpeed = 0;
1952 }
1953
1954 leave() {
1955 this._floorPlatform = null;
1956 this._floorPolygon = null;
1957 }
1958
1959 updateFloorPosition() {
1960 this._floorLastX = this._floorPlatform!.owner.getX();
1961 this._floorLastY = this._floorPlatform!.owner.getY();
1962 }
1963
1964 beforeUpdatingObstacles(timeDelta: float) {
1965 const object = this._behavior.owner;
1966 // Stick the object to the floor if its height has changed.
1967 if (this._oldHeight !== object.getHeight()) {
1968 // TODO This should probably be done after the events because
1969 // the character stays at the wrong place during 1 frame.
1970 const deltaY =
1971 ((this._oldHeight - object.getHeight()) *
1972 (object.getHeight() + object.getDrawableY() - object.getY())) /
1973 object.getHeight();
1974 object.setY(object.getY() + deltaY);
1975 }
1976 // Directly follow the floor movement on the Y axis by moving the character.
1977 // For the X axis, we follow the floor movement using `_requestedDeltaX`
1978 // (see `beforeMovingX`).
1979 // We don't use `_requestedDeltaY` to follow the floor on the Y axis
1980 // to avoid a transition loop with the Falling state.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected