mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-30 03:42:17 +00:00
bumper animation fix
This commit is contained in:
parent
ebfff3847e
commit
40f075e93b
4 changed files with 38 additions and 30 deletions
BIN
marblegame.hl
BIN
marblegame.hl
Binary file not shown.
36
src/shapes/AbstractBumper.hx
Normal file
36
src/shapes/AbstractBumper.hx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package shapes;
|
||||
|
||||
import collision.CollisionInfo;
|
||||
import src.DtsObject;
|
||||
import src.TimeState;
|
||||
import src.Util;
|
||||
|
||||
class AbstractBumper extends DtsObject {
|
||||
var lastContactTime = Math.NEGATIVE_INFINITY;
|
||||
|
||||
override function update(timeState:src.TimeState) {
|
||||
// Override the keyframe
|
||||
var currentCompletion = getCurrentCompletion(timeState);
|
||||
this.sequenceKeyframeOverride.set(this.dts.sequences[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(time:TimeState, ?contact:CollisionInfo) {
|
||||
super.onMarbleContact(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);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,39 +5,11 @@ import src.DtsObject;
|
|||
import src.TimeState;
|
||||
import src.Util;
|
||||
|
||||
class RoundBumper extends DtsObject {
|
||||
var lastContactTime = Math.NEGATIVE_INFINITY;
|
||||
|
||||
class RoundBumper extends AbstractBumper {
|
||||
public function new() {
|
||||
super();
|
||||
dtsPath = "data/shapes/bumpers/pball_round.dts";
|
||||
isCollideable = true;
|
||||
identifier = "RoundBumper";
|
||||
}
|
||||
|
||||
override function update(timeState:src.TimeState) {
|
||||
// Override the keyframe
|
||||
var currentCompletion = getCurrentCompletion(timeState);
|
||||
this.sequenceKeyframeOverride.set(this.dts.sequences[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(time:TimeState, ?contact:CollisionInfo) {
|
||||
super.onMarbleContact(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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package shapes;
|
|||
|
||||
import src.DtsObject;
|
||||
|
||||
class TriangleBumper extends DtsObject {
|
||||
class TriangleBumper extends AbstractBumper {
|
||||
public function new() {
|
||||
super();
|
||||
dtsPath = "data/shapes/bumpers/pball_tri.dts";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue