three v154
This commit is contained in:
parent
3f84ddd8df
commit
5a85c0cae2
@ -55,6 +55,7 @@ export default class MazeMesh extends THREE.InstancedMesh {
|
||||
|
||||
isWall(position) {
|
||||
if (0 <= position.x && position.x < this.width &&
|
||||
0 <= position.y &&
|
||||
0 <= position.z && position.z < this.length) {
|
||||
return this.map[Math.floor(position.z)][Math.floor(position.x)]
|
||||
} else {
|
||||
@ -62,6 +63,10 @@ export default class MazeMesh extends THREE.InstancedMesh {
|
||||
}
|
||||
}
|
||||
|
||||
collision(position) {
|
||||
return this.isWall(this.worldToLocal(position))
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.map.map(row =>
|
||||
row.map(isWall => isWall? "██":" ").join("")
|
||||
|
@ -12,8 +12,8 @@
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"three": "https://unpkg.com/three@0.153/build/three.module.js?module",
|
||||
"three/addons/": "https://unpkg.com/three@0.153/examples/jsm/"
|
||||
"three": "https://unpkg.com/three@0.154/build/three.module.js?module",
|
||||
"three/addons/": "https://unpkg.com/three@0.154/examples/jsm/"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
5
main.js
5
main.js
@ -3,7 +3,6 @@ import * as THREE from 'three';
|
||||
import { Octree } from 'three/addons/math/Octree.js';
|
||||
import { Capsule } from 'three/addons/math/Capsule.js';
|
||||
import { Water } from 'three/addons/objects/Water.js';
|
||||
// import { Sky } from 'three/addons/objects/Sky.js';
|
||||
import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';
|
||||
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
||||
import { OctreeHelper } from 'three/addons/helpers/OctreeHelper.js';
|
||||
@ -11,6 +10,7 @@ import Stats from 'three/addons/libs/stats.module.js';
|
||||
|
||||
import MazeMesh from './MazeMesh.js';
|
||||
|
||||
const playerHeight = 0.5;
|
||||
const mazeWidth = 23
|
||||
|
||||
const parameters = {
|
||||
@ -89,6 +89,7 @@ window.scene = scene;
|
||||
|
||||
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
camera.rotation.order = 'YXZ';
|
||||
camera.position.set(0, 25 + playerHeight, 0);
|
||||
|
||||
const mazeCollisionner = new THREE.Group();
|
||||
|
||||
@ -500,7 +501,7 @@ const STEPS_PER_FRAME = 10;
|
||||
|
||||
const playerCollider = new Capsule(
|
||||
new THREE.Vector3(0, 25.0, 0),
|
||||
new THREE.Vector3(0, 25.5, 0),
|
||||
new THREE.Vector3(0, 25 + playerHeight, 0),
|
||||
0.3
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user