diff --git a/coffee/levels.coffee b/coffee/levels.coffee index bc67136..4b8e445 100644 --- a/coffee/levels.coffee +++ b/coffee/levels.coffee @@ -11,12 +11,13 @@ class Levels @list = [ # intro # "steps", - "start", + # "start", #"move", "electro", "elevate", # "throw", # easy # "gold", - "jump", "escape", "gears", + # "jump", + "escape", "gears", # "gamma", "cube", "switch", "borg", "mini", diff --git a/coffee/levels/escape.coffee b/coffee/levels/escape.coffee index 5f57384..98a8451 100644 --- a/coffee/levels/escape.coffee +++ b/coffee/levels/escape.coffee @@ -31,7 +31,7 @@ module.exports = Switch = require '../switch' exit_switch = new Switch() exit_switch.getEventWithName("switched").addAction world.continuous () -> world.toggle "exit" - world.addObjectAtPos(exit_switch, world.decenter( 0, -2, 0)) + 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 @@ -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 diff --git a/coffee/lib/pos.coffee b/coffee/lib/pos.coffee index 414035e..dcdcab2 100644 --- a/coffee/lib/pos.coffee +++ b/coffee/lib/pos.coffee @@ -17,13 +17,13 @@ class Pos @y = Math.round x.y @z = Math.round x.z ? 0 else if Array.isArray x - @x = Math.round x[0] - @y = Math.round x[1] - @z = Math.round x[2] + @x = Math.floor x[0] + @y = Math.floor x[1] + @z = Math.floor x[2] else - @x = Math.round x - @y = Math.round y - @z = Math.round z + @x = Math.floor x + @y = Math.floor y + @z = Math.floor z # log "Pos #{@x} #{@y} #{@z}" if Number.isNaN @x throw new Error diff --git a/coffee/player.coffee b/coffee/player.coffee index bbfbbbf..eb5509e 100644 --- a/coffee/player.coffee +++ b/coffee/player.coffee @@ -6,25 +6,14 @@ # 000 0000000 000 000 000 00000000 000 000 { clamp -} = require '/Users/kodi/s/ko/js/tools/tools' -log = require '/Users/kodi/s/ko/js/tools/log' -Bot = require './bot' -Action = require './action' -Timer = require './timer' -Vector = require './lib/vector' -Quaternion = require './lib/quaternion' +} = require '/Users/kodi/s/ko/js/tools/tools' +log = require '/Users/kodi/s/ko/js/tools/log' +Bot = require './bot' +Action = require './action' +Timer = require './timer' +Vector = require './lib/vector' +Quaternion = require './lib/quaternion' Perspective = require './perspective' - -forward_key = "UP" -backward_key = "DOWN" -turn_left_key = "LEFT" -turn_right_key = "RIGHT" -shoot_key = "SPACE" -jump_key = "CTRL" -push_key = "SHIFT" -look_up_key = "HOME" -look_down_key = "END" -view_key = "PAGEDOWN" class Player extends Bot @@ -42,6 +31,7 @@ class Player extends Bot shoot: 'enter' jump: 'space' view: 'c' + push: 'shift' @look_action = null @look_angle = 0.0 @@ -55,16 +45,11 @@ class Player extends Bot @addAction new Action @, Action.LOOK_DOWN, "look down", 220 @addAction new Action @, Action.LOOK_RESET, "look reset", 60 - # @addEventWithName "keyset" - # @addEventWithName "keyset failed" @addEventWithName "landed" @projection = new Perspective 90.0 @projection.updateViewport() - # @projection.getLight().setCutoff 90.0 - # @projection.getLight().setAttenuation 1.0, 0.0, 0.05 - # 00000000 00000000 0000000 000 00000000 0000000 000000000 000 0000000 000 000 # 000 000 000 000 000 000 000 000 000 000 000 000 000 0000 000 # 00000000 0000000 000 000 000 0000000 000 000 000 000 000 000 0 000 @@ -323,12 +308,15 @@ class Player extends Bot # 000 000 00000000 000 modKeyComboEventDown: (mod, key, combo, event) -> + # log "player.modKeyComboEventDown mod:#{mod} key:#{key} combo:#{combo}" - switch combo + + switch key when @key.forward, @key.backward + @push = mod == @key.push @move = true # try to move as long as the key is not released if not @move_action? - @new_dir_sgn = @dir_sgn = (combo == @key.backward) and -1 or 1 + @new_dir_sgn = @dir_sgn = (key == @key.backward) and -1 or 1 @moveBot() # perform new move action (depending on environment) else if @move_action.id == Action.JUMP and @move_action.getRelativeTime() < 1 @@ -339,11 +327,11 @@ class Player extends Bot Timer.removeAction @move_action @move_action = action Timer.addAction @move_action - @new_dir_sgn = (combo == @key.backward) and -1 or 1 + @new_dir_sgn = (key == @key.backward) and -1 or 1 return true when @key.left, @key.right - @rotate = (combo == @key.left) and Action.TURN_LEFT or Action.TURN_RIGHT + @rotate = (key == @key.left) and Action.TURN_LEFT or Action.TURN_RIGHT if not @rotate_action? and not @spiked # player is not performing a rotation and unspiked @rotate_action = @getActionWithId @rotate Timer.addAction @rotate_action @@ -388,7 +376,7 @@ class Player extends Bot when @key.lookUp, @key.lookDown if not @look_action - @look_action = @getActionWithId (combo == @key.lookUp) and Action.LOOK_UP or Action.LOOK_DOWN + @look_action = @getActionWithId (key == @key.lookUp) and Action.LOOK_UP or Action.LOOK_DOWN @look_action.reset() Timer.addAction @look_action return true @@ -406,8 +394,9 @@ class Player extends Bot # 000 000 00000000 0000000 00000000 000 000 0000000 00000000 modKeyComboEventUp: (mod, key, combo, event) -> + @push = false if @key.push == 'shift' # log "player.modKeyComboEventUp mod:#{mod} key:#{key} combo:#{combo}" - switch combo + switch key when @key.shoot Timer.removeAction @getActionWithId Action.SHOOT @shoot = false diff --git a/coffee/pushable.coffee b/coffee/pushable.coffee index 6f6f29b..da2b9e5 100644 --- a/coffee/pushable.coffee +++ b/coffee/pushable.coffee @@ -5,9 +5,10 @@ # 000 0000000 0000000 000 000 000 000 0000000 0000000 00000000 log = require '/Users/kodi/s/ko/js/tools/log' +Vector = require './lib/vector' Item = require './item' Action = require './action' -Vector = require './lib/vector' +Timer = require './timer' class Pushable extends Item @@ -36,7 +37,7 @@ class Pushable extends Item @move_action = pushAction @direction = dir - pushAction.setDuration world.unmapMsTime duration + pushAction.duration = world.unmapMsTime duration Timer.addAction pushAction initAction: (action) -> diff --git a/coffee/stone.coffee b/coffee/stone.coffee index c90d876..742d206 100644 --- a/coffee/stone.coffee +++ b/coffee/stone.coffee @@ -10,7 +10,7 @@ class Stone extends Pushable constructor: (@slippery=false) -> - @geom = new THREE.BoxGeometry 1,1,1 + @geom = new THREE.BoxGeometry 0.99,0.99,0.99 @mat = new THREE.MeshPhongMaterial color: 0xff8800 @@ -21,8 +21,6 @@ class Stone extends Pushable shininess: 0.9 @mesh = new THREE.Mesh @geom, @mat - world.scene.add @mesh - @mesh.matrixAutoUpdate = true super isSlippery: -> return @slippery diff --git a/coffee/world.coffee b/coffee/world.coffee index 00cbf6c..390afdf 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -22,6 +22,7 @@ Timer = require './timer' Actor = require './actor' Action = require './action' TmpObject = require './tmpobject' +Pushable = require './pushable' Quaternion = require './lib/quaternion' Vector = require './lib/vector' Pos = require './lib/pos' @@ -817,12 +818,13 @@ class World extends Actor return true mayObjectPushToPos: (object, pos, duration) -> + 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 direction = pos.minus object.getPos() # direction from object to pushable object - return false if @isInvalidPos pos.plus @direction + return false if @isInvalidPos pos.plus direction objectAtNewPos = @getOccupantAtPos pos.plus direction if objectAtNewPos @@ -836,9 +838,10 @@ class World extends Actor else return false pushableObject = @getOccupantAtPos pos - - if pushableObject? and pushableObject instanceof Pushable and - pushableObject instanceof MotorGear # bad + log "pushableObject #{pushableObject?.name}" + if pushableObject? and pushableObject instanceof Pushable #and + # pushableObject instanceof MotorGear # bad + log 'pushedByObjectInDirection' pushableObject.pushedByObjectInDirection object, direction, duration return true