wire
This commit is contained in:
parent
e20381d55d
commit
aa54788ff1
|
@ -8,20 +8,21 @@ Quaternion = require './lib/quaternion'
|
|||
Vector = require './lib/vector'
|
||||
|
||||
class Face
|
||||
|
||||
@X = 0
|
||||
@Y = 1
|
||||
@Z = 2
|
||||
@NX = 3
|
||||
@NY = 4
|
||||
@NZ = 5
|
||||
|
||||
@orientationForFace: (face) ->
|
||||
switch face % 6
|
||||
# when 0 then return Quaternion.rot_90_Y
|
||||
# when 1 then return Quaternion.rot_0
|
||||
# when 2 then return Quaternion.rot_270_X
|
||||
# when 3 then return Quaternion.rot_270_Y
|
||||
# when 4 then return Quaternion.rot_90_X
|
||||
# when 5 then return Quaternion.rot_180_X
|
||||
when 0 then return Quaternion.rot_90_Y
|
||||
when 1 then return Quaternion.rot_90_X
|
||||
when 1 then return Quaternion.rot_270_X
|
||||
when 2 then return Quaternion.rot_0
|
||||
when 3 then return Quaternion.rot_270_Y
|
||||
when 4 then return Quaternion.rot_270_X
|
||||
when 4 then return Quaternion.rot_90_X
|
||||
when 5 then return Quaternion.rot_180_X
|
||||
|
||||
@normalVectorForFace: (face) ->
|
||||
|
@ -31,12 +32,5 @@ class Face
|
|||
when 1 then return new Vector 0, o, 0
|
||||
when 2 then return new Vector 0, 0, o
|
||||
new Vector
|
||||
|
||||
@X = 0
|
||||
@Y = 1
|
||||
@Z = 2
|
||||
@NX = 3
|
||||
@NY = 4
|
||||
@NZ = 5
|
||||
|
||||
|
||||
module.exports = Face
|
||||
|
|
|
@ -10,6 +10,21 @@ Vector = require './lib/vector'
|
|||
|
||||
class Geom
|
||||
|
||||
@wire: ->
|
||||
quads = 16
|
||||
triangles = quads*2+8
|
||||
positions = new Float32Array triangles*9
|
||||
normals = new Float32Array triangles*9
|
||||
pi = -1
|
||||
pi = @quadStrip positions, normals, pi, @wireQuadStrip1
|
||||
pi = @quadStrip positions, normals, pi, @wireQuadStrip2
|
||||
pi = @triangleList positions, normals, pi, @wireTriangles
|
||||
geom = new THREE.BufferGeometry
|
||||
geom.addAttribute 'position', new THREE.BufferAttribute positions, 3
|
||||
geom.addAttribute 'normal', new THREE.BufferAttribute normals, 3
|
||||
geom.translate 0,0,-0.5+0.008
|
||||
geom
|
||||
|
||||
@kolben: ->
|
||||
quads = 6+8
|
||||
triangles = quads*2
|
||||
|
@ -183,7 +198,44 @@ class Geom
|
|||
positions[pi+=1] = strip[qi+jj+i]
|
||||
normals[pi] = n[i]
|
||||
pi
|
||||
|
||||
# 000 000 000 00000000 00000000
|
||||
# 000 0 000 000 000 000 000
|
||||
# 000000000 000 0000000 0000000
|
||||
# 000 000 000 000 000 000
|
||||
# 00 00 000 000 000 00000000
|
||||
|
||||
@wireQuadStrip1 = [
|
||||
0, 0.18, 0, 0, 0.14, 0.05, 0.14, 0.14, 0, 0.1, 0.1, 0.05,
|
||||
0.18, 0, 0, 0.14, 0, 0.05,
|
||||
0.14, -0.14, 0, 0.1, -0.1, 0.05,
|
||||
0, -0.18, 0, 0, -0.14, 0.05,
|
||||
-0.14, -0.14, 0, -0.1, -0.1, 0.05,
|
||||
-0.18, 0, 0, -0.14, 0, 0.05,
|
||||
-0.14, 0.14, 0, -0.1, 0.1, 0.05,
|
||||
0, 0.18, 0, 0, 0.14, 0.05,
|
||||
]
|
||||
@wireQuadStrip2 = [
|
||||
0, 0.14, 0.05, 0, 0.07, 0.08, 0.1, 0.1, 0.05, 0.05, 0.05, 0.08,
|
||||
0.14, 0, 0.05, 0.07, 0, 0.08,
|
||||
0.1, -0.1, 0.05, 0.05, -0.05, 0.08,
|
||||
0, -0.14, 0.05, 0, -0.07, 0.08,
|
||||
-0.1, -0.1, 0.05, -0.05, -0.05, 0.08,
|
||||
-0.14, 0, 0.05, -0.07, 0, 0.08,
|
||||
-0.1, 0.1, 0.05, -0.05, 0.05, 0.08,
|
||||
0, 0.14, 0.05, 0, 0.07, 0.08,
|
||||
]
|
||||
@wireTriangles = [
|
||||
0, 0.07, 0.08, 0.05, 0.05, 0.08, 0,0,0.02,
|
||||
0.05, 0.05, 0.08, 0.07, 0, 0.08, 0,0,0.02,
|
||||
0.07, 0, 0.08, 0.05, -0.05, 0.08, 0,0,0.02,
|
||||
0.05, -0.05, 0.08, 0, -0.07, 0.08, 0,0,0.02,
|
||||
0, -0.07, 0.08, -0.05, -0.05, 0.08, 0,0,0.02,
|
||||
-0.05, -0.05, 0.08, -0.07, 0, 0.08, 0,0,0.02,
|
||||
-0.07, 0, 0.08, -0.05, 0.05, 0.08, 0,0,0.02,
|
||||
-0.05, 0.05, 0.08, 0, 0.07, 0.08, 0,0,0.02
|
||||
]
|
||||
|
||||
# 000 000 0000000 000 0000000 00000000 000 000
|
||||
# 000 000 000 000 000 000 000 000 0000 000
|
||||
# 0000000 000 000 000 0000000 0000000 000 0 000
|
||||
|
@ -427,9 +479,9 @@ class Geom
|
|||
0.2, 0.27, 0.077, 0.05, 0.33, 0.077, 0.05, 0.33, -0.077, 0.2, 0.27, -0.077,
|
||||
-0.27, 0.2, 0.077, -0.33, 0.05, 0.077, -0.33, 0.05, -0.077, -0.27, 0.2, -0.077,
|
||||
-0.2, -0.27, 0.077, -0.05, -0.33, 0.077, -0.05, -0.33, -0.077, -0.2, -0.27, -0.077,
|
||||
0.100, 0, 0.5, 0.071, 0.071, 0.5, 0, 0.100, 0.5, 0.071, -0.071, 0.5,
|
||||
-0.100, 0, 0.5, -0.071, -0.071, 0.5, 0, -0.100, 0.5, -0.071, 0.071, 0.5,
|
||||
0.071, -0.071, 0.5, 0, 0.100, 0.5, -0.071, 0.071, 0.5, 0, -0.100, 0.5,
|
||||
0.1, 0, 0.5, 0.071, 0.071, 0.5, 0, 0.1, 0.5, 0.071, -0.071, 0.5,
|
||||
-0.1, 0, 0.5, -0.071, -0.071, 0.5, 0, -0.1, 0.5, -0.071, 0.071, 0.5,
|
||||
0.071, -0.071, 0.5, 0, 0.1, 0.5, -0.071, 0.071, 0.5, 0, -0.1, 0.5,
|
||||
0.2, 0, -0.077, 0.141, -0.141, -0.077, 0, -0.2, -0.077, 0.141, 0.141, -0.077,
|
||||
-0.2, 0, -0.077, -0.141, 0.141, -0.077, 0, 0.2, -0.077, -0.141, -0.141, -0.077,
|
||||
0.141, 0.141, -0.077, 0, -0.2, -0.077, -0.141, -0.141, -0.077, 0, 0.2, -0.077,
|
||||
|
@ -456,23 +508,23 @@ class Geom
|
|||
0, 0.200, 0.077, 0, 0.059, 0.220,
|
||||
]
|
||||
@generatorQuadStrip3 = [
|
||||
0, 0.100, 0.354, 0, 0.100, 0.5, 0.071, 0.071, 0.354, 0.071, 0.071, 0.5,
|
||||
0.100, 0, 0.354, 0.100, 0, 0.5,
|
||||
0, 0.1, 0.354, 0, 0.1, 0.5, 0.071, 0.071, 0.354, 0.071, 0.071, 0.5,
|
||||
0.1, 0, 0.354, 0.1, 0, 0.5,
|
||||
0.071, -0.071, 0.354, 0.071, -0.071, 0.5,
|
||||
0, -0.100, 0.354, 0, -0.100, 0.5,
|
||||
0, -0.1, 0.354, 0, -0.1, 0.5,
|
||||
-0.071, -0.071, 0.354, -0.071, -0.071, 0.5,
|
||||
-0.100, 0, 0.354, -0.100, 0, 0.5,
|
||||
-0.1, 0, 0.354, -0.1, 0, 0.5,
|
||||
-0.071, 0.071, 0.354, -0.071, 0.071, 0.5,
|
||||
0, 0.100, 0.354, 0, 0.100, 0.5,
|
||||
0, 0.1, 0.354, 0, 0.1, 0.5,
|
||||
]
|
||||
@generatorQuadStrip4 = [
|
||||
0.042, 0.042, 0.220, 0.071, 0.071, 0.354, 0.059, 0, 0.220, 0.100, 0, 0.354,
|
||||
0.042, 0.042, 0.220, 0.071, 0.071, 0.354, 0.059, 0, 0.220, 0.1, 0, 0.354,
|
||||
0.042, -0.042, 0.220, 0.071, -0.071, 0.354,
|
||||
0, -0.059, 0.220, 0, -0.100, 0.354,
|
||||
0, -0.059, 0.220, 0, -0.1, 0.354,
|
||||
-0.042, -0.042, 0.220, -0.071, -0.071, 0.354,
|
||||
-0.059, 0, 0.220, -0.100, 0, 0.354,
|
||||
-0.059, 0, 0.220, -0.1, 0, 0.354,
|
||||
-0.042, 0.042, 0.220, -0.071, 0.071, 0.354,
|
||||
0, 0.059, 0.220, 0, 0.100, 0.354,
|
||||
0, 0.059, 0.220, 0, 0.1, 0.354,
|
||||
0.042, 0.042, 0.220, 0.071, 0.071, 0.354,
|
||||
]
|
||||
@generatorQuadStrip5 = [
|
||||
|
@ -532,21 +584,21 @@ class Geom
|
|||
# 0 000 000 0000000 0 00000000
|
||||
|
||||
@valveQuads = [
|
||||
0.100, 0, 0.5, 0.071, 0.071, 0.5, 0, 0.100, 0.5, 0.071, -0.071, 0.5,
|
||||
-0.100, 0, 0.5, -0.071, -0.071, 0.5, 0, -0.100, 0.5, -0.071, 0.071, 0.5,
|
||||
0.071, -0.071, 0.5, 0, 0.100, 0.5, -0.071, 0.071, 0.5, 0, -0.100, 0.5,
|
||||
0.100, 0, -0.5, 0.071, -0.071, -0.5, 0, -0.100, -0.5, 0.071, 0.071, -0.5,
|
||||
-0.100, 0, -0.5, -0.071, 0.071, -0.5, 0, 0.100, -0.5, -0.071, -0.071, -0.5,
|
||||
0.071, 0.071, -0.5, 0, -0.100, -0.5, -0.071, -0.071, -0.5, 0, 0.100, -0.5,
|
||||
0.1, 0, 0.5, 0.071, 0.071, 0.5, 0, 0.1, 0.5, 0.071, -0.071, 0.5,
|
||||
-0.1, 0, 0.5, -0.071, -0.071, 0.5, 0, -0.1, 0.5, -0.071, 0.071, 0.5,
|
||||
0.071, -0.071, 0.5, 0, 0.1, 0.5, -0.071, 0.071, 0.5, 0, -0.1, 0.5,
|
||||
0.1, 0, -0.5, 0.071, -0.071, -0.5, 0, -0.1, -0.5, 0.071, 0.071, -0.5,
|
||||
-0.1, 0, -0.5, -0.071, 0.071, -0.5, 0, 0.1, -0.5, -0.071, -0.071, -0.5,
|
||||
0.071, 0.071, -0.5, 0, -0.1, -0.5, -0.071, -0.071, -0.5, 0, 0.1, -0.5,
|
||||
]
|
||||
@valveQuadStrip1 = [
|
||||
0.071, 0.071, -0.346, 0.042, 0.042, -0.220, 0.100, 0, -0.346, 0.059, 0, -0.220,
|
||||
0.071, 0.071, -0.346, 0.042, 0.042, -0.220, 0.1, 0, -0.346, 0.059, 0, -0.220,
|
||||
0.071, -0.071, -0.346, 0.042, -0.042, -0.220,
|
||||
0, -0.100, -0.346, 0, -0.059, -0.220,
|
||||
0, -0.1, -0.346, 0, -0.059, -0.220,
|
||||
-0.071, -0.071, -0.346, -0.042, -0.042, -0.220,
|
||||
-0.100, 0, -0.346, -0.059, 0, -0.220,
|
||||
-0.1, 0, -0.346, -0.059, 0, -0.220,
|
||||
-0.071, 0.071, -0.346, -0.042, 0.042, -0.220,
|
||||
0, 0.100, -0.346, 0, 0.059, -0.220,
|
||||
0, 0.1, -0.346, 0, 0.059, -0.220,
|
||||
0.071, 0.071, -0.346, 0.042, 0.042, -0.220
|
||||
]
|
||||
@valveQuadStrip2 = [
|
||||
|
@ -560,33 +612,33 @@ class Geom
|
|||
0.042, 0.042, -0.220, 0.042, 0.042, 0.220
|
||||
]
|
||||
@valveQuadStrip3 = [
|
||||
0.071, 0.071, -0.5, 0.071, 0.071, -0.346, 0.100, 0, -0.5, 0.100, 0, -0.346,
|
||||
0.071, 0.071, -0.5, 0.071, 0.071, -0.346, 0.1, 0, -0.5, 0.1, 0, -0.346,
|
||||
0.071, -0.071, -0.5, 0.071, -0.071, -0.346,
|
||||
0, -0.100, -0.5, 0, -0.100, -0.346,
|
||||
0, -0.1, -0.5, 0, -0.1, -0.346,
|
||||
-0.071, -0.071, -0.5, -0.071, -0.071, -0.346,
|
||||
-0.100, 0, -0.5, -0.100, 0, -0.346,
|
||||
-0.1, 0, -0.5, -0.1, 0, -0.346,
|
||||
-0.071, 0.071, -0.5, -0.071, 0.071, -0.346,
|
||||
0, 0.100, -0.5, 0, 0.100, -0.346,
|
||||
0, 0.1, -0.5, 0, 0.1, -0.346,
|
||||
0.071, 0.071, -0.5, 0.071, 0.071, -0.346,
|
||||
]
|
||||
@valveQuadStrip4 = [
|
||||
0, 0.100, 0.354, 0, 0.100, 0.5, 0.071, 0.071, 0.354, 0.071, 0.071, 0.5,
|
||||
0.100, 0, 0.354, 0.100, 0, 0.5,
|
||||
0, 0.1, 0.354, 0, 0.1, 0.5, 0.071, 0.071, 0.354, 0.071, 0.071, 0.5,
|
||||
0.1, 0, 0.354, 0.1, 0, 0.5,
|
||||
0.071, -0.071, 0.354, 0.071, -0.071, 0.5,
|
||||
0, -0.100, 0.354, 0, -0.100, 0.5,
|
||||
0, -0.1, 0.354, 0, -0.1, 0.5,
|
||||
-0.071, -0.071, 0.354, -0.071, -0.071, 0.5,
|
||||
-0.100, 0, 0.354, -0.100, 0, 0.5,
|
||||
-0.1, 0, 0.354, -0.1, 0, 0.5,
|
||||
-0.071, 0.071, 0.354, -0.071, 0.071, 0.5,
|
||||
0, 0.100, 0.354, 0, 0.100, 0.5,
|
||||
0, 0.1, 0.354, 0, 0.1, 0.5,
|
||||
]
|
||||
@valveQuadStrip5 = [
|
||||
0.042, 0.042, 0.220, 0.071, 0.071, 0.354, 0.059, 0, 0.220, 0.100, 0, 0.354,
|
||||
0.042, 0.042, 0.220, 0.071, 0.071, 0.354, 0.059, 0, 0.220, 0.1, 0, 0.354,
|
||||
0.042, -0.042, 0.220, 0.071, -0.071, 0.354,
|
||||
0, -0.059, 0.220, 0, -0.100, 0.354,
|
||||
0, -0.059, 0.220, 0, -0.1, 0.354,
|
||||
-0.042, -0.042, 0.220, -0.071, -0.071, 0.354,
|
||||
-0.059, 0, 0.220, -0.100, 0, 0.354,
|
||||
-0.059, 0, 0.220, -0.1, 0, 0.354,
|
||||
-0.042, 0.042, 0.220, -0.071, 0.071, 0.354,
|
||||
0, 0.059, 0.220, 0, 0.100, 0.354,
|
||||
0, 0.059, 0.220, 0, 0.1, 0.354,
|
||||
0.042, 0.042, 0.220, 0.071, 0.071, 0.354,
|
||||
]
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
module.exports =
|
||||
Gear: require './gear'
|
||||
Stone: require './stone'
|
||||
Wire: require './wire'
|
||||
WireStone: require './wirestone'
|
||||
Wall: require './wall'
|
||||
MotorGear: require './motorgear'
|
||||
MotorCylinder: require './motorcylinder'
|
||||
|
|
|
@ -38,9 +38,10 @@ class Levels
|
|||
# "fallen",
|
||||
# "cheese",
|
||||
# "invisimaze",
|
||||
"spiral",
|
||||
# "spiral",
|
||||
# difficult
|
||||
"slick", "bridge", "flower", "stones", "walls", "grid",
|
||||
# "slick",
|
||||
"bridge", "flower", "stones", "walls", "grid",
|
||||
"rings",
|
||||
# "core",
|
||||
"bronze", "pool",
|
||||
|
|
|
@ -22,27 +22,28 @@ module.exports =
|
|||
place a wire stone
|
||||
next to the exit
|
||||
"""
|
||||
player: position: [0,-3,1]
|
||||
player:
|
||||
position: [0,-3,1]
|
||||
exits: [
|
||||
name: "exit"
|
||||
active: 0
|
||||
position: [0,-1,0]
|
||||
]
|
||||
create: ->
|
||||
|
||||
s = world.size
|
||||
{Face,MotorCylinder,MotorGear,Generator,Wire} = require '../items'
|
||||
|
||||
world.addObjectAtPos KikiMotorGear(KikiFace.NY), KikiPos s.x/2-1, s.y-1, s.z/2
|
||||
world.addObjectAtPos KikiMotorCylinder(KikiFace.NY), KikiPos s.x/2-1, s.y-2, s.z/2
|
||||
world.addObjectAtPos KikiGenerator(KikiFace.NY), KikiPos s.x/2+1, s.y-1, s.z/2
|
||||
world.addObjectLine "KikiWire (KikiFace.NY, KikiWire.VERTICAL)", s.x/2, s.y-1, 0, s.x/2, s.y-1, s.z
|
||||
world.addObjectLine "KikiWire (KikiFace.PY, KikiWire.VERTICAL)", s.x/2, 0, 0, s.x/2, 0, s.z
|
||||
world.addObjectLine "KikiWire (KikiFace.PZ, KikiWire.VERTICAL)", s.x/2, 0, 0, s.x/2, s.y, 0
|
||||
world.addObjectLine "KikiWire (KikiFace.NZ, KikiWire.VERTICAL)", s.x/2, 0, s.z-1, s.x/2, s.y, s.z-1
|
||||
world.addObjectAtPos new MotorGear(Face.NY), s.x/2-1, s.y-1, s.z/2
|
||||
world.addObjectAtPos new MotorCylinder(Face.NY), s.x/2-1, s.y-2, s.z/2
|
||||
world.addObjectAtPos new Generator(Face.NY), s.x/2+1, s.y-1, s.z/2
|
||||
world.addObjectLine new Wire(Face.NY, Wire.VERTICAL), s.x/2, s.y-1, 0, s.x/2, s.y-1, s.z
|
||||
world.addObjectLine new Wire(Face.Y, Wire.VERTICAL), s.x/2, 0, 0, s.x/2, 0, s.z
|
||||
world.addObjectLine new Wire(Face.Z, Wire.VERTICAL), s.x/2, 0, 0, s.x/2, s.y, 0
|
||||
world.addObjectLine new Wire(Face.NZ, Wire.VERTICAL), s.x/2, 0, s.z-1, s.x/2, s.y, s.z-1
|
||||
|
||||
world.addObjectAtPos 'KikiWireStone', KikiPos s.x/2+3, 0, s.z/2
|
||||
world.addObjectAtPos 'KikiWireStone', KikiPos s.x/2-3, 0, s.z/2
|
||||
world.addObjectAtPos 'KikiWireStone', KikiPos s.x/2+2, 1, s.z/2
|
||||
world.addObjectAtPos 'KikiWireStone', KikiPos s.x/2-2, 1, s.z/2
|
||||
world.addObjectAtPos 'KikiWireStone', KikiPos s.x/2+1, 2, s.z/2
|
||||
world.addObjectAtPos 'KikiWireStone', KikiPos s.x/2-1, 2, s.z/2
|
||||
world.addObjectAtPos 'WireStone', s.x/2+3, 0, s.z/2
|
||||
world.addObjectAtPos 'WireStone', s.x/2-3, 0, s.z/2
|
||||
world.addObjectAtPos 'WireStone', s.x/2+2, 1, s.z/2
|
||||
world.addObjectAtPos 'WireStone', s.x/2-2, 1, s.z/2
|
||||
world.addObjectAtPos 'WireStone', s.x/2+1, 2, s.z/2
|
||||
world.addObjectAtPos 'WireStone', s.x/2-1, 2, s.z/2
|
||||
|
|
|
@ -18,17 +18,26 @@ module.exports =
|
|||
create: ->
|
||||
|
||||
s = world.size
|
||||
{Gear,Generator,MotorCylinder,MotorGear,Face,Wall} = require '../items'
|
||||
{Gear,Generator,MotorCylinder,MotorGear,Face,Wall,Wire,WireStone,Stone} = require '../items'
|
||||
|
||||
# world.addObjectAtPos new Wire(Face.Z, Wire.ALL), 7, 5, 0
|
||||
# world.addObjectAtPos new Wire(Face.NZ, Wire.ALL), 7, 5, 0
|
||||
# world.addObjectAtPos new Wire(Face.Y, Wire.ALL), 7, 5, 0
|
||||
# world.addObjectAtPos new Wire(Face.NY, Wire.ALL), 7, 5, 0
|
||||
# world.addObjectAtPos new Wire(Face.X, Wire.ALL), 7, 5, 0
|
||||
# world.addObjectAtPos new Wire(Face.NX, Wire.ALL), 7, 5, 0
|
||||
|
||||
world.addObjectAtPos new Generator(Face.Z), 5, 7, 0
|
||||
world.addObjectAtPos new Wall(), 6, 7, 0
|
||||
world.addObjectAtPos new Wall(), 6, 7, 1
|
||||
world.addObjectAtPos new Wall(), 6, 7, 2
|
||||
world.addObjectAtPos new Stone(), 6, 7, 0
|
||||
world.addObjectAtPos new Stone(), 6, 7, 2
|
||||
world.addObjectAtPos new WireStone(), 6, 7, 1
|
||||
world.addObjectAtPos new WireStone(), 3, 7, 1
|
||||
|
||||
world.addObjectAtPos new MotorCylinder(Face.Z), 4, 5, 1
|
||||
world.addObjectAtPos new MotorGear(Face.Z), 4, 5, 0
|
||||
world.addObjectAtPos new Gear(Face.Z), 6, 5, 0
|
||||
world.addObjectAtPos new Gear(Face.Z), 5, 6, 0
|
||||
world.addObjectAtPos new Gear(Face.Z), 5, 4, 0
|
||||
# world.addObjectAtPos new Gear(Face.Z), 6, 5, 0
|
||||
# world.addObjectAtPos new Gear(Face.Z), 5, 6, 0
|
||||
# world.addObjectAtPos new Gear(Face.Z), 5, 4, 0
|
||||
return
|
||||
world.addObjectAtPos new Gear(Face.Z), 6, 6, 0
|
||||
world.addObjectAtPos new Gear(Face.Z), 4, 4, 0
|
||||
|
|
|
@ -24,7 +24,8 @@ class Vector
|
|||
@w = w ? 0
|
||||
if Number.isNaN @x or Number.isNaN @w
|
||||
throw new Error
|
||||
|
||||
|
||||
clone: -> new Vector @
|
||||
copy: (v) ->
|
||||
@x = v.x
|
||||
@y = v.y
|
||||
|
|
|
@ -12,6 +12,12 @@ module.exports =
|
|||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 20
|
||||
|
||||
wire: new THREE.MeshPhongMaterial
|
||||
color: 0xff0000
|
||||
side: THREE.DoubleSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 40
|
||||
|
||||
raster: new THREE.MeshPhongMaterial
|
||||
color: 0x880000
|
||||
|
@ -27,7 +33,7 @@ module.exports =
|
|||
|
||||
plate: new THREE.MeshPhongMaterial
|
||||
color: 0x880000
|
||||
side: THREE.FrontSide
|
||||
side: THREE.DoubleSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 10
|
||||
emissive: 0x880000
|
||||
|
|
|
@ -62,7 +62,7 @@ class Player extends Bot
|
|||
posDelta = world.getSpeed() / 10.0
|
||||
playerDir = @getCurrentDir()
|
||||
playerUp = @current_orientation.rotate(new Vector(0,1,0)).normal()
|
||||
camPos = @current_position.plus playerDir.mul 0.4*(1-Math.abs(@look_angle)/90)
|
||||
camPos = @current_position.clone()
|
||||
if @look_angle < 0
|
||||
camPos.add playerUp.mul -2*@look_angle/90
|
||||
@projection.setPosition @projection.getPosition().mul(1.0-posDelta).plus camPos.mul posDelta
|
||||
|
|
|
@ -4,12 +4,23 @@
|
|||
# 000 000 000 000 000 000
|
||||
# 00 00 000 000 000 00000000
|
||||
|
||||
Item = require './item'
|
||||
Item = require './item'
|
||||
Geom = require './geom'
|
||||
Face = require './face'
|
||||
Vector = require './lib/vector'
|
||||
Material = require './material'
|
||||
|
||||
class Wire extends Item
|
||||
|
||||
@UP =1
|
||||
@RIGHT =2
|
||||
@DOWN =4
|
||||
@LEFT =8
|
||||
@VERTICAL =5
|
||||
@HORIZONTAL =10
|
||||
@ALL =15
|
||||
|
||||
constructor: (@face, @connections) ->
|
||||
|
||||
constructor: (@face=Face.Z, @connections=Wire.ALL) ->
|
||||
super
|
||||
@active = false
|
||||
@value = 1.0
|
||||
|
@ -18,7 +29,39 @@ class Wire extends Item
|
|||
@SWITCH_ON_EVENT = @addEventWithName "on"
|
||||
@SWITCHED_EVENT = @addEventWithName "switched"
|
||||
|
||||
@updateActive: ->
|
||||
createMesh: ->
|
||||
o = 0.005
|
||||
geom = new THREE.Geometry
|
||||
|
||||
h = 0.1
|
||||
s = 0.5
|
||||
w = s+o
|
||||
|
||||
if @connections & Wire.RIGHT
|
||||
plane = new THREE.PlaneGeometry w, h
|
||||
plane.translate w/2, 0, -s+o
|
||||
geom.merge plane
|
||||
if @connections & Wire.LEFT
|
||||
plane = new THREE.PlaneGeometry w, h
|
||||
plane.translate -w/2, 0, -s+o
|
||||
geom.merge plane
|
||||
if @connections & Wire.UP
|
||||
plane = new THREE.PlaneGeometry h, w
|
||||
plane.translate 0, w/2, -s+o
|
||||
geom.merge plane
|
||||
if @connections & Wire.DOWN
|
||||
plane = new THREE.PlaneGeometry h, w
|
||||
plane.translate 0, -w/2, -s+o
|
||||
geom.merge plane
|
||||
|
||||
@wire = new THREE.Mesh geom, Material.wire
|
||||
@mesh = new THREE.Mesh Geom.wire(), Material.plate
|
||||
@mesh.add @wire
|
||||
@mesh.receiveShadow = true
|
||||
@mesh.position.copy Face.normalVectorForFace(@face).mul -(0.5+o)
|
||||
@mesh.quaternion.copy Face.orientationForFace @face
|
||||
|
||||
updateActive: ->
|
||||
for wire in @getNeighborWires()
|
||||
@setActive true if wire.active
|
||||
|
||||
|
@ -50,22 +93,22 @@ class Wire extends Item
|
|||
neighbor_dirs = []
|
||||
|
||||
rot = Face.orientationForFace @face
|
||||
n = Face.normalVectorForFace @face
|
||||
n = Face.normalVectorForFace @face
|
||||
|
||||
neighbor_dirs.push_back new Vector
|
||||
neighbor_dirs.push new Vector
|
||||
|
||||
if @connections & RIGHT
|
||||
neighbor_dirs.push_back rot.rotate new Vector(1,0,0)
|
||||
neighbor_dirs.push_back rot.rotate new Vector(1,0,0) + n
|
||||
if @connections & LEFT
|
||||
neighbor_dirs.push_back rot.rotate new Vector(-1,0,0)
|
||||
neighbor_dirs.push_back rot.rotate new Vector(-1,0,0) + n
|
||||
if @connections & UP
|
||||
neighbor_dirs.push_back rot.rotate new Vector(0,1,0)
|
||||
neighbor_dirs.push_back rot.rotate new Vector(0,1,0) + n
|
||||
if @connections & DOWN
|
||||
neighbor_dirs.push_back rot.rotate new Vector(0,-1,0)
|
||||
neighbor_dirs.push_back rot.rotate new Vector(0,-1,0) + n
|
||||
if @connections & Wire.RIGHT
|
||||
neighbor_dirs.push rot.rotate new Vector(1,0,0)
|
||||
neighbor_dirs.push rot.rotate new Vector(1,0,0).plus n
|
||||
if @connections & Wire.LEFT
|
||||
neighbor_dirs.push rot.rotate new Vector(-1,0,0)
|
||||
neighbor_dirs.push rot.rotate new Vector(-1,0,0).plus n
|
||||
if @connections & Wire.UP
|
||||
neighbor_dirs.push rot.rotate new Vector(0,1,0)
|
||||
neighbor_dirs.push rot.rotate new Vector(0,1,0).plus n
|
||||
if @connections & Wire.DOWN
|
||||
neighbor_dirs.push rot.rotate new Vector(0,-1,0)
|
||||
neighbor_dirs.push rot.rotate new Vector(0,-1,0).plus n
|
||||
|
||||
for i in [0...neighbor_dirs.length]
|
||||
neighbors = world.getObjectsOfTypeAtPos Wire, @position.plus neighbor_dirs[i]
|
||||
|
@ -76,62 +119,22 @@ class Wire extends Item
|
|||
for neighbor_point in neighbor_points
|
||||
if (neighbor_point.minus point).length() < 0.1
|
||||
wires.push iter
|
||||
|
||||
wires
|
||||
|
||||
getConnectionPoints: ->
|
||||
points = []
|
||||
to_border = 0.5 * Face.normalVectorForFace @face
|
||||
to_border = Face.normalVectorForFace(@face).mul 0.5
|
||||
rot = Face.orientationForFace @face
|
||||
|
||||
if (connections & RIGHT)
|
||||
points.push position.plus to_border.plus rot.rotate new Vector 0.5, 0, 0
|
||||
if (connections & LEFT)
|
||||
points.push position.plus to_border.plus rot.rotate new Vector -0.5, 0, 0
|
||||
if (connections & UP)
|
||||
points.push position.plus to_border.plus rot.rotate new Vector 0, 0.5, 0
|
||||
if (connections & DOWN)
|
||||
points.push position.plus to_border.plus rot.rotate new Vector 0, -0.5, 0
|
||||
|
||||
if @connections & Wire.RIGHT
|
||||
points.push @position.plus to_border.plus rot.rotate new Vector 0.5, 0, 0
|
||||
if @connections & Wire.LEFT
|
||||
points.push @position.plus to_border.plus rot.rotate new Vector -0.5, 0, 0
|
||||
if @connections & Wire.UP
|
||||
points.push @position.plus to_border.plus rot.rotate new Vector 0, 0.5, 0
|
||||
if @connections & Wire.DOWN
|
||||
points.push @position.plus to_border.plus rot.rotate new Vector 0, -0.5, 0
|
||||
points
|
||||
|
||||
display: ->
|
||||
# KikiObject::preDisplay();
|
||||
# KVector face_normal = KikiFace::normalVectorForFace (face);
|
||||
# float o = 0.005;
|
||||
# ((0.5-o) * face_normal).glTranslate();
|
||||
#
|
||||
# glPushMatrix();
|
||||
#
|
||||
# KMatrix mat(KikiFace::orientationForFace (face));
|
||||
# mat.glMultMatrix();
|
||||
#
|
||||
# colors[KikiWire_base_color].glColor();
|
||||
#
|
||||
# render_wire;
|
||||
#
|
||||
# glDisable (GL_CULL_FACE);
|
||||
# float h = 0.05;
|
||||
# float s = 0.5+o;
|
||||
# glNormal3f(0.0, 0.0, 1.0);
|
||||
# if (connections & RIGHT) glRectf ( 0.0, -h, s, h);
|
||||
# if (connections & LEFT) glRectf (-s, -h, 0.0, h);
|
||||
# if (connections & UP) glRectf (-h, 0.0, h, s);
|
||||
# if (connections & DOWN) glRectf (-h, -s, h, 0.0);
|
||||
# glEnable (GL_CULL_FACE);
|
||||
#
|
||||
# glPopMatrix();
|
||||
#
|
||||
# if (active)
|
||||
# KColor c (colors[KikiWire_light_color]);
|
||||
# c.setAlpha (value);
|
||||
# c.glColor();
|
||||
#
|
||||
# (face_normal * -0.1).glTranslate();
|
||||
#
|
||||
# KikiBillBoard::displayTextureWithSize
|
||||
# (Controller.world->getTextureId(KikiWorld::TEXTURE_GRADIENT), 0.15);
|
||||
#
|
||||
# KikiObject::postDisplay();
|
||||
|
||||
# KikiBillBoard::displayTextureWithSize 0.15
|
||||
|
||||
module.exports = Wire
|
||||
|
|
|
@ -8,28 +8,25 @@ Stone = require './stone'
|
|||
Wall = require './wall'
|
||||
Face = require './face'
|
||||
Wire = require './wire'
|
||||
Action = require './action'
|
||||
Generator = require './generator'
|
||||
|
||||
class WireStone extends Stone
|
||||
|
||||
constructor: () ->
|
||||
@wires = [null, null, null, null, null, null]
|
||||
super
|
||||
|
||||
initAction: (action) ->
|
||||
|
||||
switch action.id
|
||||
|
||||
when Action.FALL, Action.PUSH
|
||||
|
||||
for i in [0...6]
|
||||
if @wires[i]?
|
||||
world.unsetObject @wires[i]
|
||||
@wires[i].setActive false
|
||||
|
||||
for generator in world.getObjectsOfType Generator
|
||||
if generator.active
|
||||
generator.activateWires()
|
||||
|
||||
super action
|
||||
|
||||
setPosition: (pos) ->
|
||||
|
@ -37,7 +34,7 @@ class WireStone extends Stone
|
|||
newPos = pos.minus Face.normalVectorForFace i
|
||||
if @isFreePos newPos
|
||||
if not @wires[i]?
|
||||
@wires[i] = new Wire i
|
||||
@wires[i] = new Wire (i+3)%6
|
||||
world.addObjectAtPos @wires[i], newPos
|
||||
else
|
||||
world.setObjectAtPos @wires[i], newPos
|
||||
|
@ -49,20 +46,20 @@ class WireStone extends Stone
|
|||
for generator in world.getObjectsOfType Generator
|
||||
if generator.active
|
||||
generator.activateWires()
|
||||
|
||||
|
||||
super pos
|
||||
|
||||
setCurrentPosition: (pos) ->
|
||||
super pos
|
||||
for i in [0...6]
|
||||
@wires[i]?.setPosition pos.minus Face.normalVectorForFace i
|
||||
@wires[i]?.setPosition @current_position.minus Face.normalVectorForFace i
|
||||
|
||||
isFreePos: (pos) ->
|
||||
if world.isUnoccupiedPos pos
|
||||
return true
|
||||
if world.isValidPos pos
|
||||
occupant = world.getOccupantAtPos pos
|
||||
return (occupant instanceof Wall) or not (occupant instanceof Stone)
|
||||
return not (occupant instanceof Wall) and not (occupant instanceof Stone)
|
||||
return false
|
||||
|
||||
module.exports = WireStone
|
||||
|
|
|
@ -422,12 +422,10 @@ class World extends Actor
|
|||
# 000 000 000 000 000 000 000 000 000 000
|
||||
# 0000000 0000000 0000000 00000000 0000000 000 0000000
|
||||
|
||||
getObjectsOfType: (clss) -> @objects.filter (o) -> o instanceof clss
|
||||
getObjectsOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getObjectsOfType clss
|
||||
getObjectOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getRealObjectOfType clss
|
||||
getOccupantAtPos: (pos) ->
|
||||
# log "getOccupantAtPos cell? #{@getCellAtPos(pos)?}", pos
|
||||
@getCellAtPos(pos)?.getOccupant()
|
||||
getObjectsOfType: (clss) -> @objects.filter (o) -> o instanceof clss
|
||||
getObjectsOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getObjectsOfType(clss) ? []
|
||||
getObjectOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getRealObjectOfType(clss) ? []
|
||||
getOccupantAtPos: (pos) -> @getCellAtPos(pos)?.getOccupant()
|
||||
getRealOccupantAtPos: (pos) ->
|
||||
occupant = @getOccupantAtPos pos
|
||||
if occupant and occupant instanceof TmpObject
|
||||
|
@ -454,7 +452,6 @@ class World extends Actor
|
|||
if not cell?
|
||||
cellIndex = @posToIndex(pos)
|
||||
cell = new Cell()
|
||||
# log "created cell at index #{cellIndex}"
|
||||
@cells[cellIndex] = cell
|
||||
|
||||
object.setPosition pos
|
||||
|
@ -462,11 +459,9 @@ class World extends Actor
|
|||
|
||||
unsetObject: (object) ->
|
||||
pos = object.getPos()
|
||||
# log "world.unsetObject #{object.name} pos:", pos
|
||||
if cell = @getCellAtPos pos
|
||||
cell.removeObject object
|
||||
if cell.isEmpty()
|
||||
# log 'world.unsetObject remove cell empty cell', pos
|
||||
@cells[@posToIndex(pos)] = null
|
||||
else
|
||||
log 'world.unsetObject [WARNING] no cell at pos:', pos
|
||||
|
@ -502,10 +497,7 @@ class World extends Actor
|
|||
true
|
||||
|
||||
toggle: (objectName) ->
|
||||
# toggles object with name objectName
|
||||
object = @getObjectWithName objectName
|
||||
log "world.toggle #{objectName} #{object?}"
|
||||
# @startTimedAction object.getActionWithName "toggle"
|
||||
object.getActionWithName("toggle").perform()
|
||||
|
||||
# 0000000 00000000 000 00000000 000000000 00000000
|
||||
|
@ -515,7 +507,6 @@ class World extends Actor
|
|||
# 0000000 00000000 0000000 00000000 000 00000000
|
||||
|
||||
deleteObject: (object) ->
|
||||
# log "world.deleteObject #{object.name}"
|
||||
if not object?
|
||||
log "world.deleteObject [WARNING] no object?"
|
||||
return
|
||||
|
@ -524,7 +515,6 @@ class World extends Actor
|
|||
|
||||
deleteAllObjects: () ->
|
||||
# log 'world.deleteAllObjects'
|
||||
|
||||
Timer.removeAllActions()
|
||||
|
||||
if @player?
|
||||
|
@ -553,14 +543,14 @@ class World extends Actor
|
|||
for o in @objects
|
||||
if objectName == o.name
|
||||
return o
|
||||
log "World.getObjectWithName :: no object found with name #{objectName}"
|
||||
log "World.getObjectWithName [WARNING] no object with name #{objectName}"
|
||||
null
|
||||
|
||||
setCameraMode: (mode) -> @camera_mode = clamp World.CAMERA_INSIDE, World.CAMERA_FOLLOW, mode
|
||||
|
||||
changeCameraMode: () ->
|
||||
@camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
||||
log "world.changeCameraMode #{@camera_mode}"
|
||||
# log "world.changeCameraMode #{@camera_mode}"
|
||||
@camera_mode
|
||||
|
||||
# 0000000 0000000 000 00 00 0000000 000 000 00000000
|
||||
|
@ -597,16 +587,15 @@ class World extends Actor
|
|||
log "world.objectWillMoveToPos [WARNING] #{object.name} already occupied:", targetPos
|
||||
|
||||
if object.name != 'player'
|
||||
# log "---------- tmpObjects not player? #{object.name}"
|
||||
@unsetObject object # remove object from cell grid
|
||||
|
||||
# log 'tmpObject at old pos', sourcePos
|
||||
# log 'world.objectWillMoveToPos tmpObject at old pos', sourcePos
|
||||
tmpObject = new TmpObject object # insert tmp object at old pos
|
||||
tmpObject.setPosition sourcePos
|
||||
tmpObject.time = -duration
|
||||
@addObjectAtPos tmpObject, sourcePos
|
||||
|
||||
# log 'tmpObject at new pos', targetPos
|
||||
# log 'world.objectWillMoveToPos tmpObject at new pos', targetPos
|
||||
tmpObject = new TmpObject object # insert tmp object at new pos
|
||||
tmpObject.setPosition targetPos
|
||||
tmpObject.time = duration
|
||||
|
@ -634,24 +623,18 @@ class World extends Actor
|
|||
if @isOccupiedPos targetPos
|
||||
log "World.objectMoved [WARNING] #{movedObject.name} occupied target pos:", targetPos
|
||||
|
||||
# log 'World.objectMovedFromPos sourcePos:', sourcePos
|
||||
# log 'World.objectMovedFromPos targetPos:', targetPos
|
||||
|
||||
if sourceCell?
|
||||
sourceCell.removeObject movedObject
|
||||
if sourceCell.isEmpty()
|
||||
# log 'world.objectMoved remove empty cell at pos:', sourcePos
|
||||
@cells[@posToIndex(sourcePos)] = null
|
||||
|
||||
targetCell = @getCellAtPos targetPos
|
||||
if not targetCell?
|
||||
cellIndex = @posToIndex targetPos
|
||||
targetCell = new Cell()
|
||||
# log "world.objectMoved created cell at index #{cellIndex}", targetPos
|
||||
@cells[cellIndex] = targetCell
|
||||
|
||||
if targetCell?
|
||||
# log "add #{movedObject.name} to targetCell at pos", targetPos
|
||||
targetCell.addObject movedObject
|
||||
else
|
||||
log "world.objectMoved [WARNING] #{movedObject.name} no target cell?"
|
||||
|
|
|
@ -2,6 +2,7 @@ name kiki
|
|||
main js/main.js
|
||||
dependencies
|
||||
coffee-script ^1.10.0
|
||||
howler ^2.0.0
|
||||
lodash ^4.13.1
|
||||
noon >=1.0.12
|
||||
performance-now ^0.2.0
|
||||
|
|
Loading…
Reference in New Issue
Block a user