Moving platform code
It adds the platform’s speed to the player’s position (x coordinate) and its own position (x coordinate).
This is old code! And it is combined with “pixel perfect” functions for its collisions.
this.player_touch = false;
this.direction = 0;
this.SPEED = 5;
project.TILES.push(eval(this._identifier));
this.update_hitbox = function () {
this.hitbox = project.get_tile_hitbox(eval(this._identifier));
};
this.update_hitbox();
onEvent('update', function () {
if (this.x > 245 && this.direction === 0) {
if (this.player_touch) {
player.x -= this.SPEED * player.delta_time;
}
this.x -= this.SPEED * player.delta_time;
this.update_hitbox();
}
else if (this.x < 465 && this.direction === 1) {
if (this.player_touch) {
player.x += this.SPEED * player.delta_time;
}
this.x += this.SPEED * player.delta_time;
this.update_hitbox();
}
else {
this.direction = ((this.direction === 0) ? 1 : 0);
}
});