| export declare class BaseLevel { | ||
| static readonly STEP = 0.25; | ||
| static readonly COLS: number; | ||
| static readonly ROWS: number; | ||
| static readonly FILL = 0.5; | ||
| static readonly POND = 0.36; | ||
| static readonly ITERATIONS = 4; | ||
| static readonly HEIGHT_MAX: number; | ||
| static zToStep(z?: number): number; | ||
| static reducer(input: number[][], heights: number[][]): number[][]; | ||
| static createMatrix({ min, max, iterations, fill, cols, rows }: { | ||
| min?: number | undefined; | ||
| max?: number | undefined; | ||
| iterations?: number | undefined; | ||
| fill?: number | undefined; | ||
| cols?: number | undefined; | ||
| rows?: number | undefined; | ||
| }): number[][]; | ||
| protected readonly heights: number[][]; | ||
| constructor(); | ||
| getZ(x: number, y: number): number; | ||
| protected forEachHeight(heights: number[][] | undefined, iterator: (col: number, row: number, height: number) => void): void; | ||
| protected getXY(col: number, row: number): { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
| protected createCollider(col: number, row: number, z: number): import("check2d").Box<any>; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.BaseLevel = void 0; | ||
| const rot_js_1 = require("rot-js"); | ||
| const state_1 = require("../state"); | ||
| const detect_mobile_1 = require("../utils/detect-mobile"); | ||
| const query_params_1 = require("../utils/query-params"); | ||
| class BaseLevel { | ||
| static zToStep(z = 0) { | ||
| return Math.round(z / BaseLevel.STEP); | ||
| } | ||
| static reducer(input, heights) { | ||
| return heights.map((column, x) => column.map((value, y) => (input[x]?.[y] || 0) + value), []); | ||
| } | ||
| static createMatrix({ min = 0, max = 1, iterations = BaseLevel.ITERATIONS, fill = BaseLevel.FILL, cols = BaseLevel.COLS, rows = BaseLevel.ROWS }) { | ||
| return Array.from({ length: max }, () => { | ||
| const map = new rot_js_1.Map.Cellular(cols, rows); | ||
| map.randomize(fill); | ||
| for (let i = 0; i < iterations; i++) { | ||
| map.create(); | ||
| } | ||
| return map._map; | ||
| }) | ||
| .reduce(BaseLevel.reducer, []) | ||
| .map((arrays) => arrays.map((value) => Math.max(0, value - min) * BaseLevel.STEP)); | ||
| } | ||
| constructor() { | ||
| this.heights = []; | ||
| const min = Math.round(BaseLevel.HEIGHT_MAX * 2 * BaseLevel.POND); | ||
| const max = BaseLevel.HEIGHT_MAX + min; | ||
| this.heights = BaseLevel.createMatrix({ | ||
| min, | ||
| max | ||
| }); | ||
| } | ||
| getZ(x, y) { | ||
| const posX = Math.floor(x + BaseLevel.COLS / 2); | ||
| const posY = Math.floor(y + BaseLevel.ROWS / 2); | ||
| return this.heights[posX]?.[posY] || 0; | ||
| } | ||
| forEachHeight(heights = this.heights, iterator) { | ||
| heights.forEach((rows, col) => { | ||
| rows.forEach((height, row) => { | ||
| if (height) { | ||
| iterator(col, row, height); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| getXY(col, row) { | ||
| return { | ||
| x: col - BaseLevel.COLS / 2, | ||
| y: row - BaseLevel.ROWS / 2 | ||
| }; | ||
| } | ||
| createCollider(col, row, z) { | ||
| const { x, y } = this.getXY(col, row); | ||
| return state_1.physics.createBox({ x, y }, 1, 1, { | ||
| isStatic: true, | ||
| userData: { step: BaseLevel.zToStep(z) } | ||
| }); | ||
| } | ||
| } | ||
| exports.BaseLevel = BaseLevel; | ||
| BaseLevel.STEP = 0.25; | ||
| BaseLevel.COLS = detect_mobile_1.DeviceDetector.HIGH_END ? 32 : 24; | ||
| BaseLevel.ROWS = detect_mobile_1.DeviceDetector.HIGH_END ? 32 : 24; | ||
| BaseLevel.FILL = 0.5; | ||
| BaseLevel.POND = 0.36; | ||
| BaseLevel.ITERATIONS = 4; | ||
| BaseLevel.HEIGHT_MAX = 'height' in query_params_1.queryParams | ||
| ? Number(query_params_1.queryParams.height) | ||
| : detect_mobile_1.DeviceDetector.HIGH_END | ||
| ? 16 | ||
| : 12; |
| import { BaseBody } from '../model'; | ||
| export declare class AbstractBody { | ||
| export declare abstract class AbstractBody { | ||
| static getZ(body: BaseBody, x?: number, y?: number): number; | ||
| static stepToZ(step?: number): number; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.AbstractBody = void 0; | ||
| const abstract_level_1 = require("../level/abstract-level"); | ||
| const base_level_1 = require("../level/base-level"); | ||
| class AbstractBody { | ||
@@ -10,5 +10,5 @@ static getZ(body, x = body.x, y = body.y) { | ||
| static stepToZ(step = 0) { | ||
| return step * abstract_level_1.AbstractLevel.STEP; | ||
| return step * base_level_1.BaseLevel.STEP; | ||
| } | ||
| } | ||
| exports.AbstractBody = AbstractBody; |
@@ -6,3 +6,3 @@ "use strict"; | ||
| const abstract_body_1 = require("../body/abstract-body"); | ||
| const abstract_level_1 = require("../level/abstract-level"); | ||
| const base_level_1 = require("../level/base-level"); | ||
| const state_1 = require("../state"); | ||
@@ -66,5 +66,5 @@ const detect_mobile_1 = require("../utils/detect-mobile"); | ||
| Camera.FAR = detect_mobile_1.DeviceDetector.HIGH_END ? 32 : 16; | ||
| Camera.MIN_HEIGHT = abstract_level_1.AbstractLevel.HEIGHT_MAX * abstract_level_1.AbstractLevel.STEP; | ||
| Camera.MIN_HEIGHT = base_level_1.BaseLevel.HEIGHT_MAX * base_level_1.BaseLevel.STEP; | ||
| Camera.cameraGoal = new three_1.Vector3(0, Camera.MIN_HEIGHT + Camera.HEIGHT, 0); | ||
| Camera.cameraLookAt = new three_1.Vector3(0, Camera.MIN_HEIGHT, 0); | ||
| Camera.projection = new three_1.Vector3(); |
+1
-1
| export * from './level/index'; | ||
| export * from './level/base-level'; | ||
| export * from './level/box-mesh'; | ||
| export * from './level/model'; | ||
| export * from './level/abstract-level'; | ||
| export * from './utils/view-utils'; | ||
@@ -6,0 +6,0 @@ export * from './utils/debug'; |
+1
-1
@@ -18,5 +18,5 @@ "use strict"; | ||
| __exportStar(require("./level/index"), exports); | ||
| __exportStar(require("./level/base-level"), exports); | ||
| __exportStar(require("./level/box-mesh"), exports); | ||
| __exportStar(require("./level/model"), exports); | ||
| __exportStar(require("./level/abstract-level"), exports); | ||
| __exportStar(require("./utils/view-utils"), exports); | ||
@@ -23,0 +23,0 @@ __exportStar(require("./utils/debug"), exports); |
| import { Texture } from 'three'; | ||
| import { AbstractLevel } from './abstract-level'; | ||
| import { BaseLevel } from './base-level'; | ||
| import { BoxMesh } from './box-mesh'; | ||
| import { LevelCreateProps, LevelObjects, LevelProps } from './model'; | ||
| export declare class Level extends AbstractLevel { | ||
| export declare class Level extends BaseLevel { | ||
| static SIDES: string; | ||
@@ -7,0 +7,0 @@ static FLOOR: string; |
@@ -9,7 +9,7 @@ "use strict"; | ||
| const view_utils_1 = require("../utils/view-utils"); | ||
| const abstract_level_1 = require("./abstract-level"); | ||
| const base_level_1 = require("./base-level"); | ||
| const box_mesh_1 = require("./box-mesh"); | ||
| const billboard_1 = require("../view/billboard"); | ||
| const texture_utils_1 = require("../utils/texture-utils"); | ||
| class Level extends abstract_level_1.AbstractLevel { | ||
| class Level extends base_level_1.BaseLevel { | ||
| static async create(canvas, { sides, floor, ocean, objects = Level.DEFAULT_OBJECTS } = {}) { | ||
@@ -16,0 +16,0 @@ const [sidesTex, floorTex, oceanTex] = await texture_utils_1.TextureUtils.load([ |
@@ -7,3 +7,3 @@ "use strict"; | ||
| const camera_1 = require("../core/camera"); | ||
| const abstract_level_1 = require("../level/abstract-level"); | ||
| const base_level_1 = require("../level/base-level"); | ||
| const state_1 = require("../state"); | ||
@@ -82,3 +82,3 @@ const texture_utils_1 = require("../utils/texture-utils"); | ||
| } | ||
| spawn(level, x = (Math.random() - 0.5) * (abstract_level_1.AbstractLevel.COLS * 0.5), y = (Math.random() - 0.5) * (abstract_level_1.AbstractLevel.ROWS * 0.5)) { | ||
| spawn(level, x = (Math.random() - 0.5) * (base_level_1.BaseLevel.COLS * 0.5), y = (Math.random() - 0.5) * (base_level_1.BaseLevel.ROWS * 0.5)) { | ||
| this.body = this.createBody(x, y, level); | ||
@@ -85,0 +85,0 @@ this.mesh.position.set(x, this.body.z, y); |
+2
-2
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NPC = void 0; | ||
| const abstract_level_1 = require("../level/abstract-level"); | ||
| const base_level_1 = require("../level/base-level"); | ||
| const detect_mobile_1 = require("../utils/detect-mobile"); | ||
@@ -28,3 +28,3 @@ const query_params_1 = require("../utils/query-params"); | ||
| const dy = this.mesh.position.z; | ||
| const radius = (abstract_level_1.AbstractLevel.COLS + abstract_level_1.AbstractLevel.ROWS) / 2; | ||
| const radius = (base_level_1.BaseLevel.COLS + base_level_1.BaseLevel.ROWS) / 2; | ||
| const diff = Math.sqrt(dx * dx + dy * dy) - radius; | ||
@@ -31,0 +31,0 @@ if (diff > 0 && Math.random() < diff / radius) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
| const three_1 = require("three"); | ||
| const abstract_level_1 = require("../level/abstract-level"); | ||
| const base_level_1 = require("../level/base-level"); | ||
| const state_1 = require("../state"); | ||
@@ -11,8 +11,8 @@ const texture_utils_1 = require("../utils/texture-utils"); | ||
| class Ocean { | ||
| constructor(texture, scale = abstract_level_1.AbstractLevel.STEP * 2) { | ||
| constructor(texture, scale = base_level_1.BaseLevel.STEP * 2) { | ||
| this.mesh = new three_1.Group(); | ||
| this.animations = []; | ||
| this.startTime = Date.now(); | ||
| this.cols = abstract_level_1.AbstractLevel.COLS; | ||
| this.rows = abstract_level_1.AbstractLevel.ROWS; | ||
| this.cols = base_level_1.BaseLevel.COLS; | ||
| this.rows = base_level_1.BaseLevel.ROWS; | ||
| texture.wrapS = three_1.RepeatWrapping; | ||
@@ -19,0 +19,0 @@ texture.wrapT = three_1.RepeatWrapping; |
+3
-2
| { | ||
| "name": "make3d", | ||
| "description": "Game FrameWork for JavaScript 3D WebGL Games", | ||
| "version": "1.26.5", | ||
| "version": "1.27.0", | ||
| "main": "./dist/index.js", | ||
@@ -37,3 +37,4 @@ "types": "./dist/index.d.ts", | ||
| "precommit": "yarn lint && yarn build && yarn build:docs && yarn format", | ||
| "amend": "yarn precommit && git commit -a --am --no-edit" | ||
| "amend": "yarn precommit && git commit -a --am --no-edit", | ||
| "update": "npx npm-check-updates -u" | ||
| }, | ||
@@ -40,0 +41,0 @@ "files": [ |
+9
-13
@@ -21,3 +21,3 @@ # make3d | ||
| 👉 https://nenjack.github.io/make3d/demo/ | ||
| 👉 https://nenjack.github.io/make3d/demo/?fps | ||
@@ -56,4 +56,4 @@ --- | ||
| - **AbstractLevel** – base class for custom levels | ||
| - **Level** – main game level abstraction | ||
| - **BaseLevel** – base class for custom levels | ||
| - **Level** – main game level ready to use | ||
@@ -64,10 +64,10 @@ ### rendering | ||
| - **Camera** – camera helper | ||
| - **BoxMesh** – basic mesh helper | ||
| - **BoxMesh** – basic 2.5D mesh | ||
| - **Sprite** – sprite helper | ||
| - **Skybox** – skybox utility | ||
| - **Skybox** – skybox | ||
| - **Ocean** – ocean / water surface | ||
| - **Billboard** – camera-facing objects | ||
| ### entities | ||
| - **Billboard** – camera-facing objects | ||
| - **Player** – player entity | ||
@@ -78,11 +78,11 @@ - **NPC** – non-player character | ||
| - **physics** – shared physics instance (powered by check2d) | ||
| - **DynamicBody** – movable physics body | ||
| - **StaticBody** – static physics body | ||
| - **AbstractBody** – base physics body | ||
| - **physics** – shared physics instance (powered by check2d) | ||
| ### input | ||
| - **mouse** – shared mouse instance | ||
| - **Mouse** – mouse input handler | ||
| - **mouse** – shared mouse instance | ||
@@ -101,5 +101,5 @@ ### state & events | ||
| - **getQueryParams** – get query params from current url | ||
| - **Debug** – debug helpers | ||
| - **DeviceDetector** – device detection | ||
| - **getQueryParams** – get query params from current url | ||
@@ -126,5 +126,1 @@ --- | ||
| MIT | ||
| ``` | ||
| ``` |
| export declare abstract class AbstractLevel { | ||
| static readonly STEP = 0.25; | ||
| static readonly COLS: number; | ||
| static readonly ROWS: number; | ||
| static readonly FILL = 0.5; | ||
| static readonly POND = 0.36; | ||
| static readonly ITERATIONS = 4; | ||
| static readonly HEIGHT_MAX: number; | ||
| static zToStep(z?: number): number; | ||
| static reducer(input: number[][], heights: number[][]): number[][]; | ||
| static createMatrix({ min, max, iterations, fill, cols, rows }: { | ||
| min?: number | undefined; | ||
| max?: number | undefined; | ||
| iterations?: number | undefined; | ||
| fill?: number | undefined; | ||
| cols?: number | undefined; | ||
| rows?: number | undefined; | ||
| }): number[][]; | ||
| protected readonly heights: number[][]; | ||
| constructor(); | ||
| getZ(x: number, y: number): number; | ||
| protected forEachHeight(heights: number[][] | undefined, iterator: (col: number, row: number, height: number) => void): void; | ||
| protected getXY(col: number, row: number): { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
| protected createCollider(col: number, row: number, z: number): import("check2d").Box<any>; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.AbstractLevel = void 0; | ||
| const rot_js_1 = require("rot-js"); | ||
| const state_1 = require("../state"); | ||
| const detect_mobile_1 = require("../utils/detect-mobile"); | ||
| const query_params_1 = require("../utils/query-params"); | ||
| class AbstractLevel { | ||
| static zToStep(z = 0) { | ||
| return Math.round(z / AbstractLevel.STEP); | ||
| } | ||
| static reducer(input, heights) { | ||
| return heights.map((column, x) => column.map((value, y) => (input[x]?.[y] || 0) + value), []); | ||
| } | ||
| static createMatrix({ min = 0, max = 1, iterations = AbstractLevel.ITERATIONS, fill = AbstractLevel.FILL, cols = AbstractLevel.COLS, rows = AbstractLevel.ROWS }) { | ||
| return Array.from({ length: max }, () => { | ||
| const map = new rot_js_1.Map.Cellular(cols, rows); | ||
| map.randomize(fill); | ||
| for (let i = 0; i < iterations; i++) { | ||
| map.create(); | ||
| } | ||
| return map._map; | ||
| }) | ||
| .reduce(AbstractLevel.reducer, []) | ||
| .map((arrays) => arrays.map((value) => Math.max(0, value - min) * AbstractLevel.STEP)); | ||
| } | ||
| constructor() { | ||
| this.heights = []; | ||
| const min = Math.round(AbstractLevel.HEIGHT_MAX * 2 * AbstractLevel.POND); | ||
| const max = AbstractLevel.HEIGHT_MAX + min; | ||
| this.heights = AbstractLevel.createMatrix({ | ||
| min, | ||
| max | ||
| }); | ||
| } | ||
| getZ(x, y) { | ||
| const posX = Math.floor(x + AbstractLevel.COLS / 2); | ||
| const posY = Math.floor(y + AbstractLevel.ROWS / 2); | ||
| return this.heights[posX]?.[posY] || 0; | ||
| } | ||
| forEachHeight(heights = this.heights, iterator) { | ||
| heights.forEach((rows, col) => { | ||
| rows.forEach((height, row) => { | ||
| if (height) { | ||
| iterator(col, row, height); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| getXY(col, row) { | ||
| return { | ||
| x: col - AbstractLevel.COLS / 2, | ||
| y: row - AbstractLevel.ROWS / 2 | ||
| }; | ||
| } | ||
| createCollider(col, row, z) { | ||
| const { x, y } = this.getXY(col, row); | ||
| return state_1.physics.createBox({ x, y }, 1, 1, { | ||
| isStatic: true, | ||
| userData: { step: AbstractLevel.zToStep(z) } | ||
| }); | ||
| } | ||
| } | ||
| exports.AbstractLevel = AbstractLevel; | ||
| AbstractLevel.STEP = 0.25; | ||
| AbstractLevel.COLS = detect_mobile_1.DeviceDetector.HIGH_END ? 32 : 24; | ||
| AbstractLevel.ROWS = detect_mobile_1.DeviceDetector.HIGH_END ? 32 : 24; | ||
| AbstractLevel.FILL = 0.5; | ||
| AbstractLevel.POND = 0.36; | ||
| AbstractLevel.ITERATIONS = 4; | ||
| AbstractLevel.HEIGHT_MAX = 'height' in query_params_1.queryParams | ||
| ? Number(query_params_1.queryParams.height) | ||
| : detect_mobile_1.DeviceDetector.HIGH_END | ||
| ? 16 | ||
| : 12; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
6386534
-0.01%121
-3.2%