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 heaps
|
||||||
-lib hlsdl
|
-lib hlsdl
|
||||||
-hl native/marblegame.c
|
-hl native/marblegame.c
|
||||||
--main Main
|
--main Main
|
||||||
-debug
|
|
||||||
10
index.html
10
index.html
|
|
@ -14,10 +14,18 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
#pointercontainer {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<canvas id="webgl"></canvas>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="webgl"></canvas>
|
<div id="pointercontainer" tabindex="0"></div>
|
||||||
<script type="text/javascript" src="marblegame.js"></script>
|
<script type="text/javascript" src="marblegame.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
BIN
marblegame.hl
BIN
marblegame.hl
Binary file not shown.
|
|
@ -62,6 +62,7 @@ class CameraController extends Object {
|
||||||
public var theta:Float;
|
public var theta:Float;
|
||||||
|
|
||||||
var lastCamPos:Vector;
|
var lastCamPos:Vector;
|
||||||
|
var lastVertTranslation:Vector;
|
||||||
|
|
||||||
public var oob:Bool = false;
|
public var oob:Bool = false;
|
||||||
public var finish:Bool = false;
|
public var finish:Bool = false;
|
||||||
|
|
@ -83,6 +84,8 @@ class CameraController extends Object {
|
||||||
#if js
|
#if js
|
||||||
var jsCanvas = @:privateAccess Window.getInstance().canvas;
|
var jsCanvas = @:privateAccess Window.getInstance().canvas;
|
||||||
jsCanvas.focus();
|
jsCanvas.focus();
|
||||||
|
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||||
|
pointercontainer.hidden = true;
|
||||||
#end
|
#end
|
||||||
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
||||||
#if hl
|
#if hl
|
||||||
|
|
@ -98,6 +101,8 @@ class CameraController extends Object {
|
||||||
#if js
|
#if js
|
||||||
var jsCanvas = @:privateAccess Window.getInstance().canvas;
|
var jsCanvas = @:privateAccess Window.getInstance().canvas;
|
||||||
@:privateAccess Window.getInstance().lockCallback = null; // Fix cursorlock position shit
|
@:privateAccess Window.getInstance().lockCallback = null; // Fix cursorlock position shit
|
||||||
|
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||||
|
pointercontainer.hidden = false;
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,11 +264,13 @@ class CameraController extends Object {
|
||||||
|
|
||||||
if (oob) {
|
if (oob) {
|
||||||
camera.pos = lastCamPos;
|
camera.pos = lastCamPos;
|
||||||
camera.target = marblePosition.add(cameraVerticalTranslation);
|
camera.target = marblePosition.add(lastVertTranslation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oob)
|
if (!oob) {
|
||||||
lastCamPos = camera.pos;
|
lastCamPos = camera.pos;
|
||||||
|
lastVertTranslation = cameraVerticalTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
this.setPosition(camera.pos.x, camera.pos.y, camera.pos.z);
|
this.setPosition(camera.pos.x, camera.pos.y, camera.pos.z);
|
||||||
// camera.target = null;
|
// camera.target = null;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import h3d.Vector;
|
||||||
import h3d.mat.Material;
|
import h3d.mat.Material;
|
||||||
import h3d.prim.Sphere;
|
import h3d.prim.Sphere;
|
||||||
import h3d.scene.Object;
|
import h3d.scene.Object;
|
||||||
|
import src.MarbleGame;
|
||||||
import src.CameraController;
|
import src.CameraController;
|
||||||
|
|
||||||
class Move {
|
class Move {
|
||||||
|
|
@ -916,7 +917,7 @@ class Marble extends GameObject {
|
||||||
this.collider.setTransform(tform);
|
this.collider.setTransform(tform);
|
||||||
this.collider.velocity = this.velocity;
|
this.collider.velocity = this.velocity;
|
||||||
|
|
||||||
if (this.heldPowerup != null && m.powerup) {
|
if (this.heldPowerup != null && m.powerup && !this.level.outOfBounds) {
|
||||||
var pTime = timeState.clone();
|
var pTime = timeState.clone();
|
||||||
pTime.dt = timeStep;
|
pTime.dt = timeStep;
|
||||||
pTime.currentAttemptTime = piTime;
|
pTime.currentAttemptTime = piTime;
|
||||||
|
|
@ -944,7 +945,7 @@ class Marble extends GameObject {
|
||||||
public function update(timeState:TimeState, collisionWorld:CollisionWorld, pathedInteriors:Array<PathedInterior>) {
|
public function update(timeState:TimeState, collisionWorld:CollisionWorld, pathedInteriors:Array<PathedInterior>) {
|
||||||
var move = new Move();
|
var move = new Move();
|
||||||
move.d = new Vector();
|
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)) {
|
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||||
move.d.x -= 1;
|
move.d.x -= 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,6 @@ class MarbleGame {
|
||||||
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
||||||
if (!paused && world != null) {
|
if (!paused && world != null) {
|
||||||
if (world.finishTime == null && world._ready) {
|
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) {
|
if (js.Browser.document.pointerLockElement != @:privateAccess Window.getInstance().canvas) {
|
||||||
paused = true;
|
paused = true;
|
||||||
handlePauseGame();
|
handlePauseGame();
|
||||||
|
|
@ -58,6 +56,31 @@ class MarbleGame {
|
||||||
canvasElement.style.width = "100%";
|
canvasElement.style.width = "100%";
|
||||||
canvasElement.style.height = "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
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -874,13 +874,12 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function callCollisionHandlers(marble:Marble, timeState:TimeState) {
|
public function callCollisionHandlers(marble:Marble, timeState:TimeState) {
|
||||||
var gjkCapsule = new collision.gjk.Capsule();
|
var gjkSphere = new collision.gjk.Sphere();
|
||||||
gjkCapsule.p1 = marble.getAbsPos().getPosition();
|
gjkSphere.position = marble.getAbsPos().getPosition();
|
||||||
gjkCapsule.p2 = marble.prevPos;
|
gjkSphere.radius = marble._radius;
|
||||||
gjkCapsule.radius = marble._radius;
|
|
||||||
|
|
||||||
var spherebounds = new Bounds();
|
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);
|
// 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 = this.collisionWorld.radiusSearch(marble.getAbsPos().getPosition(), marble._radius);
|
||||||
var contacts = marble.contactEntities;
|
var contacts = marble.contactEntities;
|
||||||
|
|
@ -940,7 +939,7 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
if (this.finishTime == null) {
|
if (this.finishTime == null) {
|
||||||
if (spherebounds.collide(this.endPad.finishBounds)) {
|
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) {
|
if (!endPad.inFinish) {
|
||||||
touchFinish();
|
touchFinish();
|
||||||
endPad.inFinish = true;
|
endPad.inFinish = true;
|
||||||
|
|
@ -976,11 +975,17 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
function showFinishScreen() {
|
function showFinishScreen() {
|
||||||
var egg:EndGameGui = null;
|
var egg:EndGameGui = null;
|
||||||
|
#if js
|
||||||
|
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||||
|
#end
|
||||||
egg = new EndGameGui((sender) -> {
|
egg = new EndGameGui((sender) -> {
|
||||||
this.dispose();
|
this.dispose();
|
||||||
var pmg = new PlayMissionGui();
|
var pmg = new PlayMissionGui();
|
||||||
PlayMissionGui.currentSelectionStatic = mission.index + 1;
|
PlayMissionGui.currentSelectionStatic = mission.index + 1;
|
||||||
MarbleGame.canvas.setContent(pmg);
|
MarbleGame.canvas.setContent(pmg);
|
||||||
|
#if js
|
||||||
|
pointercontainer.hidden = false;
|
||||||
|
#end
|
||||||
}, (sender) -> {
|
}, (sender) -> {
|
||||||
MarbleGame.canvas.popDialog(egg);
|
MarbleGame.canvas.popDialog(egg);
|
||||||
this.setCursorLock(true);
|
this.setCursorLock(true);
|
||||||
|
|
@ -988,6 +993,9 @@ class MarbleWorld extends Scheduler {
|
||||||
}, mission, finishTime);
|
}, mission, finishTime);
|
||||||
MarbleGame.canvas.pushDialog(egg);
|
MarbleGame.canvas.pushDialog(egg);
|
||||||
this.setCursorLock(false);
|
this.setCursorLock(false);
|
||||||
|
#if js
|
||||||
|
pointercontainer.hidden = true;
|
||||||
|
#end
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
import haxe.io.BytesBuffer;
|
import haxe.io.BytesBuffer;
|
||||||
import haxe.Http;
|
|
||||||
import h2d.Tile;
|
import h2d.Tile;
|
||||||
import hxd.BitmapData;
|
import hxd.BitmapData;
|
||||||
import mis.MisParser;
|
import mis.MisParser;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue