action
This commit is contained in:
parent
5f4d722c0b
commit
4a251fe5e2
|
@ -62,10 +62,9 @@ class Action
|
||||||
perform: () -> @object.performAction @
|
perform: () -> @object.performAction @
|
||||||
finish: () -> @object.finishAction @
|
finish: () -> @object.finishAction @
|
||||||
finished: () ->
|
finished: () ->
|
||||||
log "Action.finished #{@name} #{@object?.actionFinished?}"
|
# log "Action.finished #{@name} #{@object?.actionFinished?}"
|
||||||
@object.actionFinished @
|
@object.actionFinished @
|
||||||
return if @deleted
|
return if @deleted
|
||||||
|
|
||||||
if @current == @getDuration() # if keepRest wasn't called -> reset start and current values
|
if @current == @getDuration() # if keepRest wasn't called -> reset start and current values
|
||||||
@reset()
|
@reset()
|
||||||
|
|
||||||
|
|
|
@ -292,7 +292,7 @@ class Bot extends Pushable
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
|
|
||||||
# log "Bot.finishAction #{action.id} #{action.name}"
|
log "Bot.finishAction #{action.id} #{action.name}"
|
||||||
|
|
||||||
switch action.id
|
switch action.id
|
||||||
when Action.NOOP, Action.SHOOT
|
when Action.NOOP, Action.SHOOT
|
||||||
|
@ -300,8 +300,9 @@ class Bot extends Pushable
|
||||||
when Action.PUSH
|
when Action.PUSH
|
||||||
super action
|
super action
|
||||||
return
|
return
|
||||||
when Action.TURN_LEFT or 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()
|
||||||
|
@ -357,8 +358,8 @@ class Bot extends Pushable
|
||||||
@startTimedAction @getActionWithId(Action.NOOP), 0
|
@startTimedAction @getActionWithId(Action.NOOP), 0
|
||||||
return
|
return
|
||||||
|
|
||||||
if action.id == Action.PUSH or not @direction.isZero()
|
if action.id == Action.PUSH #or action.id == Action.FALL # not @direction.isZero()
|
||||||
log 'super action!'
|
log 'super (Pushable) action!'
|
||||||
super action
|
super action
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -384,7 +385,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.minus @getUp() # below will be empty
|
else if world.isUnoccupiedPos @position.minus @getUp() # 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
|
||||||
|
|
|
@ -67,18 +67,12 @@ class Event
|
||||||
@save_actions.pop()
|
@save_actions.pop()
|
||||||
|
|
||||||
addFinishedAction: (action) ->
|
addFinishedAction: (action) ->
|
||||||
log "Event.addFinishedAction #{action.name} #{@finished_actions.length}"
|
# log "Event.addFinishedAction #{action.name} #{@finished_actions.length}"
|
||||||
@finished_actions.push action
|
@finished_actions.push action
|
||||||
|
|
||||||
finishActions: () ->
|
finishActions: () ->
|
||||||
while @finished_actions.length
|
while @finished_actions.length
|
||||||
log "Event.finishActions pop:#{@finished_actions.length}", last(@finished_actions).name
|
# log "Event.finishActions pop:#{@finished_actions.length}", last(@finished_actions).name
|
||||||
@finished_actions.pop().finished()
|
@finished_actions.pop().finished()
|
||||||
# action = last @finished_actions
|
|
||||||
# action.finished()
|
|
||||||
# if @finished_actions.length and action == last @finished_actions
|
|
||||||
# log 'pop finished'
|
|
||||||
# @finished_actions.pop()
|
|
||||||
# log "Event.finishActions actions:#{@actions.length}" if @actions.length > 1 or @actions[0]?.name != 'noop'
|
|
||||||
|
|
||||||
module.exports = Event
|
module.exports = Event
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Item extends Actor
|
||||||
isSlippery: -> false
|
isSlippery: -> false
|
||||||
|
|
||||||
setPosition: (x,y,z) ->
|
setPosition: (x,y,z) ->
|
||||||
@position = new Vector x,y,z
|
@position = @current_position = new Vector x,y,z
|
||||||
@mesh?.position.copy @position
|
@mesh?.position.copy @position
|
||||||
|
|
||||||
getPos: -> new Pos @current_position
|
getPos: -> new Pos @current_position
|
||||||
|
|
|
@ -13,18 +13,18 @@ class Pos
|
||||||
constructor: (x=0, y=0, z=0) ->
|
constructor: (x=0, y=0, z=0) ->
|
||||||
|
|
||||||
if (x instanceof Vector) or (x instanceof Pos)
|
if (x instanceof Vector) or (x instanceof Pos)
|
||||||
@x = parseInt x.x
|
@x = Math.round x.x
|
||||||
@y = parseInt x.y
|
@y = Math.round x.y
|
||||||
@z = parseInt x.z
|
@z = Math.round x.z
|
||||||
else if Array.isArray x
|
else if Array.isArray x
|
||||||
@x = parseInt x[0]
|
@x = Math.round x[0]
|
||||||
@y = parseInt x[1]
|
@y = Math.round x[1]
|
||||||
@z = parseInt x[2]
|
@z = Math.round x[2]
|
||||||
else
|
else
|
||||||
@x = parseInt x
|
@x = Math.round x
|
||||||
@y = parseInt y
|
@y = Math.round y
|
||||||
@z = parseInt z
|
@z = Math.round z
|
||||||
# log "Pos #{x} #{y} #{z}", @
|
log "Pos #{x} #{y} #{z}", @
|
||||||
if Number.isNaN @x
|
if Number.isNaN @x
|
||||||
throw new Error
|
throw new Error
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,7 @@ class Vector
|
||||||
@
|
@
|
||||||
|
|
||||||
xyperp: -> new Vector -@y, @x
|
xyperp: -> new Vector -@y, @x
|
||||||
round: -> new Vector @rint(@x), @rint(@y), @rint(@z), @w
|
round: -> new Vector Math.round(@x), Math.round(@y), Math.round(@z), @w
|
||||||
rint: (n) ->
|
|
||||||
if n < 0 then Math.floor(n - 0.5)
|
|
||||||
else Math.round n
|
|
||||||
|
|
||||||
xyangle: (v) ->
|
xyangle: (v) ->
|
||||||
thisXY = new Vector(@x, @y).normal()
|
thisXY = new Vector(@x, @y).normal()
|
||||||
|
|
|
@ -23,13 +23,9 @@ class Kiki extends Stage
|
||||||
@elem.style.bottom = '0'
|
@elem.style.bottom = '0'
|
||||||
@elem.style.background = "#004"
|
@elem.style.background = "#004"
|
||||||
@view.appendChild @elem
|
@view.appendChild @elem
|
||||||
log 'init KikiWorld', @view
|
|
||||||
@world = World.init @view
|
@world = World.init @view
|
||||||
|
|
||||||
@elem.appendChild @world.renderer.domElement
|
@elem.appendChild @world.renderer.domElement
|
||||||
|
@view.focus()
|
||||||
log 'hello world'
|
|
||||||
|
|
||||||
@animate()
|
@animate()
|
||||||
|
|
||||||
# 0000000 000000000 00000000 00000000
|
# 0000000 000000000 00000000 00000000
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Player extends Bot
|
||||||
when Action.JUMP_FORWARD
|
when Action.JUMP_FORWARD
|
||||||
@current_position = @position.plus @getDir().mul(1.0 - Math.cos(Math.PI/2 * relTime)).plus @getUp().mul Math.cos(Math.PI/2 - Math.PI/2 * relTime)
|
@current_position = @position.plus @getDir().mul(1.0 - Math.cos(Math.PI/2 * relTime)).plus @getUp().mul Math.cos(Math.PI/2 - Math.PI/2 * relTime)
|
||||||
when Action.FALL_FORWARD
|
when Action.FALL_FORWARD
|
||||||
@current_position = @position.plus @getDir().mul(Math.cos(Math.PI/2 - Math.PI/2 * relTime)).plus @getUp().mul -(1.0 - Math.cos(Math.PI/2 * relTime))
|
@current_position = @position.plus @getDir().mul(Math.cos(Math.PI/2 - Math.PI/2 * relTime)).plus @getUp().mul -(1.0 - Math.cos Math.PI/2 * relTime)
|
||||||
|
|
||||||
# 00000000 00000000 0000000 000 00000000 0000000 000000000 000 0000000 000 000
|
# 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
|
# 000 000 000 000 000 000 000 000 000 000 000 000 000 0000 000
|
||||||
|
@ -85,7 +85,7 @@ class Player extends Bot
|
||||||
# 000 000 000 000 000 000 000 000 000 000 000 000 000 000 0000
|
# 000 000 000 000 000 000 000 000 000 000 000 000 000 000 0000
|
||||||
# 000 000 000 0000000 0000000 00000000 0000000 000 000 0000000 000 000
|
# 000 000 000 0000000 0000000 00000000 0000000 000 000 0000000 000 000
|
||||||
|
|
||||||
getProjection: () ->
|
getInsideProjection: () ->
|
||||||
|
|
||||||
# smooth camera movement a little bit
|
# smooth camera movement a little bit
|
||||||
posDelta = world.getSpeed() / 10.0
|
posDelta = world.getSpeed() / 10.0
|
||||||
|
@ -142,7 +142,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).minus playerDir.mul lookDelta
|
newLookVector = @projection.getZVector().mul(1.0 - lookDelta).plus playerDir.mul lookDelta
|
||||||
newLookVector.normalize()
|
newLookVector.normalize()
|
||||||
|
|
||||||
@projection.setZVector newLookVector
|
@projection.setZVector newLookVector
|
||||||
|
@ -180,11 +180,11 @@ class Player extends Bot
|
||||||
if cameraBotDistance >= desiredDistance
|
if cameraBotDistance >= desiredDistance
|
||||||
difference = cameraBotDistance - desiredDistance
|
difference = cameraBotDistance - desiredDistance
|
||||||
delta = difference*difference/400.0 # weight for following speed
|
delta = difference*difference/400.0 # weight for following speed
|
||||||
cameraPos = cameraPos.mul(1.0 - delta).plus playerPos.mul delta
|
cameraPos = cameraPos.mul(1.0-delta).plus playerPos.mul delta
|
||||||
else
|
else
|
||||||
difference = desiredDistance - cameraBotDistance
|
difference = desiredDistance - cameraBotDistance
|
||||||
delta = difference/20.0 # weight for negative following speed
|
delta = difference/20.0 # weight for negative following speed
|
||||||
cameraPos = cameraPos.mul(1.0 - delta).plus (playerPos.plus botToCamera.normal().mul desiredDistance).mul delta
|
cameraPos = cameraPos.mul(1.0-delta).plus (playerPos.plus botToCamera.normal().mul desiredDistance).mul delta
|
||||||
|
|
||||||
# ____________________________________________________ refining camera position
|
# ____________________________________________________ refining camera position
|
||||||
# second, rotate around bot
|
# second, rotate around bot
|
||||||
|
@ -221,7 +221,7 @@ class Player extends Bot
|
||||||
if botToCameraNormal.dot(playerRight) > 0
|
if botToCameraNormal.dot(playerRight) > 0
|
||||||
horizontalAngle = -horizontalAngle
|
horizontalAngle = -horizontalAngle
|
||||||
|
|
||||||
cameraPos = playerPos.plus Quaternion.rotationAroundVector(horizontalAngle / (rotFactor * 400.0), playerUp).rotate botToCamera
|
cameraPos = playerPos.plus Quaternion.rotationAroundVector(horizontalAngle/(rotFactor*400.0), playerUp).rotate botToCamera
|
||||||
|
|
||||||
botToCamera = cameraPos.minus playerPos
|
botToCamera = cameraPos.minus playerPos
|
||||||
botToCameraNormal = botToCamera.normal()
|
botToCameraNormal = botToCamera.normal()
|
||||||
|
@ -235,7 +235,8 @@ class Player extends Bot
|
||||||
# slowly adjust look direction by interpolating current and desired directions
|
# slowly adjust look direction by interpolating current and desired directions
|
||||||
lookDelta = 2.0 - @projection.getZVector().dot botToCameraNormal
|
lookDelta = 2.0 - @projection.getZVector().dot botToCameraNormal
|
||||||
lookDelta *= lookDelta / 30.0
|
lookDelta *= lookDelta / 30.0
|
||||||
newLookVector = @projection.getZVector().mul(1.0 - lookDelta).plus botToCameraNormal.mul(lookDelta)
|
# newLookVector = @projection.getZVector().mul(1.0-lookDelta).plus botToCameraNormal.mul(lookDelta)
|
||||||
|
newLookVector = @projection.getZVector().mul(1.0-lookDelta).plus botToCameraNormal.neg().mul(lookDelta)
|
||||||
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
|
||||||
|
@ -307,7 +308,7 @@ class Player extends Bot
|
||||||
@look_action = null
|
@look_action = null
|
||||||
@look_angle = 0.0
|
@look_angle = 0.0
|
||||||
else
|
else
|
||||||
if action.id == @move_action # move finished, update direction
|
if action.id == @move_action?.id # move finished, update direction
|
||||||
@dir_sgn = @new_dir_sgn
|
@dir_sgn = @new_dir_sgn
|
||||||
|
|
||||||
if action.id != Action.LOOK_UP and action.id != Action.LOOK_DOWN
|
if action.id != Action.LOOK_UP and action.id != Action.LOOK_DOWN
|
||||||
|
@ -356,10 +357,13 @@ 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
|
||||||
Timer.addAction @rotate_action
|
Timer.addAction @rotate_action
|
||||||
|
else
|
||||||
|
log 'already rotating!'
|
||||||
return true
|
return true
|
||||||
|
|
||||||
when @key.jump
|
when @key.jump
|
||||||
|
|
|
@ -158,8 +158,8 @@ class World extends Actor
|
||||||
|
|
||||||
@levelList = [
|
@levelList = [
|
||||||
# intro
|
# intro
|
||||||
# "start",
|
"start",
|
||||||
"steps",
|
# "steps",
|
||||||
#"move", "electro", "elevate",
|
#"move", "electro", "elevate",
|
||||||
# "throw",
|
# "throw",
|
||||||
# easy
|
# easy
|
||||||
|
@ -384,6 +384,7 @@ class World extends Actor
|
||||||
|
|
||||||
isValidPos: (pos) ->
|
isValidPos: (pos) ->
|
||||||
p = new Pos pos
|
p = new Pos pos
|
||||||
|
log 'isValidPos', p
|
||||||
p.x >= 0 and p.x < @size.x and p.y >= 0 and p.y < @size.y and p.z >= 0 and p.z < @size.z
|
p.x >= 0 and p.x < @size.x and p.y >= 0 and p.y < @size.y and p.z >= 0 and p.z < @size.z
|
||||||
|
|
||||||
isInvalidPos: (pos) -> not @isValidPos pos
|
isInvalidPos: (pos) -> not @isValidPos pos
|
||||||
|
@ -555,7 +556,7 @@ class World extends Actor
|
||||||
@initCage()
|
@initCage()
|
||||||
|
|
||||||
getCellAtPos: (pos) -> return @cells[@posToIndex(pos)] if @isValidPos pos
|
getCellAtPos: (pos) -> return @cells[@posToIndex(pos)] if @isValidPos pos
|
||||||
getBotAtPos: (pos) -> @getObjectOfTypeAtPos KikiBot, pos
|
getBotAtPos: (pos) -> @getObjectOfTypeAtPos KikiBot, new Pos pos
|
||||||
|
|
||||||
posToIndex: (pos) ->
|
posToIndex: (pos) ->
|
||||||
p = new Pos pos
|
p = new Pos pos
|
||||||
|
@ -599,8 +600,10 @@ class World extends Actor
|
||||||
|
|
||||||
cell = @getCellAtPos pos
|
cell = @getCellAtPos pos
|
||||||
if not cell?
|
if not cell?
|
||||||
|
cellIndex = @posToIndex(pos)
|
||||||
cell = new Cell()
|
cell = new Cell()
|
||||||
@cells[@posToIndex(pos)] = cell
|
log "created cell at index #{cellIndex}"
|
||||||
|
@cells[cellIndex] = cell
|
||||||
|
|
||||||
object.setPosition pos
|
object.setPosition pos
|
||||||
cell.addObject object
|
cell.addObject object
|
||||||
|
@ -634,6 +637,7 @@ class World extends Actor
|
||||||
pos = new Pos x, y, z
|
pos = new Pos x, y, z
|
||||||
object = @newObject object
|
object = @newObject object
|
||||||
@setObjectAtPos object, pos
|
@setObjectAtPos object, pos
|
||||||
|
# log "addObjectAtPos #{object.name}", pos
|
||||||
@addObject object
|
@addObject object
|
||||||
|
|
||||||
removeObject: (object) ->
|
removeObject: (object) ->
|
||||||
|
@ -701,7 +705,10 @@ class World extends Actor
|
||||||
|
|
||||||
setCameraMode: (mode) -> @camera_mode = clamp World.CAMERA_INSIDE, World.CAMERA_FOLLOW, mode
|
setCameraMode: (mode) -> @camera_mode = clamp World.CAMERA_INSIDE, World.CAMERA_FOLLOW, mode
|
||||||
|
|
||||||
changeCameraMode: () -> @camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
changeCameraMode: () ->
|
||||||
|
@camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
||||||
|
log "world.changeCameraMode #{@camera_mode}"
|
||||||
|
@camera_mode
|
||||||
|
|
||||||
# 0000000 0000000 000 00 00 0000000 000 000 00000000
|
# 0000000 0000000 000 00 00 0000000 000 000 00000000
|
||||||
# 000 000 000 000 000 000 000 000 000 000 000 000
|
# 000 000 000 000 000 000 000 000 000 000 000 000
|
||||||
|
@ -865,7 +872,7 @@ class World extends Actor
|
||||||
if @isInvalidPos pos
|
if @isInvalidPos pos
|
||||||
return true
|
return true
|
||||||
if @getOccupantAtPos pos
|
if @getOccupantAtPos pos
|
||||||
log 'isOccupiedPos occupant!', pos
|
log "isOccupiedPos occupant: #{@getOccupantAtPos(pos).name} at pos:", pos
|
||||||
return true
|
return true
|
||||||
|
|
||||||
mayObjectPushToPos: (object, pos, duration) ->
|
mayObjectPushToPos: (object, pos, duration) ->
|
||||||
|
@ -947,10 +954,9 @@ class World extends Actor
|
||||||
lignt.display()
|
lignt.display()
|
||||||
|
|
||||||
getProjection: () ->
|
getProjection: () ->
|
||||||
# log "world.getProjection #{@camera_mode}"
|
|
||||||
if not @projection
|
if not @projection
|
||||||
switch @camera_mode
|
switch @camera_mode
|
||||||
when World.CAMERA_INSIDE then @projection = @player.getProjection()
|
when World.CAMERA_INSIDE then @projection = @player.getInsideProjection()
|
||||||
when World.CAMERA_BEHIND then @projection = @player.getBehindProjection()
|
when World.CAMERA_BEHIND then @projection = @player.getBehindProjection()
|
||||||
when World.CAMERA_FOLLOW then @projection = @player.getFollowProjection()
|
when World.CAMERA_FOLLOW then @projection = @player.getFollowProjection()
|
||||||
@projection
|
@projection
|
||||||
|
|
Loading…
Reference in New Issue
Block a user