diff --git a/coffee/action.coffee b/coffee/action.coffee index 24196a3..fe577d7 100644 --- a/coffee/action.coffee +++ b/coffee/action.coffee @@ -124,7 +124,7 @@ class Action @last = 0 if @mode == Action.CONTINUOUS - log "action.performWithEvent #{@name} mode == Action.CONTINUOUS" + # log "action.performWithEvent #{@name} mode == Action.CONTINUOUS" @current = @rest @start = eventTime @last = 0 diff --git a/coffee/actor.coffee b/coffee/actor.coffee index 2fb9c72..2c9fceb 100644 --- a/coffee/actor.coffee +++ b/coffee/actor.coffee @@ -21,6 +21,8 @@ class Actor extends Emitter @events = [] super + del: -> Timer.removeActionsOfObject @ + # 00000000 000 000 00000000 000 000 000000000 # 000 000 000 000 0000 000 000 # 0000000 000 000 0000000 000 0 000 000 diff --git a/coffee/bot.coffee b/coffee/bot.coffee index a09a5d6..276c270 100644 --- a/coffee/bot.coffee +++ b/coffee/bot.coffee @@ -67,6 +67,9 @@ class Bot extends Pushable @rightTire.rotation.set 0, Vector.DEG2RAD(-90), 0 @mesh.add @rightTire + @mesh.castShadow = @rightTire.castShadow = @leftTire.castShadow = true + @mesh.receiveShadow = @leftTire.receiveShadow = @rightTire.receiveShadow = true + @left_tire_rot = 0.0 @right_tire_rot = 0.0 @last_fume = 0 @@ -112,13 +115,13 @@ class Bot extends Pushable # 000 000 000 000 000 000 000 000 000 000 000 000 0000 # 0000000 000 000 000 00000000 0000000 000 000 0000000 000 000 - getDown: -> @orientation.rotate new Vector 0,-1,0 - getUp: -> @orientation.rotate new Vector 0,1,0 + getDown: -> @orientation.rotate Vector.minusY + getUp: -> @orientation.rotate Vector.unitY getDir: -> @orientation.rotate new Vector 0,0,@dir_sgn - getCurrentDir: -> @current_orientation.rotate(new Vector 0,0,1).normal() - getCurrentUp: -> @current_orientation.rotate(new Vector 0,1,0).normal() - getCurrentLeft: -> @current_orientation.rotate(new Vector 1,0,0).normal() + getCurrentDir: -> @current_orientation.rotate(Vector.unitZ).normal() + getCurrentUp: -> @current_orientation.rotate(Vector.unitY).normal() + getCurrentLeft: -> @current_orientation.rotate(Vector.unitX).normal() addMoves: (m) -> @moves += m addHealth: (h) -> @health = Math.max @health+h @@ -254,6 +257,7 @@ class Bot extends Pushable if not @direction.isZero() super action return + log 'still needed?' @current_position = @position.plus @getDown().mul(relTime) return @@ -261,7 +265,7 @@ class Bot extends Pushable @left_tire_rot += @dir_sgn * dltTime/2 @right_tire_rot += @dir_sgn * dltTime/2 - @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * relTime * -90.0, new Vector 1,0,0 + @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * relTime * -90.0, Vector.unitX break when Action.CLIMB_DOWN @@ -271,11 +275,11 @@ class Bot extends Pushable if relTime <= 0.2 @current_position = @position.plus @getDir().mul (relTime/0.2)/2 else if (relTime >= 0.8) - @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * 90.0, new Vector 1,0,0 + @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * 90.0, Vector.unitX @current_position = @position.plus @getDir().plus @getDown().mul 0.5+(relTime-0.8)/0.2/2 else - @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * (relTime-0.2)/0.6 * 90.0, new Vector 1,0,0 - rotVec = (@orientation.mul @climb_orientation).rotate new Vector 0,1,0 + @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * (relTime-0.2)/0.6 * 90.0, Vector.unitX + rotVec = (@orientation.mul @climb_orientation).rotate Vector.unitY @current_position = @position.plus @getDir().plus(@getDown()).plus(rotVec).mul 0.5 break @@ -284,20 +288,20 @@ class Bot extends Pushable if @move_action == null and relTime == 0.0 # if not performing move action and start of rotation # update @orientation now, so next move action will move in desired @direction if action.id == Action.TURN_LEFT - @orientation = @orientation.mul Quaternion.rotationAroundVector 90.0, new Vector 0,1,0 - @rest_orientation = Quaternion.rotationAroundVector -90.0, new Vector 0,1,0 + @orientation = @orientation.mul Quaternion.rotationAroundVector 90.0, Vector.unitY + @rest_orientation = Quaternion.rotationAroundVector -90.0, Vector.unitY else - @orientation = @orientation.mul Quaternion.rotationAroundVector -90.0, new Vector 0,1,0 - @rest_orientation = Quaternion.rotationAroundVector 90.0, new Vector 0,1,0 + @orientation = @orientation.mul Quaternion.rotationAroundVector -90.0, Vector.unitY + @rest_orientation = Quaternion.rotationAroundVector 90.0, Vector.unitY if action.id == Action.TURN_LEFT @left_tire_rot += -dltTime @right_tire_rot += dltTime - @rotate_orientation = Quaternion.rotationAroundVector relTime * 90.0, new Vector 0,1,0 + @rotate_orientation = Quaternion.rotationAroundVector relTime * 90.0, Vector.unitY else @left_tire_rot += dltTime @right_tire_rot += -dltTime - @rotate_orientation = Quaternion.rotationAroundVector relTime * -90.0, new Vector 0,1,0 + @rotate_orientation = Quaternion.rotationAroundVector relTime * -90.0, Vector.unitY break else @@ -315,12 +319,13 @@ class Bot extends Pushable finishAction: (action) -> - log "Bot.finishAction #{action.id} #{action.name}" if action.name != 'noop' + # log "Bot.finishAction #{action.id} #{action.name}" if action.name != 'noop' switch action.id when Action.NOOP, Action.SHOOT return - when Action.PUSH + when Action.PUSH, Action.FALL + @move_action = null super action return when Action.TURN_LEFT, Action.TURN_RIGHT @@ -345,10 +350,10 @@ class Bot extends Pushable # take over result of rotation to prevent sliding if @rotate_action.id == Action.TURN_LEFT @orientation = @orientation.mul Quaternion.rotationAroundVector(90.0, new Vector(0,1,0)).mul @rest_orientation - @rest_orientation = Quaternion.rotationAroundVector -90.0, new Vector 0,1,0 + @rest_orientation = Quaternion.rotationAroundVector -90.0, Vector.unitY else @orientation = @orientation.mul Quaternion.rotationAroundVector(-90.0, new Vector(0,1,0)).mul @rest_orientation - @rest_orientation = Quaternion.rotationAroundVector 90.0, new Vector 0,1,0 + @rest_orientation = Quaternion.rotationAroundVector 90.0, Vector.unitY if action.id != Action.CLIMB_UP targetPos = @current_position.round() @@ -366,7 +371,7 @@ class Bot extends Pushable # 000 000 000 000 000 0000000 000 000 00000000 0000000 actionFinished: (action) -> - # log "bot.actionFinished #{action.name} #{action.id}" + log "bot.actionFinished #{action.name} #{action.id}" # if @isDead() # log "DIE!" @@ -404,6 +409,7 @@ class Bot extends Pushable @move_action = @getActionWithId Action.CLIMB_UP world.playSound 'BOT_LAND', @getPos(), 0.5 else if world.isUnoccupiedPos @position.plus @getDown() # below will be empty + log 'below empty', world.isUnoccupiedPos(@position.plus @getDown()), @position.plus @getDown() if @move # sticky if moving if world.isUnoccupiedPos @position.plus @getDir() # forward will be empty if world.isOccupiedPos @position.plus @getDir().minus @getUp() # below forward is solid @@ -417,9 +423,10 @@ class Bot extends Pushable if @move_action == null @move_action = @getActionWithId Action.FALL + @direction = @getDown() - else if action.id == Action.FALL or action.id == Action.FALL_FORWARD # landed - if @ == world.player + else if action.id in [Action.FALL_FORWARD, Action.FALL] # landed + if @name == 'player' world.playSound 'BOT_LAND' else world.playSound 'BOT_LAND', @getPos() diff --git a/coffee/cage.coffee b/coffee/cage.coffee index d191e93..3d0eed1 100644 --- a/coffee/cage.coffee +++ b/coffee/cage.coffee @@ -27,6 +27,7 @@ class Cage @raster.translateX -0.5 @raster.translateY -0.5 @raster.translateZ -0.5 + @raster.receiveShadow = true world.scene.add @raster geom = @wallTiles @gap @@ -34,6 +35,7 @@ class Cage @cage.translateX -0.5 @cage.translateY -0.5 @cage.translateZ -0.5 + @cage.receiveShadow = true world.scene.add @cage del: -> diff --git a/coffee/gate.coffee b/coffee/gate.coffee index 65fd3b9..6a57324 100644 --- a/coffee/gate.coffee +++ b/coffee/gate.coffee @@ -39,7 +39,9 @@ class Gate extends Switch t3.rotateX Vector.DEG2RAD 90 t2.merge t3 @tors = new THREE.Mesh t2, @mat + @tors.castShadow = true @mesh.add @tors + @mesh.castShadow = true @mesh bulletImpact: -> diff --git a/coffee/item.coffee b/coffee/item.coffee index 92df9b9..dfac47e 100644 --- a/coffee/item.coffee +++ b/coffee/item.coffee @@ -23,8 +23,9 @@ class Item extends Actor @direction = new Vector @move_action = null - del: -> - log "item del!!!!!!!!!!!!!!!!!!!!!! #{@name}" + del: -> + super + log "item del !!!!!!!!!!!!!!!!!!!!!! #{@name}" world.scene.remove @mesh if @mesh? world.removeObject @ @emit 'deleted' @@ -47,7 +48,11 @@ class Item extends Actor p = new Pos x,y,z @position = @current_position = new Vector p - setOrientation: (q) -> @current_orientation = @orientation = new Quaternion q + setOrientation: (q) -> + @current_orientation = @orientation = new Quaternion q + # log "item.setOrientation:", @orientation + @orientation + setCurrentPosition: (p) -> @current_position = p setCurrentOrientation: (q) -> @current_orientation = q diff --git a/coffee/levels.coffee b/coffee/levels.coffee new file mode 100644 index 0000000..bc67136 --- /dev/null +++ b/coffee/levels.coffee @@ -0,0 +1,48 @@ +# 000 00000000 000 000 00000000 000 0000000 +# 000 000 000 000 000 000 000 +# 000 0000000 000 000 0000000 000 0000000 +# 000 000 000 000 000 000 +# 0000000 00000000 0 00000000 0000000 0000000 + +class Levels + + constructor: () -> + @dict = {} + @list = [ + # intro + # "steps", + "start", + #"move", "electro", "elevate", + # "throw", + # easy + # "gold", + "jump", "escape", "gears", + # "gamma", + "cube", "switch", "borg", + "mini", + # "blocks", + "bombs", "sandbox", "energy", "maze", "love", + # medium + "towers", "edge", "random", "plate", "nice", "entropy", + # owen hay's levels (TODO: sort in) + "grasp", "fallen", "cheese", "invisimaze", "spiral", + # difficult + "slick", "bridge", "flower", "stones", "walls", "grid", + "rings", + # "core", + "bronze", "pool", + # tough + "hidden", "church", + # "strange", + "mesh", "columns", "machine", + # very hard + # "neutron", + "captured", "circuit", "regal", "conductor", "evil", + # outro + "mutants"] + + # import the levels + for levelName in @list + @dict[levelName] = require "./levels/#{levelName}" + +module.exports = Levels diff --git a/coffee/levels/escape.coffee b/coffee/levels/escape.coffee index e2bfdfd..5f57384 100644 --- a/coffee/levels/escape.coffee +++ b/coffee/levels/escape.coffee @@ -33,33 +33,33 @@ module.exports = 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)) - world.addObjectAtPos('KikiStone', world.decenter( 1, s.y/2, 0)) - world.addObjectAtPos('KikiStone', world.decenter( 0, s.y/2, 1)) - world.addObjectAtPos('KikiStone', world.decenter( 0, s.y/2,-1)) - world.addObjectAtPos('KikiStone', world.decenter(-1, s.y/2, 0)) + world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2, 0 + world.addObjectAtPos 'KikiStone', world.decenter 1, s.y/2, 0 + world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2, 1 + 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)) - world.addObjectAtPos('KikiWall', world.decenter(-1, 0, 0)) - world.addObjectAtPos('KikiWall', world.decenter( 0, 0,-1)) - - world.addObjectAtPos('KikiWall', world.decenter( 1,-1, 0)) - world.addObjectAtPos('KikiWall', world.decenter( 0,-1, 1)) - world.addObjectAtPos('KikiWall', world.decenter(-1,-1, 0)) - world.addObjectAtPos('KikiWall', world.decenter( 0,-1,-1)) - world.addObjectAtPos('KikiWall', world.decenter( 1,-1, 1)) - world.addObjectAtPos('KikiWall', world.decenter(-1,-1, 1)) - world.addObjectAtPos('KikiWall', world.decenter(-1,-1,-1)) - world.addObjectAtPos('KikiWall', world.decenter( 1,-1,-1)) - - world.addObjectAtPos('KikiWall', world.decenter( 1,-2, 0)) - world.addObjectAtPos('KikiWall', world.decenter( 0,-2, 1)) - world.addObjectAtPos('KikiWall', world.decenter(-1,-2, 0)) - world.addObjectAtPos('KikiWall', world.decenter( 0,-2,-1)) - \ No newline at end of file + world.addObjectAtPos 'KikiWall', world.decenter 1, 0, 0 + world.addObjectAtPos 'KikiWall', world.decenter 0, 0, 1 + world.addObjectAtPos 'KikiWall', world.decenter -1, 0, 0 + world.addObjectAtPos 'KikiWall', world.decenter 0, 0,-1 + + world.addObjectAtPos 'KikiWall', world.decenter 1,-1, 0 + world.addObjectAtPos 'KikiWall', world.decenter 0,-1, 1 + world.addObjectAtPos 'KikiWall', world.decenter -1,-1, 0 + world.addObjectAtPos 'KikiWall', world.decenter 0,-1,-1 + world.addObjectAtPos 'KikiWall', world.decenter 1,-1, 1 + world.addObjectAtPos 'KikiWall', world.decenter -1,-1, 1 + world.addObjectAtPos 'KikiWall', world.decenter -1,-1,-1 + world.addObjectAtPos 'KikiWall', world.decenter 1,-1,-1 + + world.addObjectAtPos 'KikiWall', world.decenter 1,-2, 0 + world.addObjectAtPos 'KikiWall', world.decenter 0,-2, 1 + world.addObjectAtPos 'KikiWall', world.decenter -1,-2, 0 + world.addObjectAtPos 'KikiWall', world.decenter 0,-2,-1 + \ No newline at end of file diff --git a/coffee/levels/start.coffee b/coffee/levels/start.coffee index dd8369b..7df6d95 100644 --- a/coffee/levels/start.coffee +++ b/coffee/levels/start.coffee @@ -17,14 +17,13 @@ module.exports = to get to the exit, jump on the stone to jump, - press "$key(jump)" - while movin + press "$key(jump)" while moving to move, press "$key(move forward)" or "$key(move backward)" to turn, press "$key(turn left)" or "$key(turn right)" """ player: - coordinates: [3,0,3] - nostatus: 0 + position: [0,0,4] + orientation: rotx270 exits: [ name: "exit" active: 1 diff --git a/coffee/levels/steps.coffee b/coffee/levels/steps.coffee index a21574c..85120cf 100644 --- a/coffee/levels/steps.coffee +++ b/coffee/levels/steps.coffee @@ -21,8 +21,8 @@ module.exports = to turn, press "$key(turn left)" or "$key(turn right)" """ player: - coordinates: [4,4,8] - nostatus: 0 + position: [0,0,-5] + orientation: roty0 exits: [ name: "exit" active: 1 diff --git a/coffee/lib/vector.coffee b/coffee/lib/vector.coffee index 101958f..5673200 100644 --- a/coffee/lib/vector.coffee +++ b/coffee/lib/vector.coffee @@ -125,11 +125,18 @@ class Vector @DEG2RAD: (d) -> Math.PI*d/180.0 @RAD2DEG: (r) -> r*180.0/Math.PI + @unitX = new Vector 1,0,0 + @unitY = new Vector 0,1,0 + @unitZ = new Vector 0,0,1 + @minusX = new Vector -1,0,0 + @minusY = new Vector 0,-1,0 + @minusZ = new Vector 0,0,-1 + @X = 0 - @SX = 0 @Y = 1 @Z = 2 @W = 3 + @SX = 0 @SY = 5 @SZ = 10 @TX = 12 diff --git a/coffee/light.coffee b/coffee/light.coffee index 82cec03..8889a05 100644 --- a/coffee/light.coffee +++ b/coffee/light.coffee @@ -15,6 +15,10 @@ class Light extends Item # @diffuse_color = colors[KikiLight_diffuse_color] # @specular_color = colors[KikiLight_specular_color] @point = new THREE.PointLight 0xffffff, @intensity, @radius, 2 + @point.castShadow = true + @point.shadowDarkness = 0.5 + @point.shadow.mapSize = new THREE.Vector2 2048, 2048 + @point.shadow.bias = 0.01 geom = new THREE.SphereGeometry 0.3, 16, 16 mat = new THREE.MeshLambertMaterial color: 0xffffff @@ -27,10 +31,12 @@ class Light extends Item @mesh = new THREE.Mesh geom, mat world.scene.add @point + world.addLight @ @setPosition pos if pos? super del: -> + world.removeLight @ world.scene.remove @point super diff --git a/coffee/player.coffee b/coffee/player.coffee index bb4eaa0..97c1be4 100644 --- a/coffee/player.coffee +++ b/coffee/player.coffee @@ -251,10 +251,10 @@ class Player extends Bot super action - finishRotateAction: () -> - if @rotate_action - @rotate = false - @finishAction @rotate_action + # finishRotateAction: () -> + # if @rotate_action + # @rotate = false + # @finishAction @rotate_action # 00000000 00000000 00000000 00000000 0000000 00000000 00 00 # 000 000 000 000 000 000 000 000 000 000 000 000 @@ -307,14 +307,14 @@ class Player extends Bot reborn: () -> @died = false - reset: () -> - super - Timer.removeActionsOfObject @ - - @look_action = null - @look_angle = 0.0 - @new_dir_sgn = 1.0 - @rotate = 0 + # reset: () -> + # super + # Timer.removeActionsOfObject @ +# + # @look_action = null + # @look_angle = 0.0 + # @new_dir_sgn = 1.0 + # @rotate = 0 # 000 000 00000000 000 000 # 000 000 000 000 000 @@ -356,8 +356,8 @@ class Player extends Bot @moveBot() # perform new move action (depending on environment) @jump_once = false else - if @move_action.name == 'move forward' and @move_action.getRelativeTime() < 0.6 or - @move_action.name == 'climb down' and @move_action.getRelativeTime() < 0.4 + if @move_action.id == Action.MOVE and @move_action.getRelativeTime() < 0.6 or + @move_action.id == Action.CLIMB_DOWN and @move_action.getRelativeTime() < 0.4 if world.isUnoccupiedPos @position.plus @getUp() if world.isUnoccupiedPos @position.plus @getUp().plus @getDir() action = @getActionWithId Action.JUMP_FORWARD @@ -367,8 +367,8 @@ class Player extends Bot Timer.removeAction @move_action @move_action = action Timer.addAction @move_action - else - log "cant jump #{@move_action.name}" + else if @move_action.id in [Action.JUMP, Action.JUMP_FORWARD] + @jump_once = false return true when @key.push diff --git a/coffee/pushable.coffee b/coffee/pushable.coffee index e756d16..7474176 100644 --- a/coffee/pushable.coffee +++ b/coffee/pushable.coffee @@ -16,15 +16,21 @@ class Pushable extends Item constructor: () -> super @pusher = null - @direction = new Vector + @direction = Vector.minusY @addAction new Action @, Action.NOOP, "noop" @addAction new Action @, Action.PUSH, "push" @addAction new Action @, Action.FALL, "fall", 40 + setOrientation: (q) -> + super q + if not @pusher? + @direction = @orientation.rotate Vector.minusZ + # log "Pushable.setOrientation direction:", @direction + pushedByObjectInDirection: (object, dir, duration) -> - pushAction = @getActionWithId Action.PUSH + pushAction = @getActionWithId Action.PUSH @pusher = object @move_action = pushAction @@ -50,12 +56,13 @@ class Pushable extends Item switch action.id when Action.PUSH, Action.FALL @move_action = null - world.objectMoved @, @position, @current_position - # log "Pushable.finishAction setPosition #{@current_position}" - @setPosition @current_position + targetPos = @current_position.round() + world.objectMoved @, @position, targetPos + log "Pushable.finishAction setPosition:", targetPos + @setPosition targetPos actionFinished: (action) -> - if action.id == Action.PUSH or actionId == Action.FALL + if action.id in [Action.PUSH, Action.FALL] gravityDir = @direction if action.id == Action.PUSH @@ -76,6 +83,7 @@ class Pushable extends Item if world.isUnoccupiedPos @position.plus gravityDir @direction = gravityDir @move_action = @getActionWithId Action.FALL + log 'Pushable.actionFinished below empty, fall!' Timer.addAction @move_action else @direction.reset() diff --git a/coffee/switch.coffee b/coffee/switch.coffee index 9fce532..83c6d93 100644 --- a/coffee/switch.coffee +++ b/coffee/switch.coffee @@ -34,6 +34,10 @@ class Switch extends Item @setActive active + del: () -> + super + @light?.del() + createMesh: () -> torusRadius = 0.05 t1 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32 @@ -43,6 +47,7 @@ class Switch extends Item shading: THREE.SmoothShading shininess: 5 @mesh = new THREE.Mesh t1, @mat + @mesh.castShadow = true t2 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32 t3 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32 @@ -50,13 +55,12 @@ class Switch extends Item t3.rotateX Vector.DEG2RAD 90 t2.merge t3 @tors = new THREE.Mesh t2, @mat + @tors.castShadow = true @mesh.add @tors @mesh bulletImpact: -> @setActive not @active - - del: () -> @light?.del() - + lightDeleted: () -> @light = null setActive: (status) -> @@ -89,9 +93,9 @@ class Switch extends Item animate: (f) -> @angle += f * 360 - @mesh.quaternion.copy Quaternion.rotationAroundVector @angle, new Vector 0,1,0 - @tors.quaternion.copy Quaternion.rotationAroundVector @angle/2, new Vector 0,0,1 - # @tort.quaternion.copy Quaternion.rotationAroundVector @angle/2, new Vector 0,0,1 + @mesh.quaternion.copy Quaternion.rotationAroundVector @angle, Vector.unitY + @tors.quaternion.copy Quaternion.rotationAroundVector @angle/2, Vector.unitZ + # @tort.quaternion.copy Quaternion.rotationAroundVector @angle/2, Vector.unitZ performAction: (action) -> diff --git a/coffee/wall.coffee b/coffee/wall.coffee index 2946ce2..7d53489 100644 --- a/coffee/wall.coffee +++ b/coffee/wall.coffee @@ -22,6 +22,8 @@ class Wall extends Item opacity: 0.85 shininess: 5 @mesh = new THREE.Mesh @geom, @mat + @mesh.castShadow = true + @mesh.receiveShadow = true super # s = 0.45 diff --git a/coffee/world.coffee b/coffee/world.coffee index 4b71405..9b3c777 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -15,6 +15,7 @@ Size = require './lib/size' Cell = require './cell' Gate = require './gate' Light = require './light' +Levels = require './levels' Player = require './player' Cage = require './cage' Timer = require './timer' @@ -35,8 +36,7 @@ class World extends Actor @CAMERA_BEHIND = 1 @CAMERA_FOLLOW = 2 - @levelList = [] - @levelDict = [] + @levels = null @normals = [ new Vector 1, 0, 0 @@ -67,6 +67,7 @@ class World extends Actor @renderer.setClearColor 0x000000 @renderer.setSize @view.offsetWidth, @view.offsetHeight + @renderer.shadowMap.type = THREE.PCFSoftShadowMap # 0000000 0000000 00 00 00000000 00000000 0000000 # 000 000 000 000 000 000 000 000 000 000 @@ -124,66 +125,26 @@ class World extends Actor world.name = 'world' global.world = world Timer.init() - world.create first @levelList + world.create first @levels.list world @initGlobal: () -> - return if @levelList.length + return if @levels? global.rot0 = new Quaternion() - global.rotz180 = Quaternion.rotationAroundVector 180, new Vector 0,0,1 - global.rotz90 = Quaternion.rotationAroundVector 90, new Vector 0,0,1 - global.roty270 = Quaternion.rotationAroundVector 270, new Vector 0,1,0 - global.roty180 = Quaternion.rotationAroundVector 180, new Vector 0,1,0 - global.roty90 = Quaternion.rotationAroundVector 90, new Vector 0,1,0 - global.roty0 = Quaternion.rotationAroundVector 0, new Vector 0,1,0 - global.rotx180 = Quaternion.rotationAroundVector 180, new Vector 1,0,0 - global.rotx90 = Quaternion.rotationAroundVector 90, new Vector 1,0,0 - - # 000 00000000 000 000 00000000 000 0000000 - # 000 000 000 000 000 000 000 - # 000 0000000 000 000 0000000 000 0000000 - # 000 000 000 000 000 000 - # 0000000 00000000 0 00000000 0000000 0000000 - - @levelList = [ - # intro - "steps", - # "start", - #"move", "electro", "elevate", - # "throw", - # easy - # "gold", - "jump", "escape", "gears", - # "gamma", - "cube", "switch", "borg", - "mini", - # "blocks", - "bombs", "sandbox", "energy", "maze", "love", - # medium - "towers", "edge", "random", "plate", "nice", "entropy", - # owen hay's levels (TODO: sort in) - "grasp", "fallen", "cheese", "invisimaze", "spiral", - # difficult - "slick", "bridge", "flower", "stones", "walls", "grid", - "rings", - # "core", - "bronze", "pool", - # tough - "hidden", "church", - # "strange", - "mesh", "columns", "machine", - # very hard - # "neutron", - "captured", "circuit", "regal", "conductor", "evil", - # outro - "mutants"] - - # import the levels - for levelName in @levelList - @levelDict[levelName] = require "./levels/#{levelName}" + global.rotz90 = Quaternion.rotationAroundVector 90, Vector.unitZ + global.rotz180 = Quaternion.rotationAroundVector 180, Vector.unitZ + global.roty0 = Quaternion.rotationAroundVector 0, Vector.unitY + global.roty90 = Quaternion.rotationAroundVector 90, Vector.unitY + global.roty180 = Quaternion.rotationAroundVector 180, Vector.unitY + global.roty270 = Quaternion.rotationAroundVector 270, Vector.unitY + global.rotx90 = Quaternion.rotationAroundVector 90, Vector.unitX + global.rotx180 = Quaternion.rotationAroundVector 180, Vector.unitX + global.rotx270 = Quaternion.rotationAroundVector 270, Vector.unitX + @levels = new Levels + # 0000000 00000000 00000000 0000000 000000000 00000000 # 000 000 000 000 000 000 000 000 # 000 0000000 0000000 000000000 000 0000000 @@ -196,9 +157,9 @@ class World extends Actor if worldDict if _.isString worldDict - @level_index = World.levelList.indexOf worldDict + @level_index = World.levels.list.indexOf worldDict @level_name = worldDict - @dict = World.levelDict[worldDict] + @dict = World.levels.dict[worldDict] else @dict = worldDict @@ -272,7 +233,7 @@ class World extends Actor @player = new Player # log "player_dict", player_dict - @player.setOrientation @dict.player.orientation ? roty90 + @player.setOrientation @dict.player.orientation ? rotx90 if @dict.player.position? @addObjectAtPos @player, @decenter @dict.player.position @@ -329,16 +290,32 @@ class World extends Actor world.moveObjectToPos @player, world.decenter @dict.player.resetPosition else world.moveObjectToPos @player, world.decenter @dict.player.position + + # 000 000 0000000 000 000 000000000 + # 000 000 000 000 000 000 + # 000 000 000 0000 000000000 000 + # 000 000 000 000 000 000 000 + # 0000000 000 0000000 000 000 000 + + addLight: (light) -> + @lights.push light + @enableShadows true + + removeLight: (light) -> + _.pull @lights, light + @enableShadows false if not @lights.length + enableShadows: (enable) -> + @renderer.shadowMap.enabled = enable + # 0000000 0000000 000000000 000 0000000 000 000 # 000 000 000 000 000 000 000 0000 000 # 000000000 000 000 000 000 000 000 0 000 # 000 000 000 000 000 000 000 000 0000 # 000 000 0000000 000 000 0000000 000 000 - exitLevel: (action) => - log "world.exitLevel #{action}" + log "world.exitLevel", action @finish() # @player.status.setMoves 0 exitIndex = parseInt action.name.slice 5 @@ -347,9 +324,8 @@ class World extends Actor # w = @dict.exits[exitIndex].world # w() if _.isFunction w # else - # world = world.create levelList[world.level_index+1] - log "world.level_index #{world.level_index} nextLevel #{World.levelList[world.level_index+1]}" - world.create World.levelList[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] activate: (objectName) -> # activates object with name objectName @@ -645,13 +621,11 @@ class World extends Actor deleteAllObjects: () -> log 'world.deleteAllObjects' + + Timer.removeAllActions() if @player? - @player.finishRotateAction() - @removeObject @player # remove the player first, to keep it's state - Timer.removeAllActions() - # Controller.removeKeyHandler (Controller.player) # prevent keyboard input while building world - @player.reset() + @player.del() while @lights.length oldSize = @lights.length @@ -664,7 +638,7 @@ class World extends Actor oldSize = @objects.length last(@objects).del() # destructor will call remove object if oldSize == @objects.length - log "WARNING World.deleteAllObjects object no auto remove" + log "WARNING World.deleteAllObjects object no auto remove #{last(@objects).name}" @objects.pop() deleteObjectsWithClassName: (className) ->