cage
This commit is contained in:
parent
a8b4438c58
commit
30f8389a2c
|
@ -60,8 +60,13 @@ class Action
|
|||
if @object? then @object.removeAction @
|
||||
@deleted = true
|
||||
|
||||
perform: () ->
|
||||
if @object.performAction?
|
||||
@object.performAction @
|
||||
else if _.isFunction @object
|
||||
@object()
|
||||
|
||||
init: () -> @object.initAction? @
|
||||
perform: () -> @object.performAction? @
|
||||
finish: () -> @object.finishAction? @
|
||||
finished: () ->
|
||||
# log "Action.finished #{@name} #{@object?.actionFinished?}"
|
||||
|
|
|
@ -96,7 +96,7 @@ class Actor extends Emitter
|
|||
|
||||
startTimedAction: (action, duration) ->
|
||||
action.duration = duration if duration >= 0
|
||||
# log "Actor.startTimedAction #{action.name} duration: #{duration}"
|
||||
# log "Actor.startTimedAction #{action.name} duration: #{action.duration}"
|
||||
Timer.addAction action
|
||||
|
||||
module.exports = Actor
|
||||
|
|
|
@ -4,34 +4,36 @@
|
|||
# 000 000 000 000 000 000
|
||||
# 0000000 000 000 0000000 00000000
|
||||
|
||||
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||
|
||||
class Cage
|
||||
|
||||
constructor: (@size, @gap) ->
|
||||
|
||||
cageMat = new THREE.MeshPhongMaterial
|
||||
color: 0x880000
|
||||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 10
|
||||
emissive: 0x880000
|
||||
emissiveIntensity: 0.02
|
||||
|
||||
rasterMat = new THREE.MeshPhongMaterial
|
||||
color: 0x880000
|
||||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 20
|
||||
@cageMat = new THREE.MeshPhongMaterial
|
||||
color: 0x880000
|
||||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 10
|
||||
emissive: 0x880000
|
||||
emissiveIntensity: 0.02
|
||||
|
||||
geom = @wallTiles 0
|
||||
@raster = new THREE.Mesh geom, rasterMat
|
||||
@rasterMat = new THREE.MeshPhongMaterial
|
||||
color: 0x880000
|
||||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
shininess: 20
|
||||
|
||||
constructor: (@size, gap) ->
|
||||
Cage.gap = gap
|
||||
geom = Cage.wallTiles @size, 'inside', 0
|
||||
@raster = new THREE.Mesh geom, Cage.rasterMat
|
||||
@raster.translateX -0.5
|
||||
@raster.translateY -0.5
|
||||
@raster.translateZ -0.5
|
||||
@raster.receiveShadow = true
|
||||
world.scene.add @raster
|
||||
|
||||
geom = @wallTiles @gap
|
||||
@cage = new THREE.Mesh geom, cageMat
|
||||
geom = Cage.wallTiles @size, 'inside', Cage.gap
|
||||
@cage = new THREE.Mesh geom, Cage.cageMat
|
||||
@cage.translateX -0.5
|
||||
@cage.translateY -0.5
|
||||
@cage.translateZ -0.5
|
||||
|
@ -42,156 +44,154 @@ class Cage
|
|||
world.scene.remove @raster
|
||||
world.scene.remove @cage
|
||||
|
||||
wallTiles: (raster=0) ->
|
||||
|
||||
faces = @size.x * @size.y * 2 + @size.x * @size.z * 2 + @size.y * @size.z * 2
|
||||
triangles = faces * 2
|
||||
@wallTiles: (size, side, raster=Cage.gap) ->
|
||||
|
||||
faces = size.x * size.y * 2 + size.x * size.z * 2 + size.y * size.z * 2
|
||||
triangles = faces * 2
|
||||
|
||||
positions = new Float32Array triangles * 3 * 3
|
||||
normals = new Float32Array triangles * 3 * 3
|
||||
|
||||
s = 1-raster
|
||||
o = raster
|
||||
i = -1
|
||||
offset = raster/20
|
||||
offset = (side == 'outside' and -1 or 1) * raster/20
|
||||
|
||||
z = offset
|
||||
n = 1
|
||||
for x in [0...@size.x]
|
||||
for y in [0...@size.y]
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
xyPlate = (x, y, z) ->
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = 1
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = 1
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = 1
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = 1
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = 1
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = 1
|
||||
|
||||
z = @size.z - offset
|
||||
n = -1
|
||||
for x in [0...@size.x]
|
||||
for y in [0...@size.y]
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = n
|
||||
yxPlate = (x, y, z) ->
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = -1
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = -1
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = -1
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = -1
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = -1
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z ; normals[i] = -1
|
||||
|
||||
y = offset
|
||||
n = 1
|
||||
for x in [0...@size.x]
|
||||
for z in [0...@size.z]
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
zxPlate = (x, y, z) ->
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = 1
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = 1
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = 1
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = 1
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = 1
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = 1
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
|
||||
y = @size.y - offset
|
||||
n = -1
|
||||
for x in [0...@size.x]
|
||||
for z in [0...@size.z]
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = n
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
xzPlate = (x, y, z) ->
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = -1
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = -1
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = -1
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = -1
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+o; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = -1
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x+s; normals[i] = 0
|
||||
positions[i+=1] = y ; normals[i] = -1
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
|
||||
x = offset
|
||||
n = 1
|
||||
for y in [0...@size.y]
|
||||
for z in [0...@size.z]
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
yzPlate = (x, y, z) ->
|
||||
positions[i+=1] = x ; normals[i] = 1
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = 1
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = 1
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = 1
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = 1
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = 1
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
|
||||
x = @size.x-offset
|
||||
n = -1
|
||||
for y in [0...@size.y]
|
||||
for z in [0...@size.z]
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = n
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
zyPlate = (x, y, z) ->
|
||||
positions[i+=1] = x ; normals[i] = -1
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = -1
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = -1
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = -1
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+o; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = -1
|
||||
positions[i+=1] = y+o; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
positions[i+=1] = x ; normals[i] = -1
|
||||
positions[i+=1] = y+s; normals[i] = 0
|
||||
positions[i+=1] = z+s; normals[i] = 0
|
||||
|
||||
plates = side == 'outside' and [yxPlate, xyPlate, xzPlate, zxPlate, zyPlate, yzPlate] or [xyPlate, yxPlate, zxPlate, xzPlate, yzPlate, zyPlate]
|
||||
for x in [0...size.x]
|
||||
for y in [0...size.y]
|
||||
plates[0] x, y, offset
|
||||
plates[1] x, y, size.z - offset
|
||||
|
||||
for x in [0...size.x]
|
||||
for z in [0...size.z]
|
||||
plates[2] x, offset, z
|
||||
plates[3] x, size.y - offset, z
|
||||
|
||||
for y in [0...size.y]
|
||||
for z in [0...size.z]
|
||||
plates[4] offset, y, z
|
||||
plates[5] size.x-offset, y, z
|
||||
|
||||
geom = new THREE.BufferGeometry
|
||||
geom.addAttribute 'position', new THREE.BufferAttribute positions, 3
|
||||
|
|
|
@ -58,11 +58,11 @@ class Event
|
|||
triggerActions: () ->
|
||||
return if not @actions.length
|
||||
@time = world.getTime()
|
||||
# log 'trigger actions', @time, @actions.length
|
||||
# log "trigger actions #{@name}", @actions.length
|
||||
@save_actions = _.clone @actions
|
||||
while @save_actions.length
|
||||
action = last @save_actions
|
||||
# log "performAction #{action.name}" if action.name != 'noop'
|
||||
# log "event.performAction #{action.name}" if action.name != 'noop'
|
||||
action.performWithEvent @
|
||||
if @save_actions.length and action == last @save_actions
|
||||
@save_actions.pop()
|
||||
|
|
|
@ -8,6 +8,7 @@ log = require "/Users/kodi/s/ko/js/tools/log"
|
|||
|
||||
Vector = require './lib/vector'
|
||||
Switch = require './switch'
|
||||
Light = require './light'
|
||||
Action = require './action'
|
||||
|
||||
class Gate extends Switch
|
||||
|
@ -21,7 +22,13 @@ class Gate extends Switch
|
|||
@getActionWithId(Action.ROTATE).duration = 3000
|
||||
@sound_on = 'GATE_OPEN'
|
||||
@sound_off = 'GATE_CLOSE'
|
||||
|
||||
|
||||
createLight: ->
|
||||
@light = new Light
|
||||
pos: @position
|
||||
radius: 12.0
|
||||
shadow: true
|
||||
|
||||
createMesh: () ->
|
||||
torusRadius = 0.05
|
||||
t1 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32
|
||||
|
|
|
@ -17,12 +17,17 @@ class Levels
|
|||
# easy
|
||||
# "gold",
|
||||
# "jump",
|
||||
"escape", "gears",
|
||||
# "escape",
|
||||
# "gears",
|
||||
# "gamma",
|
||||
"cube", "switch", "borg",
|
||||
# "cube",
|
||||
# "switch",
|
||||
# "borg",
|
||||
"mini",
|
||||
# "blocks",
|
||||
"bombs", "sandbox", "energy", "maze", "love",
|
||||
# "bombs",
|
||||
"sandbox",
|
||||
"energy", "maze", "love",
|
||||
# medium
|
||||
"towers", "edge", "random", "plate", "nice", "entropy",
|
||||
# owen hay's levels (TODO: sort in)
|
||||
|
|
|
@ -65,7 +65,7 @@ module.exports =
|
|||
world.switch_counter = 0
|
||||
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
world.switch_counter += swtch.active and 1 or -1
|
||||
exit = kikiObjectToGate(world.getObjectWithName("exit"))
|
||||
exit.setActive(world.switch_counter == 4)
|
||||
|
||||
|
|
|
@ -27,4 +27,4 @@ module.exports =
|
|||
for j in [0...5]
|
||||
for l in [0...5]
|
||||
if Math.pow(-1, i+j+l) == -1
|
||||
world.addObjectAtPos('KikiStone', KikiPos(i,j,l))
|
||||
world.addObjectAtPos 'KikiStone', i,j,l
|
||||
|
|
|
@ -67,7 +67,7 @@ module.exports =
|
|||
world.switch_counter = 0
|
||||
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
world.switch_counter += swtch.active and 1 or -1
|
||||
exit = kikiObjectToGate (world.getObjectWithName("exit"))
|
||||
exit.setActive(world.switch_counter == 4)
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports =
|
|||
s = world.size
|
||||
Switch = require '../switch'
|
||||
exit_switch = new Switch()
|
||||
exit_switch.getEventWithName("switched").addAction world.continuous () -> world.toggle "exit"
|
||||
exit_switch.getEventWithName("switched").addAction world.continuous -> world.toggle "exit"
|
||||
world.addObjectAtPos exit_switch, world.decenter 0, -2, 0
|
||||
|
||||
world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2, 0
|
||||
|
@ -39,10 +39,10 @@ module.exports =
|
|||
world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2,-1
|
||||
world.addObjectAtPos 'KikiStone', world.decenter -1, s.y/2, 0
|
||||
|
||||
# world.addObjectLine 'KikiStone', world.decenter(-2, s.y/2,-2), world.decenter( 2, s.y/2,-2)
|
||||
# world.addObjectLine 'KikiStone', world.decenter( 2, s.y/2,-2), world.decenter( 2, s.y/2, 2)
|
||||
# world.addObjectLine 'KikiStone', world.decenter( 2, s.y/2, 2), world.decenter(-2, s.y/2, 2)
|
||||
# world.addObjectLine 'KikiStone', world.decenter(-2, s.y/2, 2), world.decenter(-2, s.y/2,-2)
|
||||
world.addObjectLine 'KikiStone', world.decenter(-2, s.y/2,-2), world.decenter( 2, s.y/2,-2)
|
||||
world.addObjectLine 'KikiStone', world.decenter( 2, s.y/2,-2), world.decenter( 2, s.y/2, 2)
|
||||
world.addObjectLine 'KikiStone', world.decenter( 2, s.y/2, 2), world.decenter(-2, s.y/2, 2)
|
||||
world.addObjectLine 'KikiStone', world.decenter(-2, s.y/2, 2), world.decenter(-2, s.y/2,-2)
|
||||
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 1, 0, 0
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 0, 0, 1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# level design by Michael Abel
|
||||
|
||||
schemes=[test_scheme, tron_scheme,candy_scheme, default_scheme,
|
||||
green_scheme, yellow_scheme, blue_scheme, red_scheme, metal_scheme, bronze_scheme]
|
||||
# schemes=[test_scheme, tron_scheme,candy_scheme, default_scheme,
|
||||
# green_scheme, yellow_scheme, blue_scheme, red_scheme, metal_scheme, bronze_scheme]
|
||||
|
||||
module.exports =
|
||||
name: "gamma"
|
||||
|
@ -28,21 +28,21 @@ module.exports =
|
|||
world.switch_counter = 0
|
||||
|
||||
aswitched = () ->
|
||||
applyColorScheme (schemes[world.switch_countera])
|
||||
# applyColorScheme(schemes[world.switch_countera])
|
||||
if world.switch_countera==schemes.length-1
|
||||
world.switch_countera=0
|
||||
else
|
||||
world.switch_countera+=1
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
world.switch_counter += swtch.active and 1 or -1
|
||||
exit = kikiObjectToGate(world.getObjectWithName("exit"))
|
||||
exit.setActive(world.switch_counter == 4)
|
||||
|
||||
aswitch = KikiSwitch()
|
||||
bswitch = KikiSwitch()
|
||||
cswitch = KikiSwitch()
|
||||
dswitch = KikiSwitch()
|
||||
eswitch = KikiSwitch()
|
||||
aswitch = new Switch()
|
||||
bswitch = new Switch()
|
||||
cswitch = new Switch()
|
||||
dswitch = new Switch()
|
||||
eswitch = new Switch()
|
||||
|
||||
aswitch.getEventWithName("switched").addAction(continuous(aswitched))
|
||||
bswitch.getEventWithName("switched").addAction(continuous((s=bswitch) -> switched(s)))
|
||||
|
|
|
@ -64,7 +64,7 @@ module.exports =
|
|||
world.switch_counter = 0
|
||||
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
world.switch_counter += swtch.active and 1 or -1
|
||||
exit = kikiObjectToGate(world.getObjectWithName("exit"))
|
||||
exit.setActive(world.switch_counter == 5)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports =
|
|||
s = world.size
|
||||
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
world.switch_counter += swtch.active and 1 or -1
|
||||
exit = kikiObjectToGate(world.getObjectWithName("exit"))
|
||||
exit.setActive(world.switch_counter == 5)
|
||||
|
||||
|
|
|
@ -16,20 +16,20 @@ module.exports =
|
|||
position: [0,0,1]
|
||||
]
|
||||
create: ->
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(1,1,0))
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(3,1,0))
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(1,3,0))
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(3,3,0))
|
||||
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(1,1,6))
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(3,1,6))
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(1,3,6))
|
||||
world.addObjectAtPos( 'KikiWall', KikiPos(3,3,6))
|
||||
|
||||
world.addObjectAtPos( 'KikiStone', KikiPos(1,1,1))
|
||||
world.addObjectAtPos( 'KikiStone', KikiPos(3,1,1))
|
||||
world.addObjectAtPos( 'KikiStone', KikiPos(1,3,1))
|
||||
world.addObjectAtPos( 'KikiStone', KikiPos(3,3,1))
|
||||
|
||||
world.addObjectAtPos( 'KikiStone', KikiPos(2,4,0))
|
||||
world.addObjectAtPos 'KikiWall', 1,1,0
|
||||
world.addObjectAtPos 'KikiWall', 3,1,0
|
||||
world.addObjectAtPos 'KikiWall', 1,3,0
|
||||
world.addObjectAtPos 'KikiWall', 3,3,0
|
||||
|
||||
world.addObjectAtPos 'KikiWall', 1,1,6
|
||||
world.addObjectAtPos 'KikiWall', 3,1,6
|
||||
world.addObjectAtPos 'KikiWall', 1,3,6
|
||||
world.addObjectAtPos 'KikiWall', 3,3,6
|
||||
|
||||
world.addObjectAtPos 'KikiStone', 1,1,1
|
||||
world.addObjectAtPos 'KikiStone', 3,1,1
|
||||
world.addObjectAtPos 'KikiStone', 1,3,1
|
||||
world.addObjectAtPos 'KikiStone', 3,3,1
|
||||
|
||||
world.addObjectAtPos 'KikiStone', 2,4,0
|
||||
|
|
@ -34,53 +34,54 @@ module.exports =
|
|||
h = 0
|
||||
# bomb and stones
|
||||
|
||||
world.addObjectAtPos(KikiStone(), KikiPos(s.x/2, s.y/2, s.z/2))
|
||||
world.addObjectAtPos(KikiStone(), KikiPos(s.x/2, s.y-2, s.z/2))
|
||||
world.addObjectAtPos 'KikiStone', s.x/2, s.y/2, s.z/2
|
||||
world.addObjectAtPos 'KikiStone', s.x/2, s.y-2, s.z/2
|
||||
|
||||
world.addObjectAtPos(KikiBomb(), KikiPos(s.x/2, 1, s.z/2))
|
||||
# world.addObjectAtPos 'KikiBomb', s.x/2, 1, s.z/2
|
||||
|
||||
# stone frames for switches
|
||||
|
||||
world.addObjectAtPos(KikiWall(), world.decenter( 0, h-1, s.z/2))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter( 0, h+1, s.z/2))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter( 1, h, s.z/2))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(-1, h, s.z/2))
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 0, h-1, s.z/2
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 0, h+1, s.z/2
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 1, h, s.z/2
|
||||
world.addObjectAtPos 'KikiWall', world.decenter -1, h, s.z/2
|
||||
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(s.x/2, h-1, 0))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(s.x/2, h+1, 0))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(s.x/2, h, 1))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(s.x/2, h, -1))
|
||||
world.addObjectAtPos 'KikiWall', world.decenter s.x/2, h-1, 0
|
||||
world.addObjectAtPos 'KikiWall', world.decenter s.x/2, h+1, 0
|
||||
world.addObjectAtPos 'KikiWall', world.decenter s.x/2, h, 1
|
||||
world.addObjectAtPos 'KikiWall', world.decenter s.x/2, h, -1
|
||||
|
||||
world.addObjectAtPos(KikiWall(), world.decenter( 0, h-1, -s.z/2+1))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter( 0, h+1, -s.z/2+1))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter( 1, h, -s.z/2+1))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(-1, h, -s.z/2+1))
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 0, h-1, -s.z/2+1
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 0, h+1, -s.z/2+1
|
||||
world.addObjectAtPos 'KikiWall', world.decenter 1, h, -s.z/2+1
|
||||
world.addObjectAtPos 'KikiWall', world.decenter -1, h, -s.z/2+1
|
||||
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(-s.x/2+1, h-1, 0))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(-s.x/2+1, h+1, 0))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(-s.x/2+1, h, 1))
|
||||
world.addObjectAtPos(KikiWall(), world.decenter(-s.x/2+1, h, -1))
|
||||
world.addObjectAtPos 'KikiWall', world.decenter -s.x/2+1, h-1, 0
|
||||
world.addObjectAtPos 'KikiWall', world.decenter -s.x/2+1, h+1, 0
|
||||
world.addObjectAtPos 'KikiWall', world.decenter -s.x/2+1, h, 1
|
||||
world.addObjectAtPos 'KikiWall', world.decenter -s.x/2+1, h, -1
|
||||
|
||||
# switches
|
||||
|
||||
world.switch_counter = 0
|
||||
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
exit = kikiObjectToGate(world.getObjectWithName("exit"))
|
||||
exit.setActive(world.switch_counter == 4)
|
||||
world.switch_counter += swtch.active and 1 or -1
|
||||
exit = world.getObjectWithName "exit"
|
||||
exit.setActive world.switch_counter == 4
|
||||
|
||||
switch1 = KikiSwitch()
|
||||
switch1.getEventWithName("switched").addAction(continuous((s=switch1) -> switched(s)))
|
||||
switch2 = KikiSwitch()
|
||||
switch2.getEventWithName("switched").addAction(continuous((s=switch2) -> switched(s)))
|
||||
switch3 = KikiSwitch()
|
||||
switch3.getEventWithName("switched").addAction(continuous((s=switch3) -> switched(s)))
|
||||
switch4 = KikiSwitch()
|
||||
switch4.getEventWithName("switched").addAction(continuous((s=switch4) -> switched(s)))
|
||||
Switch = require '../switch'
|
||||
switch1 = new Switch()
|
||||
switch1.getEventWithName("switched").addAction(world.continuous((s=switch1) -> switched(s)))
|
||||
switch2 = new Switch()
|
||||
switch2.getEventWithName("switched").addAction(world.continuous((s=switch2) -> switched(s)))
|
||||
switch3 = new Switch()
|
||||
switch3.getEventWithName("switched").addAction(world.continuous((s=switch3) -> switched(s)))
|
||||
switch4 = new Switch()
|
||||
switch4.getEventWithName("switched").addAction(world.continuous((s=switch4) -> switched(s)))
|
||||
|
||||
world.addObjectAtPos(switch1, world.decenter(-s.x/2+1, 0, 0))
|
||||
world.addObjectAtPos(switch2, world.decenter( s.x/2, 0, 0))
|
||||
world.addObjectAtPos(switch3, world.decenter(0, 0, -s.z/2+1))
|
||||
world.addObjectAtPos(switch4, world.decenter(0, 0, s.z/2))
|
||||
world.addObjectAtPos switch1, world.decenter -s.x/2+1, 0, 0
|
||||
world.addObjectAtPos switch2, world.decenter s.x/2, 0, 0
|
||||
world.addObjectAtPos switch3, world.decenter 0, 0, -s.z/2+1
|
||||
world.addObjectAtPos switch4, world.decenter 0, 0, s.z/2
|
||||
|
|
@ -8,14 +8,15 @@ Item = require './item'
|
|||
|
||||
class Light extends Item
|
||||
|
||||
constructor: (pos, radius) ->
|
||||
@radius = radius ? 4
|
||||
@intensity = 1
|
||||
constructor: (opt) ->
|
||||
@radius = opt?.radius ? 4
|
||||
@shadow = opt?.shadow ? false
|
||||
@intensity = opt?.intensity ? 0.5
|
||||
# @ambient_color = colors[KikiLight_base_color]
|
||||
# @diffuse_color = colors[KikiLight_diffuse_color]
|
||||
# @specular_color = colors[KikiLight_specular_color]
|
||||
@point = new THREE.PointLight 0xffffff, @intensity, @radius, 2
|
||||
@point.castShadow = true
|
||||
@point.castShadow = @shadow
|
||||
@point.shadow.darkness = 0.5
|
||||
@point.shadow.mapSize = new THREE.Vector2 2048, 2048
|
||||
@point.shadow.bias = 0.01
|
||||
|
@ -32,7 +33,7 @@ class Light extends Item
|
|||
@mesh = new THREE.Mesh geom, mat
|
||||
world.scene.add @point
|
||||
world.addLight @
|
||||
@setPosition pos if pos?
|
||||
@setPosition opt.pos if opt?.pos?
|
||||
super
|
||||
|
||||
del: ->
|
||||
|
|
|
@ -10,15 +10,16 @@ class Stone extends Pushable
|
|||
|
||||
constructor: (@slippery=false) ->
|
||||
|
||||
@geom = new THREE.BoxGeometry 0.99,0.99,0.99
|
||||
@geom = new THREE.BoxGeometry 0.98,0.98,0.98
|
||||
# @geom.translate 0.01, 0.01, 0.01
|
||||
|
||||
@mat = new THREE.MeshPhongMaterial
|
||||
color: 0xff8800
|
||||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
side: THREE.DoubleSide
|
||||
shading: THREE.FlatShading
|
||||
transparent: true
|
||||
opacity: 0.58
|
||||
shininess: 0.9
|
||||
opacity: 0.8
|
||||
shininess: 15
|
||||
|
||||
@mesh = new THREE.Mesh @geom, @mat
|
||||
super
|
||||
|
|
|
@ -62,10 +62,16 @@ class Switch extends Item
|
|||
bulletImpact: -> @setActive not @active
|
||||
|
||||
lightDeleted: () -> @light = null
|
||||
createLight: ->
|
||||
@light = new Light
|
||||
pos: @position
|
||||
radius: 6.0
|
||||
|
||||
toggle: -> @setActive not @active
|
||||
|
||||
setActive: (status) ->
|
||||
log "switch #{@name} active:#{status}"
|
||||
if @active != status
|
||||
log "switch #{@name} active:#{status}"
|
||||
@active = status
|
||||
|
||||
if @active
|
||||
|
@ -73,7 +79,7 @@ class Switch extends Item
|
|||
@startTimedAction @getActionWithId Action.ROTATE
|
||||
world.playSound @sound_on
|
||||
@events[@SWITCH_ON_EVENT].triggerActions()
|
||||
@light = new Light @position, 10.0
|
||||
@createLight()
|
||||
@light.on 'deleted', @lightDeleted
|
||||
else
|
||||
@stopAction @getActionWithId Action.ROTATE
|
||||
|
@ -84,7 +90,7 @@ class Switch extends Item
|
|||
if @light
|
||||
@light.del()
|
||||
@light = null
|
||||
|
||||
log 'trigger SWITCHED_EVENT'
|
||||
@events[@SWITCHED_EVENT].triggerActions()
|
||||
|
||||
setPosition: (pos) ->
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
# 000 000 000 000 000 000
|
||||
# 00 00 000 000 0000000 0000000
|
||||
|
||||
Pos = require './lib/pos'
|
||||
Item = require './item'
|
||||
Cage = require './cage'
|
||||
|
||||
class Wall extends Item
|
||||
|
||||
|
@ -13,32 +15,20 @@ class Wall extends Item
|
|||
|
||||
constructor: ->
|
||||
|
||||
@geom = new THREE.BoxGeometry 1,1,1
|
||||
@mat = new THREE.MeshPhongMaterial
|
||||
color: 0x0000ff
|
||||
side: THREE.FrontSide
|
||||
shading: THREE.SmoothShading
|
||||
transparent: true
|
||||
opacity: 0.85
|
||||
shininess: 5
|
||||
@mesh = new THREE.Mesh @geom, @mat
|
||||
@mesh.castShadow = true
|
||||
@mesh.receiveShadow = true
|
||||
geom = Cage.wallTiles new Pos(1,1,1), 'outside', 0
|
||||
geom.translate -0.5, -0.5, -0.5
|
||||
@raster = new THREE.Mesh geom, Cage.rasterMat
|
||||
@raster.receiveShadow = true
|
||||
|
||||
geom = Cage.wallTiles new Pos(1,1,1), 'outside', Cage.gap
|
||||
geom.translate -0.5, -0.5, -0.5
|
||||
@plates = new THREE.Mesh geom, Cage.cageMat
|
||||
@plates.receiveShadow = true
|
||||
|
||||
@mesh = new THREE.Object3D
|
||||
@mesh.add @raster
|
||||
@mesh.add @plates
|
||||
|
||||
super
|
||||
|
||||
# s = 0.45
|
||||
# d = 0.5
|
||||
|
||||
# glDisable(GL_LIGHTING);
|
||||
# colors[KikiWall_base_color].glColor();
|
||||
# glDepthMask(false);
|
||||
# kDisplaySolidCube(1.0);
|
||||
# glDepthMask(true);
|
||||
|
||||
# colors[KikiWall_plate_color].glColor();
|
||||
# glEnable(GL_LIGHTING);
|
||||
# glBegin(GL_QUADS);
|
||||
#
|
||||
# glEnd();
|
||||
|
||||
module.exports = Wall
|
||||
module.exports = Wall
|
||||
|
|
|
@ -76,9 +76,9 @@ class World extends Actor
|
|||
# 000 000 000 000 0 000 000 000 000 000 000
|
||||
# 0000000 000 000 000 000 00000000 000 000 000 000
|
||||
|
||||
@fov = 70
|
||||
@near = 0.001
|
||||
@far = 500
|
||||
@fov = 90
|
||||
@near = 0.1
|
||||
@far = 20
|
||||
@aspect = @view.offsetWidth / @view.offsetHeight
|
||||
@dist = 10
|
||||
|
||||
|
@ -279,11 +279,13 @@ class World extends Actor
|
|||
|
||||
addLight: (light) ->
|
||||
@lights.push light
|
||||
@enableShadows true
|
||||
@enableShadows true if light.shadow
|
||||
|
||||
removeLight: (light) ->
|
||||
_.pull @lights, light
|
||||
@enableShadows false if not @lights.length
|
||||
for l in @lights
|
||||
shadow = true if l.shadow
|
||||
@enableShadows shadow
|
||||
|
||||
enableShadows: (enable) ->
|
||||
@renderer.shadowMap.enabled = enable
|
||||
|
@ -298,8 +300,8 @@ class World extends Actor
|
|||
log "world.exitLevel", action
|
||||
@finish()
|
||||
# @player.status.setMoves 0
|
||||
exitIndex = parseInt action.name.slice 5
|
||||
log "world.exitLevel exitIndex:#{exitIndex}"
|
||||
# exitIndex = parseInt action.name?.slice 5
|
||||
# log "world.exitLevel exitIndex:#{exitIndex}"
|
||||
# if @dict.exits[exitIndex]?.world?
|
||||
# w = @dict.exits[exitIndex].world
|
||||
# w() if _.isFunction w
|
||||
|
@ -320,158 +322,6 @@ class World extends Actor
|
|||
|
||||
isInvalidPos: (pos) -> not @isValidPos pos
|
||||
|
||||
# 0000000 0000000 000 00000000 0000000 000000000 000 000 000 000 00000000
|
||||
# 000 000 000 000 000 000 000 000 000 000 0000 000 000
|
||||
# 000 000 0000000 000 0000000 000 000 000 000 000 0 000 0000000
|
||||
# 000 000 000 000 000 000 000 000 000 000 000 000 0000 000
|
||||
# 0000000 0000000 0000000 00000000 0000000 000 0000000 000 000 000 00000000
|
||||
|
||||
addObjectLine: (object, sx,sy,sz, ex,ey,ez) ->
|
||||
if sx instanceof Pos
|
||||
start = sx
|
||||
end = sy
|
||||
else
|
||||
start = new Pos sx,sy,sz
|
||||
end = new Pos ex,ey,ez
|
||||
# adds a line of objects of type to the world. start and end should be 3-tuples or Pos objects
|
||||
if start instanceof Pos
|
||||
start = [start.x, start.y, start.z]
|
||||
[sx, sy, sz] = start
|
||||
if end instanceof Pos
|
||||
end = [end.x, end.y, end.z]
|
||||
[ex, ey, ez] = end
|
||||
|
||||
diff = [ex-sx, ey-sy, ez-sz]
|
||||
maxdiff = _.max diff.map Math.abs
|
||||
deltas = diff.map (a) -> a/maxdiff
|
||||
for i in [0...maxdiff]
|
||||
# pos = apply(Pos, (map (lambda a, b: int(a+i*b), start, deltas)))
|
||||
pos = new Pos (start[j]+i*deltas[j] for j in [0..2])
|
||||
if @isUnoccupiedPos pos
|
||||
if type(object) == types.StringType
|
||||
@addObjectAtPos eval(object), pos
|
||||
else
|
||||
@addObjectAtPos object(), pos
|
||||
|
||||
addObjectPoly: (object, points, close=1) ->
|
||||
# adds a polygon of objects of type to the world. points should be 3-tuples or Pos objects
|
||||
if close
|
||||
points.append (points[0])
|
||||
for index in range(1, len(points))
|
||||
@addObjectLine object, points[index-1], points[index]
|
||||
|
||||
addObjectRandom: (object, number) ->
|
||||
# adds number objects of type at random positions to the world
|
||||
for i in [0...number]
|
||||
if type (object) == types.StringType
|
||||
@setObjectRandom eval object
|
||||
else
|
||||
@setObjectRandom object()
|
||||
|
||||
setObjectRandom: (object) ->
|
||||
# adds number objects of type at random positions to the world
|
||||
object_set = 0
|
||||
while not object_set # hack alert!
|
||||
random_pos = Pos random.randrange(@size.x),
|
||||
random.randrange(@size.y),
|
||||
random.randrange(@size.z)
|
||||
if not object.isSpaceEgoistic() or @isUnoccupiedPos(random_pos)
|
||||
@addObjectAtPos object, random_pos
|
||||
object_set = 1
|
||||
|
||||
# 000 000 00000000 000 00000000
|
||||
# 000 000 000 000 000 000
|
||||
# 000000000 0000000 000 00000000
|
||||
# 000 000 000 000 000
|
||||
# 000 000 00000000 0000000 000
|
||||
|
||||
help: (index=0) ->
|
||||
# displays help messages
|
||||
|
||||
# text_list = @dict["help"]
|
||||
# more_text = index < len (text_list) - 1
|
||||
# less_text = index > 0
|
||||
#
|
||||
# list = text_list[index].split("$key(")
|
||||
# for i in range (1, len(list))
|
||||
# close = list[i].find(")")
|
||||
# list[i] = Controller.player.getKeyForAction (list[i][:close]) + list[i][close+1:]
|
||||
#
|
||||
# list.append ("\n\n$scale(0.5)(%d/%d)" % (index+1, len (text_list)))
|
||||
# help_text = KikiPageText ("".join(list), more_text, less_text)
|
||||
#
|
||||
# if more_text:
|
||||
# help_text.getEventWithName ("next").addAction (once (lambda i=index+1: @help (i)))
|
||||
# if less_text:
|
||||
# help_text.getEventWithName ("previous").addAction (once (lambda i=index-1: @help (i)))
|
||||
|
||||
outro: (index=0) ->
|
||||
# well hidden outro :-)
|
||||
outro_text = """
|
||||
$scale(1.5)congratulations!\n\n$scale(1)you rescued\nthe nano world!
|
||||
|
||||
the last dumb mutant bot\nhas been destroyed.\n\nthe maker is functioning again.
|
||||
kiki will go now\nand see all his new friends.\n\nyou should maybe\ndo the same?
|
||||
the maker wants to thank you!\n\n(btw.: you thought\nyou didn't see\nkiki's maker in the game?
|
||||
you are wrong!\nyou saw him\nall the time,\nbecause kiki\nlives inside him!)\n\n$scale(1.5)the end
|
||||
p.s.: the maker of the game\nwants to thank you as well!\n\ni definitely want your feedback:
|
||||
please send me a mail (monsterkodi@users.sf.net)\nwith your experiences,
|
||||
which levels you liked, etc.\n\nthanks in advance and have a nice day,\n\nyours kodi
|
||||
"""
|
||||
|
||||
more_text = index < outro_text.length-1
|
||||
less_text = index > 0
|
||||
|
||||
page_text = outro_text[index]
|
||||
page_text += "\n\n$scale(0.5)(#{index+1}/#{outro_text.length})"
|
||||
|
||||
page = KikiPageText(page_text, more_text, less_text)
|
||||
page.getEventWithName("hide").addAction(once(display_main_menu))
|
||||
|
||||
if more_text
|
||||
page.getEventWithName("next").addAction (i=index+1) => @outro i
|
||||
if less_text
|
||||
page.getEventWithName("previous").addAction (i=index-1) => @outro i
|
||||
|
||||
resetProjection: -> world.getProjection().setViewport 0.0, 0.0, 1.0, 1.0
|
||||
|
||||
toggle: (objectName) ->
|
||||
# toggles object with name objectName
|
||||
@startTimedAction(@getObjectWithName(objectName).getActionWithName("toggle"))
|
||||
|
||||
# 00000000 0000000 0000000
|
||||
# 000 000 000
|
||||
# 0000000 0000000 000
|
||||
# 000 000 000
|
||||
# 00000000 0000000 0000000
|
||||
|
||||
escape: (self) -> # handles an ESC key event
|
||||
|
||||
@resetProjection()
|
||||
|
||||
if "escape" in @dict
|
||||
if _.isFunction @dict["escape"]
|
||||
@dict["escape"]()
|
||||
else
|
||||
exec @dict["escape"] in globals()
|
||||
return
|
||||
|
||||
menu = new Menu()
|
||||
menu.getEventWithName("hide").addAction once @resetProjection
|
||||
|
||||
# if Controller.isDebugVersion()
|
||||
# menu.addItem (Controller.getLocalizedString("next level"), once(lambda w=self: w.performAction("exit 0",0)))
|
||||
# if "help" in @dict
|
||||
# menu.addItem (Controller.getLocalizedString("help"), once(@help))
|
||||
menu.addItem(Controller.getLocalizedString("restart"), once(@restart))
|
||||
|
||||
esc_menu_action = once @escape
|
||||
log "level_index #{world.level_index}"
|
||||
menu.addItem(Controller.getLocalizedString("load level"), (i=world.level_index,a=esc_menu_action) -> levelSelection(i, a))
|
||||
menu.addItem(Controller.getLocalizedString("setup"), once @quickSetup)
|
||||
menu.addItem(Controller.getLocalizedString("about"), once @display_about)
|
||||
menu.addItem(Controller.getLocalizedString("quit"), once world.quit)
|
||||
|
||||
# 0000000 00000000 000 000 0000000
|
||||
# 000 000 000 000 000
|
||||
# 000 0000000 000 000 0000000
|
||||
|
@ -499,6 +349,73 @@ class World extends Actor
|
|||
lrest = index % lsize
|
||||
new Pos index/lsize, lrest/@size.z, lrest%@size.z
|
||||
|
||||
# 0000000 0000000 0000000 0000000 0000000 000 00000000 0000000 000000000
|
||||
# 000 000 000 000 000 000 000 000 000 000 000 000 000 000
|
||||
# 000000000 000 000 000 000 000 000 0000000 000 0000000 000 000
|
||||
# 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
|
||||
# 000 000 0000000 0000000 0000000 0000000 0000000 00000000 0000000 000
|
||||
|
||||
addObjectAtPos: (object, x, y, z) ->
|
||||
pos = new Pos x, y, z
|
||||
object = @newObject object
|
||||
@setObjectAtPos object, pos
|
||||
# log "addObjectAtPos #{object.name}", pos
|
||||
@addObject object
|
||||
|
||||
addObjectLine: (object, sx,sy,sz, ex,ey,ez) ->
|
||||
if sx instanceof Pos
|
||||
start = sx
|
||||
end = sy
|
||||
else
|
||||
start = new Pos sx,sy,sz
|
||||
end = new Pos ex,ey,ez
|
||||
# adds a line of objects of type to the world. start and end should be 3-tuples or Pos objects
|
||||
if start instanceof Pos
|
||||
start = [start.x, start.y, start.z]
|
||||
[sx, sy, sz] = start
|
||||
if end instanceof Pos
|
||||
end = [end.x, end.y, end.z]
|
||||
[ex, ey, ez] = end
|
||||
|
||||
diff = [ex-sx, ey-sy, ez-sz]
|
||||
maxdiff = _.max diff.map Math.abs
|
||||
deltas = diff.map (a) -> a/maxdiff
|
||||
for i in [0...maxdiff]
|
||||
# pos = apply(Pos, (map (lambda a, b: int(a+i*b), start, deltas)))
|
||||
pos = new Pos (start[j]+i*deltas[j] for j in [0..2])
|
||||
if @isUnoccupiedPos pos
|
||||
@addObjectAtPos object, pos
|
||||
# if _.isString object
|
||||
# @addObjectAtPos eval(object), pos
|
||||
# else
|
||||
# @addObjectAtPos object(), pos
|
||||
|
||||
addObjectPoly: (object, points, close=1) ->
|
||||
# adds a polygon of objects of type to the world. points should be 3-tuples or Pos objects
|
||||
if close
|
||||
points.append (points[0])
|
||||
for index in range(1, len(points))
|
||||
@addObjectLine object, points[index-1], points[index]
|
||||
|
||||
addObjectRandom: (object, number) ->
|
||||
# adds number objects of type at random positions to the world
|
||||
for i in [0...number]
|
||||
if type (object) == types.StringType
|
||||
@setObjectRandom eval object
|
||||
else
|
||||
@setObjectRandom object()
|
||||
|
||||
setObjectRandom: (object) ->
|
||||
# adds number objects of type at random positions to the world
|
||||
object_set = 0
|
||||
while not object_set # hack alert!
|
||||
random_pos = Pos random.randrange(@size.x),
|
||||
random.randrange(@size.y),
|
||||
random.randrange(@size.z)
|
||||
if not object.isSpaceEgoistic() or @isUnoccupiedPos(random_pos)
|
||||
@addObjectAtPos object, random_pos
|
||||
object_set = 1
|
||||
|
||||
# 0000000 0000000 000 00000000 0000000 000000000 0000000
|
||||
# 000 000 000 000 000 000 000 000 000
|
||||
# 000 000 0000000 000 0000000 000 000 0000000
|
||||
|
@ -565,13 +482,6 @@ class World extends Actor
|
|||
else
|
||||
@objects.push object # if objects.indexOf(object) < 0
|
||||
|
||||
addObjectAtPos: (object, x, y, z) ->
|
||||
pos = new Pos x, y, z
|
||||
object = @newObject object
|
||||
@setObjectAtPos object, pos
|
||||
# log "addObjectAtPos #{object.name}", pos
|
||||
@addObject object
|
||||
|
||||
removeObject: (object) ->
|
||||
@unsetObject object
|
||||
_.pull @lights, object
|
||||
|
@ -584,6 +494,13 @@ class World extends Actor
|
|||
@setObjectAtPos object, pos
|
||||
world.playSound 'BOT_LAND'
|
||||
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
|
||||
# 000 000 000 000 000 000 000
|
||||
|
@ -628,7 +545,7 @@ class World extends Actor
|
|||
|
||||
getObjectWithName: (objectName) ->
|
||||
for o in @objects
|
||||
if objectName == o.getName()
|
||||
if objectName == o.name
|
||||
return o
|
||||
log "World.getObjectWithName :: no object found with name #{objectName}"
|
||||
null
|
||||
|
@ -650,11 +567,11 @@ class World extends Actor
|
|||
# log "world.objectWillMoveToPos #{object.name} #{duration}", pos
|
||||
|
||||
if @isInvalidPos pos
|
||||
log "world.objectWillMoveToPos [WARNING] invalid pos:", pos
|
||||
log "world.objectWillMoveToPos [WARNING] #{object.name} invalid pos:", pos
|
||||
return
|
||||
|
||||
if object.getPos().eql pos
|
||||
log "world.objectWillMoveToPos [WARNING] equal pos:", pos
|
||||
log "world.objectWillMoveToPos [WARNING] #{object.name} equal pos:", pos
|
||||
return
|
||||
|
||||
if cell = @getCellAtPos pos
|
||||
|
@ -664,9 +581,9 @@ class World extends Actor
|
|||
# temporary object at new pos will vanish before object will arrive . delete it
|
||||
objectAtNewPos.del()
|
||||
else
|
||||
log "world.objectWillMoveToPos [WARNING] timing conflict at pos:", pos
|
||||
log "world.objectWillMoveToPos [WARNING] #{object.name} timing conflict at pos:", pos
|
||||
else
|
||||
log "world.objectWillMoveToPos [WARNING] already occupied:", pos
|
||||
log "world.objectWillMoveToPos [WARNING] #{object.name} already occupied:", pos
|
||||
|
||||
if object.name != 'player'
|
||||
log "---------- tmpObjects not player? #{object.name}"
|
||||
|
@ -695,7 +612,7 @@ class World extends Actor
|
|||
# tmpObject.del()
|
||||
|
||||
if @isInvalidPos targetPos
|
||||
log "World.objectMoved invalid targetPos:", targetPos
|
||||
log "World.objectMoved [WARNING] #{movedObject.name} invalid targetPos:", targetPos
|
||||
return
|
||||
|
||||
# if tmpObject = @getObjectOfTypeAtPos TmpObject, pos
|
||||
|
@ -706,7 +623,7 @@ class World extends Actor
|
|||
# else
|
||||
|
||||
if @isOccupiedPos targetPos
|
||||
log "World.objectMoved object moved to occupied pos:", targetPos
|
||||
log "World.objectMoved [WARNING] #{movedObject.name} moved to occupied pos:", targetPos
|
||||
|
||||
# log 'World.objectMovedFromPos sourcePos:', sourcePos
|
||||
# log 'World.objectMovedFromPos targetPos:', targetPos
|
||||
|
@ -729,7 +646,7 @@ class World extends Actor
|
|||
if targetCell?
|
||||
targetCell.addObject movedObject
|
||||
else
|
||||
log 'world.objectMoved [WARNING] no target cell?'
|
||||
log "world.objectMoved [WARNING] #{movedObject.name} no target cell?"
|
||||
|
||||
setObjectColor: (color_name, color) ->
|
||||
if color_name == 'base'
|
||||
|
@ -818,7 +735,7 @@ class World extends Actor
|
|||
return true
|
||||
|
||||
mayObjectPushToPos: (object, pos, duration) ->
|
||||
log "world.mayObjectPushToPos object:#{object.name} duration:#{duration}", pos
|
||||
# log "world.mayObjectPushToPos object:#{object.name} duration:#{duration}", pos
|
||||
# returns true, if a pushable object is at pos and may be pushed
|
||||
return false if @isInvalidPos pos
|
||||
|
||||
|
@ -838,10 +755,9 @@ class World extends Actor
|
|||
else return false
|
||||
|
||||
pushableObject = @getOccupantAtPos pos
|
||||
log "pushableObject #{pushableObject?.name}"
|
||||
# log "pushableObject #{pushableObject?.name}"
|
||||
if pushableObject? and pushableObject instanceof Pushable #and
|
||||
# pushableObject instanceof MotorGear # bad
|
||||
log 'pushedByObjectInDirection'
|
||||
pushableObject.pushedByObjectInDirection object, direction, duration
|
||||
return true
|
||||
|
||||
|
@ -854,6 +770,95 @@ class World extends Actor
|
|||
|
||||
# Spikes::initialize()
|
||||
# Text::reinit()
|
||||
|
||||
# 000 000 00000000 000 00000000
|
||||
# 000 000 000 000 000 000
|
||||
# 000000000 0000000 000 00000000
|
||||
# 000 000 000 000 000
|
||||
# 000 000 00000000 0000000 000
|
||||
|
||||
help: (index=0) ->
|
||||
# displays help messages
|
||||
|
||||
# text_list = @dict["help"]
|
||||
# more_text = index < len (text_list) - 1
|
||||
# less_text = index > 0
|
||||
#
|
||||
# list = text_list[index].split("$key(")
|
||||
# for i in range (1, len(list))
|
||||
# close = list[i].find(")")
|
||||
# list[i] = Controller.player.getKeyForAction (list[i][:close]) + list[i][close+1:]
|
||||
#
|
||||
# list.append ("\n\n$scale(0.5)(%d/%d)" % (index+1, len (text_list)))
|
||||
# help_text = KikiPageText ("".join(list), more_text, less_text)
|
||||
#
|
||||
# if more_text:
|
||||
# help_text.getEventWithName ("next").addAction (once (lambda i=index+1: @help (i)))
|
||||
# if less_text:
|
||||
# help_text.getEventWithName ("previous").addAction (once (lambda i=index-1: @help (i)))
|
||||
|
||||
outro: (index=0) ->
|
||||
# well hidden outro :-)
|
||||
outro_text = """
|
||||
$scale(1.5)congratulations!\n\n$scale(1)you rescued\nthe nano world!
|
||||
|
||||
the last dumb mutant bot\nhas been destroyed.\n\nthe maker is functioning again.
|
||||
kiki will go now\nand see all his new friends.\n\nyou should maybe\ndo the same?
|
||||
the maker wants to thank you!\n\n(btw.: you thought\nyou didn't see\nkiki's maker in the game?
|
||||
you are wrong!\nyou saw him\nall the time,\nbecause kiki\nlives inside him!)\n\n$scale(1.5)the end
|
||||
p.s.: the maker of the game\nwants to thank you as well!\n\ni definitely want your feedback:
|
||||
please send me a mail (monsterkodi@users.sf.net)\nwith your experiences,
|
||||
which levels you liked, etc.\n\nthanks in advance and have a nice day,\n\nyours kodi
|
||||
"""
|
||||
|
||||
more_text = index < outro_text.length-1
|
||||
less_text = index > 0
|
||||
|
||||
page_text = outro_text[index]
|
||||
page_text += "\n\n$scale(0.5)(#{index+1}/#{outro_text.length})"
|
||||
|
||||
page = KikiPageText(page_text, more_text, less_text)
|
||||
page.getEventWithName("hide").addAction(once(display_main_menu))
|
||||
|
||||
if more_text
|
||||
page.getEventWithName("next").addAction (i=index+1) => @outro i
|
||||
if less_text
|
||||
page.getEventWithName("previous").addAction (i=index-1) => @outro i
|
||||
|
||||
resetProjection: -> world.getProjection().setViewport 0.0, 0.0, 1.0, 1.0
|
||||
|
||||
# 00000000 0000000 0000000
|
||||
# 000 000 000
|
||||
# 0000000 0000000 000
|
||||
# 000 000 000
|
||||
# 00000000 0000000 0000000
|
||||
|
||||
escape: (self) -> # handles an ESC key event
|
||||
|
||||
@resetProjection()
|
||||
|
||||
if "escape" in @dict
|
||||
if _.isFunction @dict["escape"]
|
||||
@dict["escape"]()
|
||||
else
|
||||
exec @dict["escape"] in globals()
|
||||
return
|
||||
|
||||
menu = new Menu()
|
||||
menu.getEventWithName("hide").addAction once @resetProjection
|
||||
|
||||
# if Controller.isDebugVersion()
|
||||
# menu.addItem (Controller.getLocalizedString("next level"), once(lambda w=self: w.performAction("exit 0",0)))
|
||||
# if "help" in @dict
|
||||
# menu.addItem (Controller.getLocalizedString("help"), once(@help))
|
||||
menu.addItem(Controller.getLocalizedString("restart"), once(@restart))
|
||||
|
||||
esc_menu_action = once @escape
|
||||
log "level_index #{world.level_index}"
|
||||
menu.addItem(Controller.getLocalizedString("load level"), (i=world.level_index,a=esc_menu_action) -> levelSelection(i, a))
|
||||
menu.addItem(Controller.getLocalizedString("setup"), once @quickSetup)
|
||||
menu.addItem(Controller.getLocalizedString("about"), once @display_about)
|
||||
menu.addItem(Controller.getLocalizedString("quit"), once world.quit)
|
||||
|
||||
# 000 000 0000000 000 000
|
||||
# 000 0 000 000 000 000 000
|
||||
|
|
Loading…
Reference in New Issue
Block a user