jump
This commit is contained in:
parent
24af8b6cce
commit
43c9898aff
|
@ -72,7 +72,7 @@ class Action
|
||||||
# log 'keeping rest', @current
|
# log 'keeping rest', @current
|
||||||
|
|
||||||
reset: () ->
|
reset: () ->
|
||||||
log "action.reset #{@name}"
|
# log "action.reset #{@name}"
|
||||||
@start = 0 # world time
|
@start = 0 # world time
|
||||||
@rest = 0
|
@rest = 0
|
||||||
@last = 0 # relative (ms since @start)
|
@last = 0 # relative (ms since @start)
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Actor extends Emitter
|
||||||
# 00000000 0 00000000 000 000 000
|
# 00000000 0 00000000 000 000 000
|
||||||
|
|
||||||
addEventWithName: (eventName) ->
|
addEventWithName: (eventName) ->
|
||||||
log "Actor.addEventWithName #{@name} eventName:#{eventName}"
|
# log "Actor.addEventWithName #{@name} eventName:#{eventName}"
|
||||||
if @getEventWithName eventName # to be removed
|
if @getEventWithName eventName # to be removed
|
||||||
log "Actor.addEventWithName [WARNING] '#{eventName}' already in use!"
|
log "Actor.addEventWithName [WARNING] '#{eventName}' already in use!"
|
||||||
return -1; # shouldn't happen anyway :-)
|
return -1; # shouldn't happen anyway :-)
|
||||||
|
|
|
@ -317,7 +317,7 @@ class Bot extends Pushable
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
|
|
||||||
log "Bot.finishAction #{action.id} #{action.name}"
|
log "Bot.finishAction #{action.id} #{action.name}" if action.name != 'noop'
|
||||||
|
|
||||||
switch action.id
|
switch action.id
|
||||||
when Action.NOOP, Action.SHOOT
|
when Action.NOOP, Action.SHOOT
|
||||||
|
@ -327,7 +327,6 @@ class Bot extends Pushable
|
||||||
return
|
return
|
||||||
when Action.TURN_LEFT, Action.TURN_RIGHT
|
when Action.TURN_LEFT, Action.TURN_RIGHT
|
||||||
@rotate_action = null
|
@rotate_action = null
|
||||||
log 'rotate_action done'
|
|
||||||
if @move_action # bot currently performing a move action -> store rotation in @rest_orientation
|
if @move_action # bot currently performing a move action -> store rotation in @rest_orientation
|
||||||
@rest_orientation = @rest_orientation.mul @rotate_orientation
|
@rest_orientation = @rest_orientation.mul @rotate_orientation
|
||||||
@rotate_orientation.reset()
|
@rotate_orientation.reset()
|
||||||
|
@ -368,7 +367,7 @@ class Bot extends Pushable
|
||||||
# 000 000 000 000 000 0000000 000 000 00000000 0000000
|
# 000 000 000 000 000 0000000 000 000 00000000 0000000
|
||||||
|
|
||||||
actionFinished: (action) ->
|
actionFinished: (action) ->
|
||||||
log "bot.actionFinished #{action.name} #{action.id}"
|
# log "bot.actionFinished #{action.name} #{action.id}"a
|
||||||
|
|
||||||
# if @isDead()
|
# if @isDead()
|
||||||
# log "DIE!"
|
# log "DIE!"
|
||||||
|
@ -410,7 +409,7 @@ class Bot extends Pushable
|
||||||
@move_action = @getActionWithId Action.CLIMB_UP
|
@move_action = @getActionWithId Action.CLIMB_UP
|
||||||
world.playSound 'BOT_LAND', @getPos(), 0.5
|
world.playSound 'BOT_LAND', @getPos(), 0.5
|
||||||
else if world.isUnoccupiedPos @position.plus @getDown() # below will be empty
|
else if world.isUnoccupiedPos @position.plus @getDown() # below will be empty
|
||||||
log 'below will be empty!'
|
# log 'below will be empty!'
|
||||||
if @move # sticky if moving
|
if @move # sticky if moving
|
||||||
if world.isUnoccupiedPos @position.plus @getDir()
|
if world.isUnoccupiedPos @position.plus @getDir()
|
||||||
# forward will be empty
|
# forward will be empty
|
||||||
|
@ -425,26 +424,24 @@ class Bot extends Pushable
|
||||||
@move_action = @getActionWithId Action.CLIMB_UP
|
@move_action = @getActionWithId Action.CLIMB_UP
|
||||||
|
|
||||||
if @move_action == null
|
if @move_action == null
|
||||||
log 'bot.actionFinished fall!'
|
# log 'bot.actionFinished fall!'
|
||||||
@move_action = @getActionWithId Action.FALL
|
@move_action = @getActionWithId Action.FALL
|
||||||
# @move_action.takeRest action
|
# @move_action.takeRest action
|
||||||
|
|
||||||
else if action.id == Action.FALL or action.id == Action.FALL_FORWARD # landed
|
else if action.id == Action.FALL or action.id == Action.FALL_FORWARD # landed
|
||||||
log 'fall|forward!'
|
|
||||||
if @ == world.player
|
if @ == world.player
|
||||||
world.playSound 'BOT_LAND'
|
world.playSound 'BOT_LAND'
|
||||||
else
|
else
|
||||||
world.playSound 'BOT_LAND', @getPos()
|
world.playSound 'BOT_LAND', @getPos()
|
||||||
|
|
||||||
if @move_action
|
if @move_action
|
||||||
log "add move_action! #{@move_action.name}"
|
# log "add move_action! #{@move_action.name}"
|
||||||
Timer.addAction @move_action
|
Timer.addAction @move_action
|
||||||
return
|
return
|
||||||
|
|
||||||
return if @rotate_action
|
return if @rotate_action
|
||||||
|
|
||||||
if @move or @jump
|
if @move or @jump
|
||||||
log '!move or jump!'
|
|
||||||
@moveBot()
|
@moveBot()
|
||||||
else
|
else
|
||||||
@dir_sgn = 1
|
@dir_sgn = 1
|
||||||
|
@ -471,7 +468,6 @@ class Bot extends Pushable
|
||||||
@move_action = @getActionWithId Action.JUMP
|
@move_action = @getActionWithId Action.JUMP
|
||||||
else if @move
|
else if @move
|
||||||
if world.isUnoccupiedPos forwardPos # forward is empty
|
if world.isUnoccupiedPos forwardPos # forward is empty
|
||||||
log 'forward is empty'
|
|
||||||
if world.isUnoccupiedPos forwardPos.plus @getDown()
|
if world.isUnoccupiedPos forwardPos.plus @getDown()
|
||||||
# below forward also empty
|
# below forward also empty
|
||||||
@move_action = @getActionWithId Action.CLIMB_DOWN
|
@move_action = @getActionWithId Action.CLIMB_DOWN
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Item extends Actor
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
|
@name = @constructor.name
|
||||||
world.scene.add @mesh if @mesh?
|
world.scene.add @mesh if @mesh?
|
||||||
@position = new Vector
|
@position = new Vector
|
||||||
@current_position = new Vector
|
@current_position = new Vector
|
||||||
|
|
|
@ -40,8 +40,8 @@ class Player extends Bot
|
||||||
lookUp: 'up'
|
lookUp: 'up'
|
||||||
lookDown: 'down'
|
lookDown: 'down'
|
||||||
shoot: 'space'
|
shoot: 'space'
|
||||||
jump: 'j'
|
jump: 'enter'
|
||||||
view: 'v'
|
view: 'c'
|
||||||
|
|
||||||
@look_action = null
|
@look_action = null
|
||||||
@look_angle = 0.0
|
@look_angle = 0.0
|
||||||
|
@ -127,7 +127,7 @@ class Player extends Bot
|
||||||
@projection.setPosition @projection.getPosition().mul(1.0 - posDelta).plus camPos.mul posDelta
|
@projection.setPosition @projection.getPosition().mul(1.0 - posDelta).plus camPos.mul posDelta
|
||||||
|
|
||||||
if @look_angle
|
if @look_angle
|
||||||
log "look_angle #{@look_angle}"
|
# log "look_angle #{@look_angle}"
|
||||||
@projection.setXVector playerDir.cross(playerUp).normal()
|
@projection.setXVector playerDir.cross(playerUp).normal()
|
||||||
rot = Quaternion.rotationAroundVector @look_angle, @projection.getXVector()
|
rot = Quaternion.rotationAroundVector @look_angle, @projection.getXVector()
|
||||||
@projection.setYVector rot.rotate playerUp
|
@projection.setYVector rot.rotate playerUp
|
||||||
|
@ -135,7 +135,7 @@ class Player extends Bot
|
||||||
else
|
else
|
||||||
# smooth camera rotation a little bit
|
# smooth camera rotation a little bit
|
||||||
lookDelta = 0.3
|
lookDelta = 0.3
|
||||||
newLookVector = @projection.getZVector().mul(1.0 - lookDelta).plus playerDir.mul lookDelta
|
newLookVector = @projection.getZVector().mul(1.0 - lookDelta).plus (playerDir.minus(@getCurrentUp().mul(0.2)).normal()).mul lookDelta
|
||||||
newLookVector.normalize()
|
newLookVector.normalize()
|
||||||
|
|
||||||
@projection.setZVector newLookVector
|
@projection.setZVector newLookVector
|
||||||
|
@ -181,11 +181,9 @@ class Player extends Bot
|
||||||
botToCameraNormal = botToCamera.normal()
|
botToCameraNormal = botToCamera.normal()
|
||||||
|
|
||||||
# if camera below bot, rotate up
|
# if camera below bot, rotate up
|
||||||
if botToCameraNormal.dot(playerUp) < 0
|
if botToCameraNormal.dot(playerUp) < 0 # calculate angle between player to camera vector and player up vector
|
||||||
# calculate angle between player to camera vector and player up vector
|
|
||||||
verticalAngle = Vector.RAD2DEG Math.acos(clamp(-1.0, 1.0, botToCameraNormal.dot playerUp))
|
verticalAngle = Vector.RAD2DEG Math.acos(clamp(-1.0, 1.0, botToCameraNormal.dot playerUp))
|
||||||
log "verticalAngle #{verticalAngle}"
|
rotQuat = Quaternion.rotationAroundVector(verticalAngle/400.0, botToCameraNormal.cross(playerUp))
|
||||||
rotQuat = Quaternion.rotationAroundVector(verticalAngle/40.0, botToCameraNormal.cross(playerUp))
|
|
||||||
botToCamera = rotQuat.rotate botToCamera
|
botToCamera = rotQuat.rotate botToCamera
|
||||||
botToCameraNormal = botToCamera.normal()
|
botToCameraNormal = botToCamera.normal()
|
||||||
camPos = playerPos.plus botToCamera
|
camPos = playerPos.plus botToCamera
|
||||||
|
@ -199,7 +197,6 @@ class Player extends Bot
|
||||||
botToCamera = camPos.minus playerPos
|
botToCamera = camPos.minus playerPos
|
||||||
botToCameraNormal = botToCamera.normal()
|
botToCameraNormal = botToCamera.normal()
|
||||||
rotFactor = 0.5 / (wall_distance-0.2)
|
rotFactor = 0.5 / (wall_distance-0.2)
|
||||||
log "rotFactor #{rotFactor}"
|
|
||||||
|
|
||||||
# try view bot from behind
|
# try view bot from behind
|
||||||
# calculate horizontal angle between bot orientation and vector to camera
|
# calculate horizontal angle between bot orientation and vector to camera
|
||||||
|
@ -207,16 +204,13 @@ class Player extends Bot
|
||||||
horizontalAngle = Vector.RAD2DEG Math.acos(clamp(-1.0, 1.0, -playerDir.dot mappedToXZ))
|
horizontalAngle = Vector.RAD2DEG Math.acos(clamp(-1.0, 1.0, -playerDir.dot mappedToXZ))
|
||||||
if botToCameraNormal.dot(playerLeft) < 0
|
if botToCameraNormal.dot(playerLeft) < 0
|
||||||
horizontalAngle = -horizontalAngle
|
horizontalAngle = -horizontalAngle
|
||||||
log "horizontalAngle #{horizontalAngle}"
|
|
||||||
rotQuat = Quaternion.rotationAroundVector horizontalAngle/(rotFactor*400.0), playerUp
|
rotQuat = Quaternion.rotationAroundVector horizontalAngle/(rotFactor*400.0), playerUp
|
||||||
camPos = playerPos.plus rotQuat.rotate botToCamera
|
camPos = playerPos.plus rotQuat.rotate botToCamera
|
||||||
|
|
||||||
botToCamera = camPos.minus playerPos
|
botToCamera = camPos.minus playerPos
|
||||||
botToCameraNormal = botToCamera.normal()
|
botToCameraNormal = botToCamera.normal()
|
||||||
|
|
||||||
# finally, set the position
|
@projection.setPosition camPos # finally, set the position
|
||||||
|
|
||||||
@projection.setPosition camPos
|
|
||||||
|
|
||||||
# slowly adjust look direction by interpolating current and desired directions
|
# slowly adjust look direction by interpolating current and desired directions
|
||||||
lookDelta = @projection.getZVector().dot botToCameraNormal
|
lookDelta = @projection.getZVector().dot botToCameraNormal
|
||||||
|
@ -225,7 +219,7 @@ class Player extends Bot
|
||||||
newLookVector.normalize()
|
newLookVector.normalize()
|
||||||
|
|
||||||
# slowly adjust up vector by interpolating current and desired up vectors
|
# slowly adjust up vector by interpolating current and desired up vectors
|
||||||
upDelta = @projection.getYVector().dot playerUp
|
upDelta = 1.5-@projection.getYVector().dot playerUp
|
||||||
upDelta *= upDelta / 100.0
|
upDelta *= upDelta / 100.0
|
||||||
newUpVector = @projection.getYVector().mul(1.0-upDelta).plus playerUp.mul(upDelta)
|
newUpVector = @projection.getYVector().mul(1.0-upDelta).plus playerUp.mul(upDelta)
|
||||||
newUpVector.normalize()
|
newUpVector.normalize()
|
||||||
|
@ -350,7 +344,6 @@ class Player extends Bot
|
||||||
return true
|
return true
|
||||||
|
|
||||||
when @key.left, @key.right
|
when @key.left, @key.right
|
||||||
log 'rotate', combo
|
|
||||||
@rotate = (combo == @key.left) and Action.TURN_LEFT or Action.TURN_RIGHT
|
@rotate = (combo == @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
|
if not @rotate_action? and not @spiked # player is not performing a rotation and unspiked
|
||||||
@rotate_action = @getActionWithId @rotate
|
@rotate_action = @getActionWithId @rotate
|
||||||
|
|
|
@ -14,10 +14,10 @@ class Timer
|
||||||
@init: ->
|
@init: ->
|
||||||
@eventID = world.addEventWithName 'timer'
|
@eventID = world.addEventWithName 'timer'
|
||||||
@event = world.getEventWithId @eventID
|
@event = world.getEventWithId @eventID
|
||||||
log "Timer.init @eventID:#{@eventID} #{@event.name}"
|
# log "Timer.init @eventID:#{@eventID} #{@event.name}"
|
||||||
|
|
||||||
@removeActionsOfObject: (o) ->
|
@removeActionsOfObject: (o) ->
|
||||||
log "Timer.removeActionsOfObject"
|
# log "Timer.removeActionsOfObject"
|
||||||
@event.removeActionsOfObject o
|
@event.removeActionsOfObject o
|
||||||
|
|
||||||
@addAction: (a) ->
|
@addAction: (a) ->
|
||||||
|
@ -25,7 +25,7 @@ class Timer
|
||||||
@event.addAction a
|
@event.addAction a
|
||||||
|
|
||||||
@removeAction: (a) ->
|
@removeAction: (a) ->
|
||||||
log "Timer.removeAction #{a.name}"
|
# log "Timer.removeAction #{a.name}"
|
||||||
a.reset()
|
a.reset()
|
||||||
@event.removeAction a
|
@event.removeAction a
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ class World extends Actor
|
||||||
|
|
||||||
constructor: (@view) ->
|
constructor: (@view) ->
|
||||||
|
|
||||||
@speed = 4
|
@speed = 6
|
||||||
@raster_size = 0.05
|
@raster_size = 0.05
|
||||||
# @camera_mode = World.CAMERA_INSIDE
|
# @camera_mode = World.CAMERA_INSIDE
|
||||||
@camera_mode = World.CAMERA_BEHIND
|
@camera_mode = World.CAMERA_BEHIND
|
||||||
|
@ -842,7 +842,7 @@ class World extends Actor
|
||||||
if @isInvalidPos pos
|
if @isInvalidPos pos
|
||||||
return true
|
return true
|
||||||
if @getOccupantAtPos pos
|
if @getOccupantAtPos pos
|
||||||
log "isOccupiedPos occupant: #{@getOccupantAtPos(pos).name} at pos:", pos
|
# log "isOccupiedPos occupant: #{@getOccupantAtPos(pos).name} at pos:", new Pos pos
|
||||||
return true
|
return true
|
||||||
|
|
||||||
mayObjectPushToPos: (object, pos, duration) ->
|
mayObjectPushToPos: (object, pos, duration) ->
|
||||||
|
@ -935,10 +935,13 @@ class World extends Actor
|
||||||
# 000 000 000 000
|
# 000 000 000 000
|
||||||
# 000 000 00000000 000
|
# 000 000 00000000 000
|
||||||
|
|
||||||
modKeyComboEventUp: (mod, key, combo, event) ->
|
|
||||||
@player?.modKeyComboEventUp mod, key, combo, event
|
|
||||||
|
|
||||||
modKeyComboEventDown: (mod, key, combo, event) ->
|
modKeyComboEventDown: (mod, key, combo, event) ->
|
||||||
@player?.modKeyComboEventDown mod, key, combo, event
|
return if @player?.modKeyComboEventDown mod, key, combo, event
|
||||||
|
switch combo
|
||||||
|
when '=' then @speed = Math.min 10, @speed+1
|
||||||
|
when '-' then @speed = Math.max 1, @speed-1
|
||||||
|
|
||||||
|
modKeyComboEventUp: (mod, key, combo, event) ->
|
||||||
|
return if @player?.modKeyComboEventUp mod, key, combo, event
|
||||||
|
|
||||||
module.exports = World
|
module.exports = World
|
||||||
|
|
Loading…
Reference in New Issue
Block a user