mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +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.TimeState;
|
||||||
import src.Util;
|
import src.Util;
|
||||||
|
|
||||||
class RoundBumper extends DtsObject {
|
class RoundBumper extends AbstractBumper {
|
||||||
var lastContactTime = Math.NEGATIVE_INFINITY;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
dtsPath = "data/shapes/bumpers/pball_round.dts";
|
dtsPath = "data/shapes/bumpers/pball_round.dts";
|
||||||
isCollideable = true;
|
isCollideable = true;
|
||||||
identifier = "RoundBumper";
|
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;
|
import src.DtsObject;
|
||||||
|
|
||||||
class TriangleBumper extends DtsObject {
|
class TriangleBumper extends AbstractBumper {
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
dtsPath = "data/shapes/bumpers/pball_tri.dts";
|
dtsPath = "data/shapes/bumpers/pball_tri.dts";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue