gears
This commit is contained in:
parent
1ca6226283
commit
bce51b92eb
|
@ -16,7 +16,7 @@ class Face
|
||||||
@NY = 4
|
@NY = 4
|
||||||
@NZ = 5
|
@NZ = 5
|
||||||
|
|
||||||
@orientationForFace: (face) ->
|
@orientation: (face) ->
|
||||||
switch face % 6
|
switch face % 6
|
||||||
when 0 then return Quaternion.rot_90_Y
|
when 0 then return Quaternion.rot_90_Y
|
||||||
when 1 then return Quaternion.rot_270_X
|
when 1 then return Quaternion.rot_270_X
|
||||||
|
@ -25,7 +25,7 @@ class Face
|
||||||
when 4 then return Quaternion.rot_90_X
|
when 4 then return Quaternion.rot_90_X
|
||||||
when 5 then return Quaternion.rot_180_X
|
when 5 then return Quaternion.rot_180_X
|
||||||
|
|
||||||
@normalVectorForFace: (face) ->
|
@normal: (face) ->
|
||||||
o = (face < 3) and 1 or -1
|
o = (face < 3) and 1 or -1
|
||||||
switch face % 3
|
switch face % 3
|
||||||
when 0 then return new Vector o, 0, 0
|
when 0 then return new Vector o, 0, 0
|
||||||
|
@ -33,4 +33,7 @@ class Face
|
||||||
when 2 then return new Vector 0, 0, o
|
when 2 then return new Vector 0, 0, o
|
||||||
new Vector
|
new Vector
|
||||||
|
|
||||||
|
@orientationForFace: (face) -> @orientation face
|
||||||
|
@normalVectorForFace: (face) -> @normal face
|
||||||
|
|
||||||
module.exports = Face
|
module.exports = Face
|
||||||
|
|
|
@ -24,14 +24,15 @@ class Gear extends Valve
|
||||||
@mesh.add new THREE.Mesh Geom.valve(), Material.plate
|
@mesh.add new THREE.Mesh Geom.valve(), Material.plate
|
||||||
@mesh.receiveShadow = true
|
@mesh.receiveShadow = true
|
||||||
|
|
||||||
getNeighborGears: ->
|
neighborGears: ->
|
||||||
dirs = Gear.neighbors[@face % 3]
|
dirs = Gear.neighbors[@face % 3]
|
||||||
pos = @getPos()
|
pos = @getPos()
|
||||||
gears = []
|
gears = []
|
||||||
for i in [0...4]
|
for i in [0...4]
|
||||||
neighbor = world.getOccupantAtPos pos.plus new Pos dirs[i]
|
neighbor = world.getOccupantAtPos pos.plus new Pos dirs[i]
|
||||||
|
# log "gear.neighborGears #{neighbor?} #{neighbor instanceof Gear} #{neighbor?.face}", pos.plus new Pos dirs[i]
|
||||||
if neighbor? and neighbor instanceof Gear
|
if neighbor? and neighbor instanceof Gear
|
||||||
if neighbor.face == face
|
if neighbor.face == @face
|
||||||
gears.push neighbor
|
gears.push neighbor
|
||||||
gears
|
gears
|
||||||
|
|
||||||
|
@ -49,22 +50,30 @@ class Gear extends Valve
|
||||||
@updateActive()
|
@updateActive()
|
||||||
|
|
||||||
updateActive: ->
|
updateActive: ->
|
||||||
@setActive false
|
# log "gear.updateActive #{@active}"
|
||||||
for gear in @getNeighborGears()
|
for gear in @neighborGears()
|
||||||
|
log "gear.updateActive neighbor active #{gear.active}"
|
||||||
if gear.active
|
if gear.active
|
||||||
@setActive true
|
@setActive true
|
||||||
return
|
return
|
||||||
|
@setActive false
|
||||||
|
|
||||||
setActive: (active) ->
|
setActive: (active) ->
|
||||||
if @active != active
|
if @active != active
|
||||||
@active = active
|
@active = active
|
||||||
|
|
||||||
world.playSound @active and 'GEAR_ON' or 'GEAR_OFF'
|
world.playSound @active and 'GEAR_ON' or 'GEAR_OFF'
|
||||||
|
|
||||||
for gear in @getNeighborGears()
|
|
||||||
if @active
|
if @active
|
||||||
|
@startTimedAction @getActionWithId Action.ROTATE
|
||||||
|
else
|
||||||
|
@stopAction @getActionWithId Action.ROTATE
|
||||||
|
log "gear.setActive neighborGears #{@neighborGears().length}"
|
||||||
|
for gear in @neighborGears()
|
||||||
|
if @active
|
||||||
|
log 'gear.setActive activate neighbor'
|
||||||
gear.setActive true
|
gear.setActive true
|
||||||
else
|
else
|
||||||
|
log 'gear.setActive update neighbor'
|
||||||
gear.updateActive()
|
gear.updateActive()
|
||||||
|
|
||||||
module.exports = Gear
|
module.exports = Gear
|
||||||
|
|
|
@ -11,8 +11,7 @@ Material = require './material'
|
||||||
|
|
||||||
class Generator extends Gear
|
class Generator extends Gear
|
||||||
|
|
||||||
constructor: (face) ->
|
constructor: (face) -> super face
|
||||||
super face
|
|
||||||
|
|
||||||
createMesh: ->
|
createMesh: ->
|
||||||
@mesh = new THREE.Mesh Geom.generator(), Material.plate
|
@mesh = new THREE.Mesh Geom.generator(), Material.plate
|
||||||
|
@ -21,7 +20,6 @@ class Generator extends Gear
|
||||||
|
|
||||||
activateWires: ->
|
activateWires: ->
|
||||||
wires = world.getObjectsOfTypeAtPos Wire, @getPos()
|
wires = world.getObjectsOfTypeAtPos Wire, @getPos()
|
||||||
|
|
||||||
for wire in wires
|
for wire in wires
|
||||||
wire.setActive active
|
wire.setActive active
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,11 @@ module.exports =
|
||||||
# world.addObjectAtPos new Gear(Face.Z), 6, 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, 6, 0
|
||||||
# world.addObjectAtPos new Gear(Face.Z), 5, 4, 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), 6, 6, 0
|
||||||
world.addObjectAtPos new Gear(Face.Z), 4, 4, 0
|
world.addObjectAtPos new Gear(Face.Z), 4, 4, 0
|
||||||
world.addObjectAtPos new Gear(Face.Z), 4, 6, 0
|
world.addObjectAtPos new Gear(Face.Z), 4, 6, 0
|
||||||
world.addObjectAtPos new Gear(Face.Z), 6, 4, 0
|
world.addObjectAtPos new Gear(Face.Z), 6, 4, 0
|
||||||
|
return
|
||||||
|
|
||||||
world.addObjectAtPos new Gear(Face.NZ), 6, 5, 4
|
world.addObjectAtPos new Gear(Face.NZ), 6, 5, 4
|
||||||
world.addObjectAtPos new Gear(Face.NZ), 4, 5, 4
|
world.addObjectAtPos new Gear(Face.NZ), 4, 5, 4
|
||||||
|
|
|
@ -4,9 +4,13 @@
|
||||||
# 000 0 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
|
# 000 0 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
|
||||||
# 000 000 0000000 000 0000000 000 000 0000000 00000000 000 000 000 000
|
# 000 000 0000000 000 0000000 000 000 0000000 00000000 000 000 000 000
|
||||||
|
|
||||||
|
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||||
Gear = require './gear'
|
Gear = require './gear'
|
||||||
Geom = require './geom'
|
Geom = require './geom'
|
||||||
|
Face = require './face'
|
||||||
Material = require './material'
|
Material = require './material'
|
||||||
|
Quaternion = require './lib/quaternion'
|
||||||
|
MotorCylinder = require './motorcylinder'
|
||||||
|
|
||||||
class MotorGear extends Gear
|
class MotorGear extends Gear
|
||||||
|
|
||||||
|
@ -15,8 +19,19 @@ class MotorGear extends Gear
|
||||||
@setActive true
|
@setActive true
|
||||||
|
|
||||||
createMesh: ->
|
createMesh: ->
|
||||||
@mesh = new THREE.Mesh Geom.gear(), Material.gear
|
@mesh = new THREE.Mesh Geom.motor(), Material.plate
|
||||||
@mesh.add new THREE.Mesh Geom.motor(), Material.plate
|
@gear = new THREE.Mesh Geom.gear(), Material.gear
|
||||||
|
@mesh.add @gear
|
||||||
@mesh.receiveShadow = true
|
@mesh.receiveShadow = true
|
||||||
|
|
||||||
|
updateMesh: ->
|
||||||
|
# log "Valve.updateMesh #{@angle} #{@face}"
|
||||||
|
rot = Quaternion.rotationAroundVector (@clockwise and 1 or -1) * @angle, 0,0,1
|
||||||
|
@gear.quaternion.copy Face.orientationForFace(@face).mul rot
|
||||||
|
|
||||||
|
updateActive: ->
|
||||||
|
pos = @position.plus Face.normal @face
|
||||||
|
# log "MotorGear.updateActive #{@active}", pos, world.getOccupantAtPos(pos) instanceof MotorCylinder
|
||||||
|
@setActive world.getOccupantAtPos(pos) instanceof MotorCylinder
|
||||||
|
|
||||||
module.exports = MotorGear
|
module.exports = MotorGear
|
||||||
|
|
|
@ -53,6 +53,9 @@ class Sound
|
||||||
src: ["#{__dirname}/../sound/#{v.file}"]
|
src: ["#{__dirname}/../sound/#{v.file}"]
|
||||||
volume: v.volume
|
volume: v.volume
|
||||||
@sounds[k].pannerAttr
|
@sounds[k].pannerAttr
|
||||||
|
coneInnerAngle: 360
|
||||||
|
coneOuterAngle: 360
|
||||||
|
coneOuterGain: 0
|
||||||
maxDistance: 10
|
maxDistance: 10
|
||||||
refDistance: 1
|
refDistance: 1
|
||||||
rolloffFactor: 4
|
rolloffFactor: 4
|
||||||
|
@ -67,7 +70,7 @@ class Sound
|
||||||
|
|
||||||
@play: (sound, pos, time) ->
|
@play: (sound, pos, time) ->
|
||||||
pos ?= world.player?.current_position
|
pos ?= world.player?.current_position
|
||||||
# log "Sound.play #{sound} #{time}", pos
|
log "Sound.play #{sound} #{time}", pos
|
||||||
id = @sounds[sound].play()
|
id = @sounds[sound].play()
|
||||||
@sounds[sound].pos pos.x, pos.y, pos.z, id if pos?
|
@sounds[sound].pos pos.x, pos.y, pos.z, id if pos?
|
||||||
|
|
||||||
|
|
|
@ -58,17 +58,17 @@ class Wire extends Item
|
||||||
@mesh = new THREE.Mesh Geom.wire(), Material.plate
|
@mesh = new THREE.Mesh Geom.wire(), Material.plate
|
||||||
@mesh.add @wire
|
@mesh.add @wire
|
||||||
@mesh.receiveShadow = true
|
@mesh.receiveShadow = true
|
||||||
@mesh.position.copy Face.normalVectorForFace(@face).mul -(0.5+o)
|
@mesh.position.copy Face.normal(@face).mul -(0.5+o)
|
||||||
@mesh.quaternion.copy Face.orientationForFace @face
|
@mesh.quaternion.copy Face.orientation @face
|
||||||
|
|
||||||
updateActive: ->
|
updateActive: ->
|
||||||
for wire in @getNeighborWires()
|
for wire in @neighborWires()
|
||||||
@setActive true if wire.active
|
@setActive true if wire.active
|
||||||
|
|
||||||
setActive: (active) ->
|
setActive: (active) ->
|
||||||
if @active != active
|
if @active != active
|
||||||
@active = active
|
@active = active
|
||||||
neighbors = @getNeighborWires()
|
neighbors = @neighborWires()
|
||||||
|
|
||||||
active_neighbor = false
|
active_neighbor = false
|
||||||
if @active
|
if @active
|
||||||
|
@ -87,9 +87,9 @@ class Wire extends Item
|
||||||
@events[@active and @SWITCH_ON_EVENT or @SWITCH_OFF_EVENT].triggerActions()
|
@events[@active and @SWITCH_ON_EVENT or @SWITCH_OFF_EVENT].triggerActions()
|
||||||
@events[@SWITCHED_EVENT].triggerActions()
|
@events[@SWITCHED_EVENT].triggerActions()
|
||||||
|
|
||||||
getNeighborWires: ->
|
neighborWires: ->
|
||||||
wires = []
|
wires = []
|
||||||
points = @getConnectionPoints()
|
points = @connectionPoints()
|
||||||
neighbor_dirs = []
|
neighbor_dirs = []
|
||||||
|
|
||||||
rot = Face.orientationForFace @face
|
rot = Face.orientationForFace @face
|
||||||
|
@ -114,14 +114,14 @@ class Wire extends Item
|
||||||
neighbors = world.getObjectsOfTypeAtPos Wire, @position.plus neighbor_dirs[i]
|
neighbors = world.getObjectsOfTypeAtPos Wire, @position.plus neighbor_dirs[i]
|
||||||
for iter in neighbors
|
for iter in neighbors
|
||||||
continue if iter == @
|
continue if iter == @
|
||||||
neighbor_points = iter.getConnectionPoints()
|
neighbor_points = iter.connectionPoints()
|
||||||
for point in points
|
for point in points
|
||||||
for neighbor_point in neighbor_points
|
for neighbor_point in neighbor_points
|
||||||
if (neighbor_point.minus point).length() < 0.1
|
if (neighbor_point.minus point).length() < 0.1
|
||||||
wires.push iter
|
wires.push iter
|
||||||
wires
|
wires
|
||||||
|
|
||||||
getConnectionPoints: ->
|
connectionPoints: ->
|
||||||
points = []
|
points = []
|
||||||
to_border = Face.normalVectorForFace(@face).mul 0.5
|
to_border = Face.normalVectorForFace(@face).mul 0.5
|
||||||
rot = Face.orientationForFace @face
|
rot = Face.orientationForFace @face
|
||||||
|
|
|
@ -243,22 +243,8 @@ class World extends Actor
|
||||||
else if @dict.player.coordinates?
|
else if @dict.player.coordinates?
|
||||||
@addObjectAtPos @player, new Pos @dict.player.coordinates
|
@addObjectAtPos @player, new Pos @dict.player.coordinates
|
||||||
|
|
||||||
# if player_dict.nostatus?
|
|
||||||
# if player_dict.nostatus or @preview
|
|
||||||
# @player_status.hide()
|
|
||||||
# else
|
|
||||||
# @player_status.show()
|
|
||||||
# else
|
|
||||||
# if @preview
|
|
||||||
# Controller.player_status.hide()
|
|
||||||
# else
|
|
||||||
# Controller.player_status.show()
|
|
||||||
#
|
|
||||||
@getProjection().setPosition new Vector 0,0,0
|
@getProjection().setPosition new Vector 0,0,0
|
||||||
|
|
||||||
# @player.getStatus().setMinMoves (highscore.levelParMoves (@level_name))
|
|
||||||
# @player.getStatus().setMoves (0)
|
|
||||||
|
|
||||||
# ............................................................ init
|
# ............................................................ init
|
||||||
# @init() # tell the world that we are finished
|
# @init() # tell the world that we are finished
|
||||||
|
|
||||||
|
@ -301,7 +287,6 @@ class World extends Actor
|
||||||
exitLevel: (action) =>
|
exitLevel: (action) =>
|
||||||
log "world.exitLevel", action
|
log "world.exitLevel", action
|
||||||
@finish()
|
@finish()
|
||||||
# @player.status.setMoves 0
|
|
||||||
# exitIndex = parseInt action.name?.slice 5
|
# exitIndex = parseInt action.name?.slice 5
|
||||||
# log "world.exitLevel exitIndex:#{exitIndex}"
|
# log "world.exitLevel exitIndex:#{exitIndex}"
|
||||||
# if @dict.exits[exitIndex]?.world?
|
# if @dict.exits[exitIndex]?.world?
|
||||||
|
@ -311,10 +296,7 @@ class World extends Actor
|
||||||
log "world.level_index #{world.level_index} nextLevel #{World.levels.list[world.level_index+1]}"
|
log "world.level_index #{world.level_index} nextLevel #{World.levels.list[world.level_index+1]}"
|
||||||
world.create World.levels.list[world.level_index+1]
|
world.create World.levels.list[world.level_index+1]
|
||||||
|
|
||||||
activate: (objectName) ->
|
activate: (objectName) -> @getObjectWithName(objectName)?.setActive? true
|
||||||
# activates object with name objectName
|
|
||||||
object = @getObjectWithName objectName
|
|
||||||
object?.setActive? 1
|
|
||||||
|
|
||||||
decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2
|
decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2
|
||||||
|
|
||||||
|
@ -493,7 +475,6 @@ class World extends Actor
|
||||||
|
|
||||||
moveObjectToPos: (object, pos) ->
|
moveObjectToPos: (object, pos) ->
|
||||||
return false if @isInvalidPos(pos) or @isOccupiedPos(pos)
|
return false if @isInvalidPos(pos) or @isOccupiedPos(pos)
|
||||||
|
|
||||||
@unsetObject object
|
@unsetObject object
|
||||||
@setObjectAtPos object, pos
|
@setObjectAtPos object, pos
|
||||||
world.playSound 'BOT_LAND'
|
world.playSound 'BOT_LAND'
|
||||||
|
@ -517,7 +498,6 @@ class World extends Actor
|
||||||
object.del()
|
object.del()
|
||||||
|
|
||||||
deleteAllObjects: () ->
|
deleteAllObjects: () ->
|
||||||
# log 'world.deleteAllObjects'
|
|
||||||
Timer.removeAllActions()
|
Timer.removeAllActions()
|
||||||
|
|
||||||
if @player?
|
if @player?
|
||||||
|
@ -551,10 +531,7 @@ class World extends Actor
|
||||||
|
|
||||||
setCameraMode: (mode) -> @camera_mode = clamp World.CAMERA_INSIDE, World.CAMERA_FOLLOW, mode
|
setCameraMode: (mode) -> @camera_mode = clamp World.CAMERA_INSIDE, World.CAMERA_FOLLOW, mode
|
||||||
|
|
||||||
changeCameraMode: () ->
|
changeCameraMode: -> @camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
||||||
@camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
|
||||||
# log "world.changeCameraMode #{@camera_mode}"
|
|
||||||
@camera_mode
|
|
||||||
|
|
||||||
# 0000000 0000000 000 00 00 0000000 000 000 00000000
|
# 0000000 0000000 000 00 00 0000000 000 000 00000000
|
||||||
# 000 000 000 000 000 000 000 000 000 000 000 000
|
# 000 000 000 000 000 000 000 000 000 000 000 000
|
||||||
|
@ -766,7 +743,6 @@ class World extends Actor
|
||||||
if o instanceof Light
|
if o instanceof Light
|
||||||
o.initialize()
|
o.initialize()
|
||||||
|
|
||||||
# Spikes::initialize()
|
|
||||||
# Text::reinit()
|
# Text::reinit()
|
||||||
|
|
||||||
# 000 000 00000000 000 00000000
|
# 000 000 00000000 000 00000000
|
||||||
|
|
Loading…
Reference in New Issue
Block a user