Skip to content

Commit

Permalink
enable_collision_on_previous_pos for io tween
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Mar 10, 2024
1 parent c87a533 commit e14bf3c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion base/game_events/GameEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,8 @@ export class GameEventManager {
info.shadow_follow_io,
info.keep_io_collision_disable,
info.dest_collision_layer,
info.change_collision_layer_on_init
info.change_collision_layer_on_init,
info.enable_collision_on_previous_pos
);
case event_types.EXIT_SAND_MODE:
return new ExitSandModeEvent(
Expand Down
14 changes: 12 additions & 2 deletions base/game_events/IOTweenPositionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export class IOTweenPositionEvent extends GameEvent {
private shadow_follow_io: boolean;
private keep_io_collision_disable: boolean;
private prev_collision_status: boolean;
private prev_collision_layer: number;
private dest_collision_layer: number;
private change_collision_layer_on_init: boolean;
private enable_collision_on_previous_pos: boolean;

constructor(
game,
Expand All @@ -42,7 +44,8 @@ export class IOTweenPositionEvent extends GameEvent {
shadow_follow_io,
keep_io_collision_disable,
dest_collision_layer,
change_collision_layer_on_init
change_collision_layer_on_init,
enable_collision_on_previous_pos
) {
super(game, data, event_types.IO_TWEEN_POSITION, active, key_name, keep_reveal, keep_custom_psynergy);
this.io_label = io_label;
Expand All @@ -59,6 +62,7 @@ export class IOTweenPositionEvent extends GameEvent {
this.keep_io_collision_disable = keep_io_collision_disable ?? false;
this.dest_collision_layer = dest_collision_layer;
this.change_collision_layer_on_init = change_collision_layer_on_init ?? false;
this.enable_collision_on_previous_pos = enable_collision_on_previous_pos ?? false;
this.finish_events = [];
if (finish_events !== undefined) {
finish_events.forEach(event_info => {
Expand Down Expand Up @@ -89,6 +93,7 @@ export class IOTweenPositionEvent extends GameEvent {
tween_pos.y = this.incremental ? interactable_object.y + tween_pos.y : tween_pos.y;
}
this.prev_collision_status = interactable_object.shapes_collision_active;
this.prev_collision_layer = interactable_object.base_collision_layer;
const target = interactable_object.body ?? interactable_object.sprite;
if (this.change_collision_layer_on_init && this.dest_collision_layer !== undefined) {
interactable_object.change_collision_layer(this.dest_collision_layer);
Expand Down Expand Up @@ -131,7 +136,12 @@ export class IOTweenPositionEvent extends GameEvent {
};
interactable_object.shift_events(
dest_tile_pos.x - interactable_object.tile_x_pos,
dest_tile_pos.y - interactable_object.tile_y_pos
dest_tile_pos.y - interactable_object.tile_y_pos,
this.enable_collision_on_previous_pos
? {
prev_collision_layer: this.prev_collision_layer,
}
: undefined
);
interactable_object.set_tile_position({
x: dest_tile_pos.x,
Expand Down
18 changes: 17 additions & 1 deletion base/interactable_objects/InteractableObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,13 @@ export class InteractableObjects {
* @param event_shift_x the x shift amount.
* @param event_shift_y the y shift amount.
*/
shift_events(event_shift_x: number, event_shift_y: number) {
shift_events(
event_shift_x: number,
event_shift_y: number,
manipulate_collision?: {
prev_collision_layer: number;
}
) {
if (event_shift_x === 0 && event_shift_y === 0) {
return;
}
Expand All @@ -1532,6 +1538,16 @@ export class InteractableObjects {
let new_x = old_x + event_shift_x;
let new_y = old_y + event_shift_y;
event.set_position(new_x, new_y, true);
if (manipulate_collision && event.type === event_types.JUMP) {
if (this.rollable || this.pushable) {
this.data.map.set_collision_in_tile(
old_x,
old_y,
true,
manipulate_collision.prev_collision_layer
);
}
}
}
}
}
Expand Down

0 comments on commit e14bf3c

Please sign in to comment.