intractive object PairMatchingGame done, no animations
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import { BoxGeometry, Mesh, MeshStandardMaterial, Group, Vector3 } from 'three';
|
import { BoxGeometry, Mesh, MeshStandardMaterial, Group, Vector3, CatmullRomCurve3 } from 'three';
|
||||||
import { LineGeometry } from 'three/examples/jsm/Addons.js';
|
import { LineMaterial, LineGeometry, Line2 } from 'three/examples/jsm/Addons.js';
|
||||||
import { LineMaterial } from 'three/examples/jsm/Addons.js';
|
|
||||||
import { Line2 } from 'three/examples/jsm/Addons.js';
|
|
||||||
import { centerOrigin } from '@/lib/MeshUtils';
|
import { centerOrigin } from '@/lib/MeshUtils';
|
||||||
import { EventManager } from '@/lib/EventManager';
|
import { EventManager } from '@/lib/EventManager';
|
||||||
import Utils from '@/lib/Utils';
|
import Utils from '@/lib/Utils';
|
||||||
@@ -60,17 +58,15 @@ class PairMatchingGame extends EventManager {
|
|||||||
let clicked, done = [];
|
let clicked, done = [];
|
||||||
|
|
||||||
let connect = (a, b)=>{
|
let connect = (a, b)=>{
|
||||||
let g = new LineGeometry();
|
let crc = new CatmullRomCurve3([
|
||||||
g.setFromPoints([
|
|
||||||
a.position,
|
a.position,
|
||||||
new Vector3().copy(a.position).lerpVectors(a.position, b.position, 0.5).multiplyScalar(1.1),
|
new Vector3().copy(a.position).lerpVectors(a.position, b.position, 0.5).multiplyScalar(1 + Math.random() * 0.1 * done.length / c),
|
||||||
b.position
|
b.position
|
||||||
]);
|
])
|
||||||
|
let g = new LineGeometry().setFromPoints( crc.getPoints(7) );
|
||||||
let m = new Line2(g, new LineMaterial( {
|
let m = new Line2(g, new LineMaterial( {
|
||||||
color: 0x00FF00,
|
color: 0x00FF00,
|
||||||
linewidth: 5, // in world units with size attenuation, pixels otherwise
|
linewidth: 5, // in world units with size attenuation, pixels otherwise
|
||||||
dashed: false,
|
|
||||||
alphaToCoverage: true,
|
|
||||||
} ));
|
} ));
|
||||||
container.add(m)
|
container.add(m)
|
||||||
}
|
}
|
||||||
@@ -85,9 +81,11 @@ class PairMatchingGame extends EventManager {
|
|||||||
if (oc.userData.gd.id === clicked.userData.gd.id){
|
if (oc.userData.gd.id === clicked.userData.gd.id){
|
||||||
connect(oc, clicked);
|
connect(oc, clicked);
|
||||||
done.push(oc.userData.gd.id)
|
done.push(oc.userData.gd.id)
|
||||||
}else{
|
if (done.length == c) {
|
||||||
clicked = null;
|
this.dispatchEvent({type:'finish'})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
clicked = null;
|
||||||
}else{
|
}else{
|
||||||
clicked.scale.setScalar(1.2);
|
clicked.scale.setScalar(1.2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user