mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
attempt alternative janky container thingy which receives the keyboard/mouse events instead for js target, which also enables the site to be scaled and shit, fix camera while oob, fix powerup particles after oobclick respawn, fix movement keys persistence after unfocus, nuke CCD for finish pad
This commit is contained in:
parent
4a0e506fde
commit
26c9cf49fb
8 changed files with 61 additions and 16 deletions
|
|
@ -2,5 +2,4 @@
|
|||
-lib heaps
|
||||
-lib hlsdl
|
||||
-hl native/marblegame.c
|
||||
--main Main
|
||||
-debug
|
||||
--main Main
|
||||
10
index.html
10
index.html
|
|
@ -14,10 +14,18 @@
|
|||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#pointercontainer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
</style>
|
||||
<canvas id="webgl"></canvas>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="webgl"></canvas>
|
||||
<div id="pointercontainer" tabindex="0"></div>
|
||||
<script type="text/javascript" src="marblegame.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
BIN
marblegame.hl
BIN
marblegame.hl
Binary file not shown.
|
|
@ -62,6 +62,7 @@ class CameraController extends Object {
|
|||
public var theta:Float;
|
||||
|
||||
var lastCamPos:Vector;
|
||||
var lastVertTranslation:Vector;
|
||||
|
||||
public var oob:Bool = false;
|
||||
public var finish:Bool = false;
|
||||
|
|
@ -83,6 +84,8 @@ class CameraController extends Object {
|
|||
#if js
|
||||
var jsCanvas = @:privateAccess Window.getInstance().canvas;
|
||||
jsCanvas.focus();
|
||||
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||
pointercontainer.hidden = true;
|
||||
#end
|
||||
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
||||
#if hl
|
||||
|
|
@ -98,6 +101,8 @@ class CameraController extends Object {
|
|||
#if js
|
||||
var jsCanvas = @:privateAccess Window.getInstance().canvas;
|
||||
@:privateAccess Window.getInstance().lockCallback = null; // Fix cursorlock position shit
|
||||
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||
pointercontainer.hidden = false;
|
||||
#end
|
||||
}
|
||||
|
||||
|
|
@ -259,11 +264,13 @@ class CameraController extends Object {
|
|||
|
||||
if (oob) {
|
||||
camera.pos = lastCamPos;
|
||||
camera.target = marblePosition.add(cameraVerticalTranslation);
|
||||
camera.target = marblePosition.add(lastVertTranslation);
|
||||
}
|
||||
|
||||
if (!oob)
|
||||
if (!oob) {
|
||||
lastCamPos = camera.pos;
|
||||
lastVertTranslation = cameraVerticalTranslation;
|
||||
}
|
||||
|
||||
this.setPosition(camera.pos.x, camera.pos.y, camera.pos.z);
|
||||
// camera.target = null;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import h3d.Vector;
|
|||
import h3d.mat.Material;
|
||||
import h3d.prim.Sphere;
|
||||
import h3d.scene.Object;
|
||||
import src.MarbleGame;
|
||||
import src.CameraController;
|
||||
|
||||
class Move {
|
||||
|
|
@ -916,7 +917,7 @@ class Marble extends GameObject {
|
|||
this.collider.setTransform(tform);
|
||||
this.collider.velocity = this.velocity;
|
||||
|
||||
if (this.heldPowerup != null && m.powerup) {
|
||||
if (this.heldPowerup != null && m.powerup && !this.level.outOfBounds) {
|
||||
var pTime = timeState.clone();
|
||||
pTime.dt = timeStep;
|
||||
pTime.currentAttemptTime = piTime;
|
||||
|
|
@ -944,7 +945,7 @@ class Marble extends GameObject {
|
|||
public function update(timeState:TimeState, collisionWorld:CollisionWorld, pathedInteriors:Array<PathedInterior>) {
|
||||
var move = new Move();
|
||||
move.d = new Vector();
|
||||
if (this.controllable && this.mode != Finish) {
|
||||
if (this.controllable && this.mode != Finish && !MarbleGame.instance.paused) {
|
||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||
move.d.x -= 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ class MarbleGame {
|
|||
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
||||
if (!paused && world != null) {
|
||||
if (world.finishTime == null && world._ready) {
|
||||
trace(js.Browser.document.pointerLockElement);
|
||||
trace(@:privateAccess Window.getInstance().canvas);
|
||||
if (js.Browser.document.pointerLockElement != @:privateAccess Window.getInstance().canvas) {
|
||||
paused = true;
|
||||
handlePauseGame();
|
||||
|
|
@ -58,6 +56,31 @@ class MarbleGame {
|
|||
canvasElement.style.width = "100%";
|
||||
canvasElement.style.height = "100%";
|
||||
});
|
||||
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||
pointercontainer.addEventListener('mousedown', (e:js.html.MouseEvent) -> {
|
||||
var buttonCode = switch (e.button) {
|
||||
case 1: 2;
|
||||
case 2: 1;
|
||||
case x: x;
|
||||
};
|
||||
@:privateAccess Key.keyPressed[buttonCode] = Key.getFrame();
|
||||
});
|
||||
pointercontainer.addEventListener('mouseup', (e:js.html.MouseEvent) -> {
|
||||
var buttonCode = switch (e.button) {
|
||||
case 1: 2;
|
||||
case 2: 1;
|
||||
case x: x;
|
||||
};
|
||||
@:privateAccess Key.keyPressed[buttonCode] = -Key.getFrame();
|
||||
});
|
||||
pointercontainer.addEventListener('keydown', (e:js.html.KeyboardEvent) -> {
|
||||
var buttonCode = (e.keyCode);
|
||||
@:privateAccess Key.keyPressed[buttonCode] = Key.getFrame();
|
||||
});
|
||||
pointercontainer.addEventListener('keyup', (e:js.html.KeyboardEvent) -> {
|
||||
var buttonCode = (e.keyCode);
|
||||
@:privateAccess Key.keyPressed[buttonCode] = -Key.getFrame();
|
||||
});
|
||||
#end
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -874,13 +874,12 @@ class MarbleWorld extends Scheduler {
|
|||
}
|
||||
|
||||
public function callCollisionHandlers(marble:Marble, timeState:TimeState) {
|
||||
var gjkCapsule = new collision.gjk.Capsule();
|
||||
gjkCapsule.p1 = marble.getAbsPos().getPosition();
|
||||
gjkCapsule.p2 = marble.prevPos;
|
||||
gjkCapsule.radius = marble._radius;
|
||||
var gjkSphere = new collision.gjk.Sphere();
|
||||
gjkSphere.position = marble.getAbsPos().getPosition();
|
||||
gjkSphere.radius = marble._radius;
|
||||
|
||||
var spherebounds = new Bounds();
|
||||
spherebounds.addSpherePos(gjkCapsule.p1.x, gjkCapsule.p1.y, gjkCapsule.p1.z, gjkCapsule.radius);
|
||||
spherebounds.addSpherePos(gjkSphere.position.x, gjkSphere.position.y, gjkSphere.position.z, gjkSphere.radius);
|
||||
// spherebounds.addSpherePos(gjkCapsule.p2.x, gjkCapsule.p2.y, gjkCapsule.p2.z, gjkCapsule.radius);
|
||||
// var contacts = this.collisionWorld.radiusSearch(marble.getAbsPos().getPosition(), marble._radius);
|
||||
var contacts = marble.contactEntities;
|
||||
|
|
@ -940,7 +939,7 @@ class MarbleWorld extends Scheduler {
|
|||
|
||||
if (this.finishTime == null) {
|
||||
if (spherebounds.collide(this.endPad.finishBounds)) {
|
||||
if (collision.gjk.GJK.gjk(gjkCapsule, this.endPad.finishCollider) != null) {
|
||||
if (collision.gjk.GJK.gjk(gjkSphere, this.endPad.finishCollider) != null) {
|
||||
if (!endPad.inFinish) {
|
||||
touchFinish();
|
||||
endPad.inFinish = true;
|
||||
|
|
@ -976,11 +975,17 @@ class MarbleWorld extends Scheduler {
|
|||
|
||||
function showFinishScreen() {
|
||||
var egg:EndGameGui = null;
|
||||
#if js
|
||||
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||
#end
|
||||
egg = new EndGameGui((sender) -> {
|
||||
this.dispose();
|
||||
var pmg = new PlayMissionGui();
|
||||
PlayMissionGui.currentSelectionStatic = mission.index + 1;
|
||||
MarbleGame.canvas.setContent(pmg);
|
||||
#if js
|
||||
pointercontainer.hidden = false;
|
||||
#end
|
||||
}, (sender) -> {
|
||||
MarbleGame.canvas.popDialog(egg);
|
||||
this.setCursorLock(true);
|
||||
|
|
@ -988,6 +993,9 @@ class MarbleWorld extends Scheduler {
|
|||
}, mission, finishTime);
|
||||
MarbleGame.canvas.pushDialog(egg);
|
||||
this.setCursorLock(false);
|
||||
#if js
|
||||
pointercontainer.hidden = true;
|
||||
#end
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package src;
|
||||
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.Http;
|
||||
import h2d.Tile;
|
||||
import hxd.BitmapData;
|
||||
import mis.MisParser;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue