Skip to content

Commit

Permalink
update map collision based on io jump events.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Feb 17, 2024
1 parent 01fd7be commit 46334c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion base/interactable_objects/InteractableObjects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {SpriteBase} from "../SpriteBase";
import {IntegerPairKey, TileEvent} from "../tile_events/TileEvent";
import {IntegerPairKey, TileEvent, event_types} from "../tile_events/TileEvent";
import * as numbers from "../magic_numbers";
import * as _ from "lodash";
import {
Expand Down Expand Up @@ -947,6 +947,16 @@ export class InteractableObjects {
if (this.sprite?.body) {
this.sprite.body.data.shapes.forEach(shape => (shape.sensor = !enable));
this._shapes_collision_active = enable;
if (this.allow_jumping_over_it) {
this.get_events().forEach(event => {
if (
event.type === event_types.JUMP &&
event.is_active_at_collision_layer(this.base_collision_layer)
) {
this.data.map.set_collision_in_tile(event.x, event.y, enable, this.base_collision_layer);
}
});
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions base/tile_events/TileEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ export abstract class TileEvent {
collision_layers_indexes.forEach(this.activation_collision_layers.add, this.activation_collision_layers);
}

/**
* Checks if this event is active in a given collision layer.
* @param collision_layer the collision layer index to be checked.
*/
is_active_at_collision_layer(collision_layer: number) {
return this.activation_collision_layers.has(collision_layer);
}

/**
* This method will be called on map update. If necessary, overrides it.
*/
Expand Down

0 comments on commit 46334c1

Please sign in to comment.