-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New world module: Verlet integration - With this it's possible to lin…
…k easily 2 objects without any physic library. New world module: Octree car - Simple car physics based on spheres. Breaking Change! Unit controller was renamed to player controller. It was needed since from now it can control anything. Breaking Change! world.onUpdate now is available as world.on.update. Breaking Change! Unit config is not an initial config anymore, from now it's part of the world config. Possible to listen world.on.dispose. Octree car related boilerplates were added. Octree module can handle spheres by default. Possible to create units without animations. Missing dispose methods were added into: region module, collectibles module. Pause related time fixes. Dependency updates.
- Loading branch information
Showing
15 changed files
with
857 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/js/newkrok/three-game/boilerplates/car-boilerplates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as THREE from "three"; | ||
|
||
export const basicCar = { | ||
body: { | ||
model: {}, | ||
width: 1.6, | ||
height: 1.5, | ||
length: 2.72, | ||
offset: new THREE.Vector3(), | ||
}, | ||
wheel: { | ||
radius: 0.4, | ||
mass: 50, | ||
}, | ||
speedReductionByCollision: 0.85, | ||
maxSpeed: 60, | ||
maxReverseSpeed: 20, | ||
accelerationForward: 0.07, | ||
accelerationBackward: 0.04, | ||
breakRatio: 0.99, | ||
damping: 0.998, | ||
friction: 0.999, | ||
minAcceleration: 1, | ||
steeringResetSpeed: 3, | ||
maxSteeringSpeed: 5, | ||
maxWheelAngle: Math.PI / 3, | ||
frontWheelSpeedMultiplier: 1, | ||
rearWheelSpeedMultiplier: 0.75, | ||
}; |
167 changes: 167 additions & 0 deletions
167
src/js/newkrok/three-game/boilerplates/player-controller-boilerplates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { ButtonKey } from "@newkrok/three-game/src/js/newkrok/three-game/control/gamepad.js"; | ||
import { Key } from "@newkrok/three-game/src/js/newkrok/three-game/control/keyboard-manager.js"; | ||
|
||
export const PlayerActionId = { | ||
PAUSE: "PAUSE", | ||
FORWARD: "FORWARD", | ||
BACKWARD: "BACKWARD", | ||
LEFT: "LEFT", | ||
RIGHT: "RIGHT", | ||
JUMP: "JUMP", | ||
SPRINT: "SPRINT", | ||
TOOL_ACTION: "TOOL_ACTION", | ||
CHOOSE_NEXT_TOOL: "CHOOSE_NEXT_TOOL", | ||
CHOOSE_PREV_TOOL: "CHOOSE_PREV_TOOL", | ||
...Array.from({ length: 10 }).reduce( | ||
(prev, _, index) => ({ | ||
...prev, | ||
[`CHOOSE_TOOL_${index}`]: `CHOOSE_TOOL_${index}`, | ||
}), | ||
{} | ||
), | ||
}; | ||
|
||
export const unitControllerConfig = { | ||
actionConfig: [ | ||
{ | ||
actionId: PlayerActionId.PAUSE, | ||
enableDuringPause: true, | ||
keys: [Key.P], | ||
gamepadButtons: [ButtonKey.Options], | ||
}, | ||
{ | ||
actionId: PlayerActionId.FORWARD, | ||
listenForDeactivation: true, | ||
keys: [Key.W, Key.ARROW_UP], | ||
gamepadButtons: [ButtonKey.Up], | ||
axis: ButtonKey.LeftAxisY, | ||
axisValidator: (v) => v < -0.1, | ||
axisValueModifier: (v) => v * -1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.BACKWARD, | ||
listenForDeactivation: true, | ||
keys: [Key.S, Key.ARROW_DOWN], | ||
gamepadButtons: [ButtonKey.Down], | ||
axis: ButtonKey.LeftAxisY, | ||
axisValidator: (v) => v > 0.1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.LEFT, | ||
listenForDeactivation: true, | ||
keys: [Key.A, Key.ARROW_LEFT], | ||
gamepadButtons: [ButtonKey.Left], | ||
axis: ButtonKey.LeftAxisX, | ||
axisValidator: (v) => v < -0.1, | ||
axisValueModifier: (v) => v * -1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.RIGHT, | ||
listenForDeactivation: true, | ||
keys: [Key.D, Key.ARROW_RIGHT], | ||
gamepadButtons: [ButtonKey.Right], | ||
axis: ButtonKey.LeftAxisX, | ||
axisValidator: (v) => v > 0.1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.JUMP, | ||
keys: [Key.SPACE], | ||
gamepadButtons: [ButtonKey.ActionBottom], | ||
}, | ||
], | ||
|
||
handlers: [ | ||
{ | ||
actionId: PlayerActionId.PAUSE, | ||
callback: ({ world }) => { | ||
if (world.cycleData.isPaused) world.resume(); | ||
else world.pause(); | ||
}, | ||
}, | ||
{ | ||
actionId: PlayerActionId.JUMP, | ||
callback: ({ target }) => { | ||
if (target.onGround) target.jump(); | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export const carControllerConfig = { | ||
actionConfig: [ | ||
{ | ||
actionId: PlayerActionId.PAUSE, | ||
enableDuringPause: true, | ||
keys: [Key.P], | ||
gamepadButtons: [ButtonKey.Options], | ||
}, | ||
{ | ||
actionId: PlayerActionId.FORWARD, | ||
listenForDeactivation: true, | ||
keys: [Key.W, Key.ARROW_UP], | ||
gamepadButtons: [ButtonKey.Up], | ||
axis: ButtonKey.LeftAxisY, | ||
axisValidator: (v) => v < -0.1, | ||
axisValueModifier: (v) => v * -1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.BACKWARD, | ||
listenForDeactivation: true, | ||
keys: [Key.S, Key.ARROW_DOWN], | ||
gamepadButtons: [ButtonKey.Down], | ||
axis: ButtonKey.LeftAxisY, | ||
axisValidator: (v) => v > 0.1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.LEFT, | ||
listenForDeactivation: true, | ||
keys: [Key.A, Key.ARROW_LEFT], | ||
gamepadButtons: [ButtonKey.Left], | ||
axis: ButtonKey.LeftAxisX, | ||
axisValidator: (v) => v < -0.1, | ||
axisValueModifier: (v) => v * -1, | ||
}, | ||
{ | ||
actionId: PlayerActionId.RIGHT, | ||
listenForDeactivation: true, | ||
keys: [Key.D, Key.ARROW_RIGHT], | ||
gamepadButtons: [ButtonKey.Right], | ||
axis: ButtonKey.LeftAxisX, | ||
axisValidator: (v) => v > 0.1, | ||
}, | ||
], | ||
|
||
handlers: [ | ||
{ | ||
actionId: PlayerActionId.PAUSE, | ||
callback: ({ world }) => { | ||
if (world.cycleData.isPaused) world.resume(); | ||
else world.pause(); | ||
}, | ||
}, | ||
{ | ||
actionId: PlayerActionId.FORWARD, | ||
callback: ({ target }) => { | ||
target.accelerate(); | ||
}, | ||
}, | ||
{ | ||
actionId: PlayerActionId.BACKWARD, | ||
callback: ({ target }) => { | ||
target.reverse(); | ||
}, | ||
}, | ||
{ | ||
actionId: PlayerActionId.LEFT, | ||
callback: ({ target }) => { | ||
target.rotateLeft(); | ||
}, | ||
}, | ||
{ | ||
actionId: PlayerActionId.RIGHT, | ||
callback: ({ target }) => { | ||
target.rotateRight(); | ||
}, | ||
}, | ||
], | ||
}; |
88 changes: 0 additions & 88 deletions
88
src/js/newkrok/three-game/boilerplates/unit-controller-boilerplates.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.