mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 21:21:41 +00:00
pushbutton
This commit is contained in:
parent
c56d382c3a
commit
7fbf8f26af
3 changed files with 87 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import shapes.PushButton;
|
||||||
#if js
|
#if js
|
||||||
import gui.MainMenuGui;
|
import gui.MainMenuGui;
|
||||||
#else
|
#else
|
||||||
|
|
@ -473,6 +474,7 @@ class MarbleWorld extends Scheduler {
|
||||||
if (full) {
|
if (full) {
|
||||||
var tidx = 0;
|
var tidx = 0;
|
||||||
var lidx = 0;
|
var lidx = 0;
|
||||||
|
var pidx = 0;
|
||||||
for (dtss in this.dtsObjects) {
|
for (dtss in this.dtsObjects) {
|
||||||
if (dtss is Trapdoor) {
|
if (dtss is Trapdoor) {
|
||||||
var trapdoor:Trapdoor = cast dtss;
|
var trapdoor:Trapdoor = cast dtss;
|
||||||
|
|
@ -496,6 +498,15 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
lidx++;
|
lidx++;
|
||||||
}
|
}
|
||||||
|
if (dtss is PushButton) {
|
||||||
|
var pushbutton:PushButton = cast dtss;
|
||||||
|
if (!this.isWatching) {
|
||||||
|
this.replay.recordPushButtonState(pushbutton.lastContactTime - this.timeState.timeSinceLoad);
|
||||||
|
} else {
|
||||||
|
pushbutton.lastContactTime = this.replay.getPushButtonState(pidx) + this.timeState.timeSinceLoad;
|
||||||
|
}
|
||||||
|
pidx++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -763,6 +774,8 @@ class MarbleWorld extends Scheduler {
|
||||||
shape = new Tornado();
|
shape = new Tornado();
|
||||||
else if (dataBlockLowerCase == "trapdoor")
|
else if (dataBlockLowerCase == "trapdoor")
|
||||||
shape = new Trapdoor();
|
shape = new Trapdoor();
|
||||||
|
else if (dataBlockLowerCase == "pushbutton")
|
||||||
|
shape = new PushButton();
|
||||||
else if (dataBlockLowerCase == "oilslick")
|
else if (dataBlockLowerCase == "oilslick")
|
||||||
shape = new Oilslick();
|
shape = new Oilslick();
|
||||||
else if (dataBlockLowerCase == "arrow" || StringTools.startsWith(dataBlockLowerCase, "sign"))
|
else if (dataBlockLowerCase == "arrow" || StringTools.startsWith(dataBlockLowerCase, "sign"))
|
||||||
|
|
@ -880,6 +893,8 @@ class MarbleWorld extends Scheduler {
|
||||||
shape = new Tornado();
|
shape = new Tornado();
|
||||||
else if (dataBlockLowerCase == "trapdoor")
|
else if (dataBlockLowerCase == "trapdoor")
|
||||||
shape = new Trapdoor();
|
shape = new Trapdoor();
|
||||||
|
else if (dataBlockLowerCase == "pushbutton")
|
||||||
|
shape = new PushButton();
|
||||||
else if (dataBlockLowerCase == "oilslick")
|
else if (dataBlockLowerCase == "oilslick")
|
||||||
shape = new Oilslick();
|
shape = new Oilslick();
|
||||||
else if (dataBlockLowerCase == "arrow" || StringTools.startsWith(dataBlockLowerCase, "sign"))
|
else if (dataBlockLowerCase == "arrow" || StringTools.startsWith(dataBlockLowerCase, "sign"))
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,7 @@ class ReplayInitialState {
|
||||||
var trapdoorLastDirections:Array<Int> = [];
|
var trapdoorLastDirections:Array<Int> = [];
|
||||||
var trapdoorLastCompletions:Array<Float> = [];
|
var trapdoorLastCompletions:Array<Float> = [];
|
||||||
var landMineDisappearTimes:Array<Float> = [];
|
var landMineDisappearTimes:Array<Float> = [];
|
||||||
|
var pushButtonContactTimes:Array<Float> = [];
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
|
|
@ -219,6 +220,10 @@ class ReplayInitialState {
|
||||||
for (time in this.landMineDisappearTimes) {
|
for (time in this.landMineDisappearTimes) {
|
||||||
bw.writeFloat(time);
|
bw.writeFloat(time);
|
||||||
}
|
}
|
||||||
|
bw.writeInt16(this.pushButtonContactTimes.length);
|
||||||
|
for (time in this.pushButtonContactTimes) {
|
||||||
|
bw.writeFloat(time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function read(br:BytesReader) {
|
public function read(br:BytesReader) {
|
||||||
|
|
@ -236,6 +241,10 @@ class ReplayInitialState {
|
||||||
for (i in 0...landMineCount) {
|
for (i in 0...landMineCount) {
|
||||||
this.landMineDisappearTimes.push(br.readFloat());
|
this.landMineDisappearTimes.push(br.readFloat());
|
||||||
}
|
}
|
||||||
|
var pushButtonCount = br.readInt16();
|
||||||
|
for (i in 0...pushButtonCount) {
|
||||||
|
this.pushButtonContactTimes.push(br.readFloat());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,7 +261,7 @@ class Replay {
|
||||||
var currentPlaybackFrameIdx:Int;
|
var currentPlaybackFrameIdx:Int;
|
||||||
var currentPlaybackTime:Float;
|
var currentPlaybackTime:Float;
|
||||||
|
|
||||||
var version:Int = 5;
|
var version:Int = 6;
|
||||||
var readFullEntry:FileEntry;
|
var readFullEntry:FileEntry;
|
||||||
|
|
||||||
public function new(mission:String) {
|
public function new(mission:String) {
|
||||||
|
|
@ -328,6 +337,10 @@ class Replay {
|
||||||
initialState.landMineDisappearTimes.push(disappearTime);
|
initialState.landMineDisappearTimes.push(disappearTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function recordPushButtonState(lastContactTime:Float) {
|
||||||
|
initialState.pushButtonContactTimes.push(lastContactTime);
|
||||||
|
}
|
||||||
|
|
||||||
public function getTrapdoorState(idx:Int) {
|
public function getTrapdoorState(idx:Int) {
|
||||||
return {
|
return {
|
||||||
lastContactTime: initialState.trapdoorLastContactTimes[idx],
|
lastContactTime: initialState.trapdoorLastContactTimes[idx],
|
||||||
|
|
@ -340,6 +353,10 @@ class Replay {
|
||||||
return initialState.landMineDisappearTimes[idx];
|
return initialState.landMineDisappearTimes[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPushButtonState(idx:Int) {
|
||||||
|
return initialState.pushButtonContactTimes[idx];
|
||||||
|
}
|
||||||
|
|
||||||
public function clear() {
|
public function clear() {
|
||||||
this.frames = [];
|
this.frames = [];
|
||||||
currentRecordFrame = null;
|
currentRecordFrame = null;
|
||||||
|
|
|
||||||
54
src/shapes/PushButton.hx
Normal file
54
src/shapes/PushButton.hx
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
package shapes;
|
||||||
|
|
||||||
|
import hxd.snd.effect.Spatialization;
|
||||||
|
import src.TimeState;
|
||||||
|
import collision.CollisionInfo;
|
||||||
|
import src.Util;
|
||||||
|
import src.DtsObject;
|
||||||
|
import h3d.Vector;
|
||||||
|
import src.ForceObject;
|
||||||
|
import src.ResourceLoader;
|
||||||
|
import src.AudioManager;
|
||||||
|
import src.MarbleWorld;
|
||||||
|
|
||||||
|
class PushButton extends DtsObject {
|
||||||
|
var lastContactTime = -1e8;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
this.dtsPath = "data/shapes/buttons/pushbutton.dts";
|
||||||
|
this.isCollideable = true;
|
||||||
|
this.isTSStatic = false;
|
||||||
|
this.identifier = "PushButton";
|
||||||
|
this.hasNonVisualSequences = true;
|
||||||
|
this.enableCollideCallbacks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override function update(timeState:TimeState) {
|
||||||
|
var currentCompletion = this.getCurrentCompletion(timeState);
|
||||||
|
|
||||||
|
// Override the keyframe
|
||||||
|
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);
|
||||||
|
if (elapsed > 5)
|
||||||
|
completion = Util.clamp(1 - (elapsed - 5) / 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; // The trapdoor is queued to open, so don't do anything.
|
||||||
|
var currentCompletion = this.getCurrentCompletion(time);
|
||||||
|
|
||||||
|
if (currentCompletion == 0)
|
||||||
|
this.lastContactTime = time.timeSinceLoad;
|
||||||
|
|
||||||
|
// this.level.replay.recordMarbleContact(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue