server side only quick respawn

This commit is contained in:
RandomityGuy 2024-06-26 20:27:58 +05:30
parent f990ed02a7
commit 39fbcc2ec4
8 changed files with 64 additions and 16 deletions

View file

@ -83,6 +83,15 @@ class Gamepad {
return false; return false;
} }
public static function releaseKey(buttons:Array<String>) {
for (button in buttons) {
var buttonId = getId(button);
if (buttonId < 0 || buttonId > gamepad.buttons.length)
continue;
@:privateAccess gamepad.buttons[buttonId] = false;
}
}
public static function isPressed(buttons:Array<String>) { public static function isPressed(buttons:Array<String>) {
if (!hasPad) if (!hasPad)
return false; return false;

View file

@ -330,6 +330,7 @@ class Marble extends GameObject {
var serverTicks:Int; var serverTicks:Int;
var recvServerTick:Int; var recvServerTick:Int;
var serverUsePowerup:Bool; var serverUsePowerup:Bool;
var lastRespawnTick:Int = -100000;
var trapdoorContacts:Map<Int, Int> = []; var trapdoorContacts:Map<Int, Int> = [];
public function new() { public function new() {
@ -1049,6 +1050,7 @@ class Marble extends GameObject {
a.set(a.x + aFriction.x, a.y + aFriction.y, a.z + aFriction.z); a.set(a.x + aFriction.x, a.y + aFriction.y, a.z + aFriction.z);
lastContactNormal = bestContact.normal; lastContactNormal = bestContact.normal;
lastContactPosition = this.getAbsPos().getPosition();
} }
a.set(a.x + aControl.x, a.y + aControl.y, a.z + aControl.z); a.set(a.x + aControl.x, a.y + aControl.y, a.z + aControl.z);
if (this.mode == Finish) { if (this.mode == Finish) {
@ -1863,6 +1865,13 @@ class Marble extends GameObject {
for (interior in pathedInteriors) { for (interior in pathedInteriors) {
interior.popTickState(); interior.popTickState();
} }
if (m.respawn) {
if (timeState.ticks - lastRespawnTick > (25000 >> 5)) {
this.level.restart(cast this);
lastRespawnTick = timeState.ticks;
}
}
} }
} }
@ -2157,6 +2166,12 @@ class Marble extends GameObject {
|| Gamepad.isDown(Settings.gamepadSettings.blast)) || Gamepad.isDown(Settings.gamepadSettings.blast))
move.blast = true; move.blast = true;
if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) {
move.respawn = true;
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0;
Gamepad.releaseKey(Settings.gamepadSettings.respawn);
}
if (MarbleGame.instance.touchInput.movementInput.pressed) { if (MarbleGame.instance.touchInput.movementInput.pressed) {
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x; move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y; move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
@ -2553,6 +2568,7 @@ class Marble extends GameObject {
this.contactEntities = []; this.contactEntities = [];
this.cloak = false; this.cloak = false;
this._firstTick = true; this._firstTick = true;
this.lastRespawnTick = -100000;
if (this.teleporting) { if (this.teleporting) {
var ourDts:DtsObject = cast this.children[0]; var ourDts:DtsObject = cast this.children[0];
ourDts.setOpacity(1); ourDts.setOpacity(1);

View file

@ -1803,6 +1803,7 @@ class MarbleWorld extends Scheduler {
ProfilerUI.measure("updateTimer"); ProfilerUI.measure("updateTimer");
this.updateTimer(dt); this.updateTimer(dt);
if (!this.isMultiplayer) {
if ((Key.isPressed(Settings.controlsSettings.respawn) || Gamepad.isPressed(Settings.gamepadSettings.respawn)) if ((Key.isPressed(Settings.controlsSettings.respawn) || Gamepad.isPressed(Settings.gamepadSettings.respawn))
&& this.finishTime == null) { && this.finishTime == null) {
performRestart(); performRestart();
@ -1820,6 +1821,7 @@ class MarbleWorld extends Scheduler {
return; return;
} }
} }
}
this.tickSchedule(timeState.currentAttemptTime); this.tickSchedule(timeState.currentAttemptTime);

View file

@ -8,6 +8,7 @@ import hxd.res.BitmapFont;
import h3d.Vector; import h3d.Vector;
import src.ResourceLoader; import src.ResourceLoader;
import src.Settings; import src.Settings;
import hxd.Key;
class MPExitGameDlg extends GuiControl { class MPExitGameDlg extends GuiControl {
public function new(resumeFunc:() -> Void, exitFunc:() -> Void) { public function new(resumeFunc:() -> Void, exitFunc:() -> Void) {
@ -93,6 +94,9 @@ class MPExitGameDlg extends GuiControl {
quickspawnBtn.position = new Vector(224, 132); quickspawnBtn.position = new Vector(224, 132);
quickspawnBtn.extent = new Vector(104, 45); quickspawnBtn.extent = new Vector(104, 45);
quickspawnBtn.vertSizing = Top; quickspawnBtn.vertSizing = Top;
quickspawnBtn.pressedAction = (e) -> {
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = Key.getFrame() - 1; // jank
}
dialogImg.addChild(quickspawnBtn); dialogImg.addChild(quickspawnBtn);
var completeRestart = new GuiButton(loadButtonImagesExt("data/ui/mp/exit/complete")); var completeRestart = new GuiButton(loadButtonImagesExt("data/ui/mp/exit/complete"));

View file

@ -148,6 +148,7 @@ class MPPlayMissionGui extends GuiImage {
leaveBtn.position = new Vector(59, 514); leaveBtn.position = new Vector(59, 514);
leaveBtn.extent = new Vector(93, 44); leaveBtn.extent = new Vector(93, 44);
leaveBtn.pressedAction = (e) -> { leaveBtn.pressedAction = (e) -> {
Net.disconnect();
MarbleGame.canvas.setContent(new JoinServerGui()); MarbleGame.canvas.setContent(new JoinServerGui());
} }
window.addChild(leaveBtn); window.addChild(leaveBtn);

View file

@ -7,6 +7,7 @@ class Move {
public var jump:Bool; public var jump:Bool;
public var powerup:Bool; public var powerup:Bool;
public var blast:Bool; public var blast:Bool;
public var respawn:Bool;
public function new() {} public function new() {}
} }

View file

@ -105,6 +105,12 @@ class MoveManager {
|| Gamepad.isDown(Settings.gamepadSettings.blast)) || Gamepad.isDown(Settings.gamepadSettings.blast))
move.blast = true; move.blast = true;
if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) {
move.respawn = true;
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0;
Gamepad.releaseKey(Settings.gamepadSettings.respawn);
}
if (MarbleGame.instance.touchInput.movementInput.pressed) { if (MarbleGame.instance.touchInput.movementInput.pressed) {
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x; move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y; move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
@ -159,6 +165,7 @@ class MoveManager {
b.writeFlag(m.move.jump); b.writeFlag(m.move.jump);
b.writeFlag(m.move.powerup); b.writeFlag(m.move.powerup);
b.writeFlag(m.move.blast); b.writeFlag(m.move.blast);
b.writeFlag(m.move.respawn);
b.writeFloat(m.motionDir.x); b.writeFloat(m.motionDir.x);
b.writeFloat(m.motionDir.y); b.writeFloat(m.motionDir.y);
b.writeFloat(m.motionDir.z); b.writeFloat(m.motionDir.z);
@ -174,6 +181,7 @@ class MoveManager {
move.jump = b.readFlag(); move.jump = b.readFlag();
move.powerup = b.readFlag(); move.powerup = b.readFlag();
move.blast = b.readFlag(); move.blast = b.readFlag();
move.respawn = b.readFlag();
var motionDir = new Vector(); var motionDir = new Vector();
motionDir.x = b.readFloat(); motionDir.x = b.readFloat();
motionDir.y = b.readFloat(); motionDir.y = b.readFloat();

View file

@ -3,6 +3,8 @@ package touch;
import src.MarbleGame; import src.MarbleGame;
import h3d.Vector; import h3d.Vector;
import src.ResourceLoader; import src.ResourceLoader;
import src.Settings;
import hxd.Key;
class RestartButton extends TouchButton { class RestartButton extends TouchButton {
public function new() { public function new() {
@ -11,8 +13,13 @@ class RestartButton extends TouchButton {
this.guiElement.horizSizing = Right; this.guiElement.horizSizing = Right;
this.guiElement.vertSizing = Bottom; this.guiElement.vertSizing = Bottom;
this.onClick = () -> { this.onClick = () -> {
if (MarbleGame.instance.world.finishTime == null && !MarbleGame.instance.paused) if (MarbleGame.instance.world.finishTime == null && !MarbleGame.instance.paused) {
if (MarbleGame.instance.world.isMultiplayer) {
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = Key.getFrame() - 1; // jank
} else {
MarbleGame.instance.world.performRestart(); MarbleGame.instance.world.performRestart();
} }
} }
} }
}
}