mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
41 lines
1.2 KiB
Haxe
41 lines
1.2 KiB
Haxe
package shapes;
|
|
|
|
import collision.CollisionInfo;
|
|
import src.DtsObject;
|
|
import src.TimeState;
|
|
import src.Util;
|
|
|
|
class AbstractBumper extends DtsObject {
|
|
var lastContactTime = Math.NEGATIVE_INFINITY;
|
|
|
|
public function new() {
|
|
super();
|
|
this.enableCollideCallbacks = true;
|
|
}
|
|
|
|
override function update(timeState:src.TimeState) {
|
|
// Override the keyframe
|
|
var currentCompletion = getCurrentCompletion(timeState);
|
|
this.sequenceKeyframeOverride[0] = (currentCompletion * (this.dts.sequences[0].numKeyFrames - 1));
|
|
|
|
super.update(timeState);
|
|
}
|
|
|
|
function getCurrentCompletion(timeState:TimeState) {
|
|
var elapsed = timeState.timeSinceLoad - this.lastContactTime;
|
|
var completion = Util.clamp(elapsed / this.dts.sequences[0].duration, 0, 1);
|
|
return completion;
|
|
}
|
|
|
|
override function onMarbleContact(marble:src.Marble, time:TimeState, ?contact:CollisionInfo) {
|
|
super.onMarbleContact(marble, time, contact);
|
|
if (time.timeSinceLoad - this.lastContactTime <= 0)
|
|
return;
|
|
var currentCompletion = this.getCurrentCompletion(time);
|
|
if (currentCompletion == 0 || currentCompletion == 1) {
|
|
this.lastContactTime = time.timeSinceLoad;
|
|
}
|
|
|
|
// this.level.replay.recordMarbleContact(this);
|
|
}
|
|
}
|