action
This commit is contained in:
parent
437b217ceb
commit
ac46d6ac00
|
@ -42,7 +42,7 @@ class Action
|
||||||
i ?= -1
|
i ?= -1
|
||||||
m ?= Action.ONCE
|
m ?= Action.ONCE
|
||||||
d ?= 0
|
d ?= 0
|
||||||
log "newAction #{i} #{n} #{d} #{m}"
|
# log "newAction #{i} #{n} #{d} #{m}"
|
||||||
@object = o
|
@object = o
|
||||||
@name = n
|
@name = n
|
||||||
@id = i
|
@id = i
|
||||||
|
|
|
@ -28,9 +28,9 @@ class Actor extends Emitter
|
||||||
# 00000000 0 00000000 000 000 000
|
# 00000000 0 00000000 000 000 000
|
||||||
|
|
||||||
addEventWithName: (eventName) ->
|
addEventWithName: (eventName) ->
|
||||||
log "Actor.addEventWithName eventName:#{eventName}"
|
# log "Actor.addEventWithName eventName:#{eventName}"
|
||||||
if @getEventWithName eventName # to be removed
|
if @getEventWithName eventName # to be removed
|
||||||
log "Actor.addEventWithName '#{eventName}' already in use!"
|
log "Actor.addEventWithName [WARNING] '#{eventName}' already in use!"
|
||||||
return -1; # shouldn't happen anyway :-)
|
return -1; # shouldn't happen anyway :-)
|
||||||
@events.push new Event @, eventName
|
@events.push new Event @, eventName
|
||||||
@events.length-1
|
@events.length-1
|
||||||
|
@ -94,7 +94,7 @@ class Actor extends Emitter
|
||||||
|
|
||||||
startTimedAction: (action, duration) ->
|
startTimedAction: (action, duration) ->
|
||||||
action.duration = duration if duration >= 0
|
action.duration = duration if duration >= 0
|
||||||
log "Actor.startTimedAction #{action.name} duration: #{duration}"
|
# log "Actor.startTimedAction #{action.name} duration: #{duration}"
|
||||||
Timer.addAction action
|
Timer.addAction action
|
||||||
|
|
||||||
module.exports = Actor
|
module.exports = Actor
|
||||||
|
|
|
@ -78,7 +78,6 @@ class Bot extends Pushable
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
@addAction new Action @, Action.NOOP, "noop", 0
|
|
||||||
@addAction new Action @, Action.FORWARD, "move forward", 200
|
@addAction new Action @, Action.FORWARD, "move forward", 200
|
||||||
@addAction new Action @, Action.CLIMB_UP, "climb up", 200
|
@addAction new Action @, Action.CLIMB_UP, "climb up", 200
|
||||||
@addAction new Action @, Action.CLIMB_DOWN, "climb down", 500
|
@addAction new Action @, Action.CLIMB_DOWN, "climb down", 500
|
||||||
|
@ -102,7 +101,6 @@ class Bot extends Pushable
|
||||||
addMoves: (m) -> @moves += m
|
addMoves: (m) -> @moves += m
|
||||||
addHealth: (h) -> @health = Math.max @health+h
|
addHealth: (h) -> @health = Math.max @health+h
|
||||||
|
|
||||||
|
|
||||||
# 0000000 000 00000000
|
# 0000000 000 00000000
|
||||||
# 000 000 000 000
|
# 000 000 000 000
|
||||||
# 000 000 000 0000000
|
# 000 000 000 0000000
|
||||||
|
@ -157,7 +155,7 @@ class Bot extends Pushable
|
||||||
# 000 000 0000000 000 000 0000000 000 000
|
# 000 000 0000000 000 000 0000000 000 000
|
||||||
|
|
||||||
initAction: (action) ->
|
initAction: (action) ->
|
||||||
log "initAction #{action.name}"
|
# log "initAction #{action.name}"
|
||||||
newPos = new Pos @position
|
newPos = new Pos @position
|
||||||
|
|
||||||
switch action.id
|
switch action.id
|
||||||
|
@ -179,7 +177,7 @@ class Bot extends Pushable
|
||||||
return
|
return
|
||||||
|
|
||||||
if not newPos.eql @position
|
if not newPos.eql @position
|
||||||
log 'bot.initAction', newPos
|
# log 'bot.initAction', newPos
|
||||||
world.objectWillMoveToPos @, newPos, action.getDuration()
|
world.objectWillMoveToPos @, newPos, action.getDuration()
|
||||||
|
|
||||||
# 00000000 00000000 00000000 00000000 0000000 00000000 00 00
|
# 00000000 00000000 00000000 00000000 0000000 00000000 00 00
|
||||||
|
@ -189,14 +187,14 @@ class Bot extends Pushable
|
||||||
# 000 00000000 000 000 000 0000000 000 000 000 000
|
# 000 00000000 000 000 000 0000000 000 000 000 000
|
||||||
|
|
||||||
performAction: (action) ->
|
performAction: (action) ->
|
||||||
actionId = action.id
|
|
||||||
relTime = action.getRelativeTime()
|
relTime = action.getRelativeTime()
|
||||||
dltTime = action.getRelativeDelta()
|
dltTime = action.getRelativeDelta()
|
||||||
|
|
||||||
# log "Bot.performAction #{action.name} #{action.current} #{action.last} #{action.duration} id #{actionId}"
|
# log "Bot.performAction #{action.name} #{action.current} #{action.last} #{action.duration} id #{action.id}"
|
||||||
# log "Bot.performAction #{action.name} #{relTime} #{dltTime} id #{actionId}"
|
# log "Bot.performAction #{action.name} #{relTime} #{dltTime} id #{action.id}"
|
||||||
|
|
||||||
switch actionId
|
switch action.id
|
||||||
when Action.SHOOT
|
when Action.SHOOT
|
||||||
if relTime == 0
|
if relTime == 0
|
||||||
Bullet.shootFromBot @
|
Bullet.shootFromBot @
|
||||||
|
@ -254,7 +252,7 @@ class Bot extends Pushable
|
||||||
@current_position = @position.plus @getDir().plus @getDown().mul 0.5+(relTime-0.8)/0.2/2
|
@current_position = @position.plus @getDir().plus @getDown().mul 0.5+(relTime-0.8)/0.2/2
|
||||||
else
|
else
|
||||||
@climb_orientation = Quaternion.rotationAroundVector @dir_sgn * (relTime-0.2)/0.6 * 90.0, new Vector 1,0,0
|
@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
|
rotVec = (@orientation.mul @climb_orientation).rotate new Vector 0,1,0
|
||||||
@current_position = @position.plus @getDir().plus(@getDown()).plus(rotVec).mul 0.5
|
@current_position = @position.plus @getDir().plus(@getDown()).plus(rotVec).mul 0.5
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -262,14 +260,14 @@ class Bot extends Pushable
|
||||||
|
|
||||||
if @move_action == null and relTime == 0.0 # if not performing move action and start of rotation
|
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
|
# update @orientation now, so next move action will move in desired @direction
|
||||||
if actionId == Action.TURN_LEFT
|
if action.id == Action.TURN_LEFT
|
||||||
@orientation = @orientation.mul Quaternion.rotationAroundVector 90.0, new Vector 0,1,0
|
@orientation = @orientation.mul Quaternion.rotationAroundVector 90.0, new Vector 0,1,0
|
||||||
@rest_orientation = Quaternion.rotationAroundVector -90.0, new Vector 0,1,0
|
@rest_orientation = Quaternion.rotationAroundVector -90.0, new Vector 0,1,0
|
||||||
else
|
else
|
||||||
@orientation = @orientation.mul Quaternion.rotationAroundVector -90.0, new Vector 0,1,0
|
@orientation = @orientation.mul Quaternion.rotationAroundVector -90.0, new Vector 0,1,0
|
||||||
@rest_orientation = Quaternion.rotationAroundVector 90.0, new Vector 0,1,0
|
@rest_orientation = Quaternion.rotationAroundVector 90.0, new Vector 0,1,0
|
||||||
|
|
||||||
if actionId == Action.TURN_LEFT
|
if action.id == Action.TURN_LEFT
|
||||||
@left_tire_rot += -dltTime
|
@left_tire_rot += -dltTime
|
||||||
@right_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, new Vector 0,1,0
|
||||||
|
@ -294,7 +292,7 @@ class Bot extends Pushable
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
|
|
||||||
# log "Bot.finishAction #{actionId} #{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
|
||||||
|
@ -349,7 +347,7 @@ class Bot extends Pushable
|
||||||
# if @isDead()
|
# if @isDead()
|
||||||
# log "DIE!"
|
# log "DIE!"
|
||||||
# @die()
|
# @die()
|
||||||
# if actionId != Action.PUSH and actionId != Action.FALL
|
# if action.id != Action.PUSH and action.id != Action.FALL
|
||||||
# # dead player may only fall, nothing else
|
# # dead player may only fall, nothing else
|
||||||
# return
|
# return
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
# 000 000 000 000
|
# 000 000 000 000
|
||||||
# 0000000 00000000 0000000 0000000
|
# 0000000 00000000 0000000 0000000
|
||||||
|
|
||||||
TmpObject = require './tmpobject'
|
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||||
|
TmpObject = require './tmpobject'
|
||||||
|
_ = require 'lodash'
|
||||||
|
|
||||||
class Cell
|
class Cell
|
||||||
|
|
||||||
|
@ -19,9 +21,11 @@ class Cell
|
||||||
getOccupant: -> _.find @objects, (o) -> o.isSpaceEgoistic()
|
getOccupant: -> _.find @objects, (o) -> o.isSpaceEgoistic()
|
||||||
|
|
||||||
removeObject: (object) ->
|
removeObject: (object) ->
|
||||||
|
# log 'cell.removeObject ', @objects.length
|
||||||
for o in @objects
|
for o in @objects
|
||||||
o.cellMateLeft object if o != object
|
o.cellMateLeft object if o != object
|
||||||
_.pull @objects, object
|
_.remove @objects, (o) -> o == object or o.object == object
|
||||||
|
# log 'cell.removedObject ', (o.name for o in @objects)
|
||||||
|
|
||||||
addObject: (object) ->
|
addObject: (object) ->
|
||||||
for o in @objects
|
for o in @objects
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Event
|
||||||
|
|
||||||
addAction: (action) ->
|
addAction: (action) ->
|
||||||
if action? and not @hasAction action
|
if action? and not @hasAction action
|
||||||
log "Event.addAction #{action.name}"
|
# log "Event.addAction #{action.name}"
|
||||||
@actions.push action
|
@actions.push action
|
||||||
action.event = @
|
action.event = @
|
||||||
action.init()
|
action.init()
|
||||||
|
|
|
@ -35,15 +35,14 @@ class Item extends Actor
|
||||||
isSlippery: -> false
|
isSlippery: -> false
|
||||||
|
|
||||||
setPosition: (x,y,z) ->
|
setPosition: (x,y,z) ->
|
||||||
@position = @current_position = new Vector x, y, z
|
@position = new Vector x,y,z
|
||||||
@mesh?.position.copy @position
|
@mesh?.position.copy @position
|
||||||
|
|
||||||
getPos: -> new Pos @current_position
|
getPos: -> new Pos @current_position
|
||||||
|
setPos: (x,y,z) ->
|
||||||
|
p = new Pos x,y,z
|
||||||
|
@position = @current_position = new Vector p
|
||||||
|
|
||||||
# getPosition: -> @position
|
|
||||||
# getOrientation: -> @orientation
|
|
||||||
# getCurrentPosition: -> @current_position
|
|
||||||
# getCurrentOrientation: -> @current_orientation
|
|
||||||
setOrientation: (q) -> @current_orientation = @orientation = new Quaternion q
|
setOrientation: (q) -> @current_orientation = @orientation = new Quaternion q
|
||||||
setCurrentPosition: (p) -> @current_position = p
|
setCurrentPosition: (p) -> @current_position = p
|
||||||
setCurrentOrientation: (q) -> @current_orientation = q
|
setCurrentOrientation: (q) -> @current_orientation = q
|
||||||
|
|
|
@ -11,9 +11,7 @@ Vector = require './vector'
|
||||||
class Matrix
|
class Matrix
|
||||||
|
|
||||||
constructor: (o) ->
|
constructor: (o) ->
|
||||||
|
|
||||||
@matrix = []
|
@matrix = []
|
||||||
|
|
||||||
switch
|
switch
|
||||||
when not o? then @reset()
|
when not o? then @reset()
|
||||||
when o instanceof Quaternion then @initQuat o
|
when o instanceof Quaternion then @initQuat o
|
||||||
|
@ -25,7 +23,6 @@ class Matrix
|
||||||
when o?.x? and o?.y? and o?.z?
|
when o?.x? and o?.y? and o?.z?
|
||||||
@initXYZ o.x, o.y, o.z
|
@initXYZ o.x, o.y, o.z
|
||||||
else @reset()
|
else @reset()
|
||||||
log 'matrix.init', @matrix
|
|
||||||
|
|
||||||
initXYZ: (x,y,z) ->
|
initXYZ: (x,y,z) ->
|
||||||
@matrix[0] = x.x
|
@matrix[0] = x.x
|
||||||
|
@ -306,7 +303,6 @@ class Matrix
|
||||||
@matrix[12] = v.x
|
@matrix[12] = v.x
|
||||||
@matrix[13] = v.y
|
@matrix[13] = v.y
|
||||||
@matrix[14] = v.z
|
@matrix[14] = v.z
|
||||||
# log 'Matrix.setPosition', @matrix
|
|
||||||
|
|
||||||
setXVector: (v) ->
|
setXVector: (v) ->
|
||||||
@matrix[0] = v.x
|
@matrix[0] = v.x
|
||||||
|
|
|
@ -62,15 +62,13 @@ class Perspective extends Matrix
|
||||||
camPos = @getPosition()
|
camPos = @getPosition()
|
||||||
camera.position.copy camPos
|
camera.position.copy camPos
|
||||||
camera.up.copy @getYVector()
|
camera.up.copy @getYVector()
|
||||||
camera.lookAt camPos.minus @getZVector()
|
camera.lookAt camPos.plus @getZVector()
|
||||||
|
|
||||||
if @light?
|
if @light?
|
||||||
pos = @getPosition().plus @light_offset
|
pos = @getPosition().plus @light_offset
|
||||||
@light.setDirection -@getZVector()
|
@light.setDirection -@getZVector()
|
||||||
@light.setPosition new Vector pos[X], pos[Y], pos[Z], 1.0 # positional light source
|
@light.setPosition new Vector pos[X], pos[Y], pos[Z], 1.0 # positional light source
|
||||||
|
|
||||||
focusOn: (pos) -> @setPosition pos.plus @getZVector().mul @eye_distance
|
|
||||||
|
|
||||||
setEyeDistance: (distance) ->
|
setEyeDistance: (distance) ->
|
||||||
lookAtPos = @getLookAtPosition()
|
lookAtPos = @getLookAtPosition()
|
||||||
@eye_distance = Math.min Math.max(@znear, distance), 0.9*@zfar
|
@eye_distance = Math.min Math.max(@znear, distance), 0.9*@zfar
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Player extends Bot
|
||||||
constructor: ->
|
constructor: ->
|
||||||
|
|
||||||
super
|
super
|
||||||
|
@name = 'player'
|
||||||
@key =
|
@key =
|
||||||
forward: 'w'
|
forward: 'w'
|
||||||
backward: 's'
|
backward: 's'
|
||||||
|
@ -71,13 +71,13 @@ class Player extends Bot
|
||||||
if relTime <= 1.0
|
if relTime <= 1.0
|
||||||
switch @move_action.id
|
switch @move_action.id
|
||||||
when Action.FORWARD
|
when Action.FORWARD
|
||||||
@current_position = @position + relTime * @getDir()
|
@current_position = @position.plus @getDir().mul relTime
|
||||||
when Action.FALL
|
when Action.FALL
|
||||||
@current_position = @position - relTime * @getUp()
|
@current_position = @position.minus @getUp().mul relTime
|
||||||
when Action.JUMP_FORWARD
|
when Action.JUMP_FORWARD
|
||||||
@current_position = @position + (1.0 - Math.cos(Math.PI/2 * relTime)) * @getDir() + Math.cos(Math.PI/2 - Math.PI/2 * relTime) * @getUp()
|
@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 + Math.cos(Math.PI/2 - Math.PI/2 * relTime) * @getDir() + (1.0 - Math.cos(Math.PI/2 * relTime)) * -@getUp()
|
@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
|
||||||
|
@ -203,7 +203,7 @@ class Player extends Bot
|
||||||
botToCameraNormal = botToCamera.normal()
|
botToCameraNormal = botToCamera.normal()
|
||||||
|
|
||||||
rotFactor = 1.0
|
rotFactor = 1.0
|
||||||
log "playerPos", playerPos
|
# log "playerPos", playerPos
|
||||||
wall_distance = world.getWallDistanceForPos playerPos.plus botToCamera
|
wall_distance = world.getWallDistanceForPos playerPos.plus botToCamera
|
||||||
if wall_distance < 0.5
|
if wall_distance < 0.5
|
||||||
# ____________________________________________________ piercing walls
|
# ____________________________________________________ piercing walls
|
||||||
|
@ -259,9 +259,8 @@ class Player extends Bot
|
||||||
# 000 000 0000000 000 000 0000000 000 000
|
# 000 000 0000000 000 000 0000000 000 000
|
||||||
|
|
||||||
initAction: (action) ->
|
initAction: (action) ->
|
||||||
log "initAction #{action.id} #{action.name}"
|
# log "initAction #{action.id} #{action.name}"
|
||||||
actionId = action.id
|
switch action.id
|
||||||
switch actionId
|
|
||||||
when Action.CLIMB_DOWN, Action.FORWARD
|
when Action.CLIMB_DOWN, Action.FORWARD
|
||||||
# @status.addMoves 1
|
# @status.addMoves 1
|
||||||
log 'init action forward'
|
log 'init action forward'
|
||||||
|
@ -286,21 +285,13 @@ class Player extends Bot
|
||||||
|
|
||||||
performAction: (action) ->
|
performAction: (action) ->
|
||||||
relTime = action.getRelativeTime()
|
relTime = action.getRelativeTime()
|
||||||
|
|
||||||
switch action.id
|
switch action.id
|
||||||
when Action.NOOP then return
|
when Action.NOOP then return
|
||||||
|
when Action.LOOK_UP then @look_angle = relTime * 90.0
|
||||||
when Action.LOOK_UP
|
when Action.LOOK_DOWN then @look_angle = relTime * -90.0
|
||||||
@look_angle = relTime * -90.0
|
|
||||||
|
|
||||||
when Action.LOOK_DOWN
|
|
||||||
@look_angle = relTime * 90.0
|
|
||||||
|
|
||||||
when Action.LOOK_RESET
|
when Action.LOOK_RESET
|
||||||
if @look_angle > 0
|
if @look_angle > 0 then @look_angle = Math.min @look_angle, (1.0-relTime) * 90.0
|
||||||
@look_angle = Math.min @look_angle, (1.0-relTime) * 90.0
|
else @look_angle = Math.max @look_angle, (1.0-relTime) * -90.0
|
||||||
else
|
|
||||||
@look_angle = Math.max @look_angle, (1.0-relTime) * -90.0
|
|
||||||
else
|
else
|
||||||
super action
|
super action
|
||||||
|
|
||||||
|
@ -311,19 +302,18 @@ class Player extends Bot
|
||||||
# 000 000 000 000 000 0000000 000 000
|
# 000 000 000 000 000 0000000 000 000
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
actionId = action.id
|
|
||||||
|
|
||||||
if actionId == Action.LOOK_RESET
|
if action.id == Action.LOOK_RESET
|
||||||
@look_action = null
|
@look_action = null
|
||||||
@look_angle = 0.0
|
@look_angle = 0.0
|
||||||
else
|
else
|
||||||
if action == @move_action # move finished, update direction
|
if action.id == @move_action # move finished, update direction
|
||||||
@dir_sgn = @new_dir_sgn
|
@dir_sgn = @new_dir_sgn
|
||||||
|
|
||||||
if actionId != Action.LOOK_UP and actionId != Action.LOOK_DOWN
|
if action.id != Action.LOOK_UP and action.id != Action.LOOK_DOWN
|
||||||
super action
|
super action
|
||||||
|
|
||||||
if actionId == Action.TURN_LEFT or actionId == Action.TURN_RIGHT
|
if action.id == Action.TURN_LEFT or action.id == Action.TURN_RIGHT
|
||||||
if @rotate
|
if @rotate
|
||||||
@rotate_action = @getActionWithId @rotate
|
@rotate_action = @getActionWithId @rotate
|
||||||
@rotate_action.reset()
|
@rotate_action.reset()
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Pushable extends Item
|
||||||
@pusher = null
|
@pusher = null
|
||||||
@direction = new Vector()
|
@direction = new Vector()
|
||||||
|
|
||||||
|
@addAction new Action @, Action.NOOP, "noop"
|
||||||
@addAction new Action @, Action.PUSH, "push"
|
@addAction new Action @, Action.PUSH, "push"
|
||||||
@addAction new Action @, Action.FALL, "fall", 40
|
@addAction new Action @, Action.FALL, "fall", 40
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ class Pushable extends Item
|
||||||
performAction: (action) ->
|
performAction: (action) ->
|
||||||
switch action.id
|
switch action.id
|
||||||
when Action.PUSH, Action.FALL
|
when Action.PUSH, Action.FALL
|
||||||
@setCurrentPosition @position + action.getRelativeTime() * @direction
|
@setCurrentPosition @position.plus @direction.mul action.getRelativeTime()
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
log "Pushable.finishAction #{action.name}"
|
log "Pushable.finishAction #{action.name}"
|
||||||
|
@ -49,12 +50,10 @@ class Pushable extends Item
|
||||||
@setPosition @current_position
|
@setPosition @current_position
|
||||||
|
|
||||||
actionFinished: (action) ->
|
actionFinished: (action) ->
|
||||||
actionId = action.id
|
if action.id == Action.PUSH or actionId == Action.FALL
|
||||||
|
|
||||||
if actionId == Action.PUSH or actionId == Action.FALL
|
|
||||||
gravityDir = @direction
|
gravityDir = @direction
|
||||||
|
|
||||||
if actionId == Action.PUSH
|
if action.id == Action.PUSH
|
||||||
if @pusher instanceof Bot
|
if @pusher instanceof Bot
|
||||||
gravityDir = pusher.getDown()
|
gravityDir = pusher.getDown()
|
||||||
else if pusher instanceof Bomb
|
else if pusher instanceof Bomb
|
||||||
|
@ -69,7 +68,7 @@ class Pushable extends Item
|
||||||
direction.reset()
|
direction.reset()
|
||||||
return # objects pushed by bombs don't fall
|
return # objects pushed by bombs don't fall
|
||||||
|
|
||||||
if world.isUnoccupiedPos @position + gravityDir
|
if world.isUnoccupiedPos @position.plus gravityDir
|
||||||
@direction = gravityDir
|
@direction = gravityDir
|
||||||
@move_action = @getActionWithId Action.FALL
|
@move_action = @getActionWithId Action.FALL
|
||||||
Timer.addAction @move_action
|
Timer.addAction @move_action
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Timer
|
||||||
@event.removeActionsOfObject o
|
@event.removeActionsOfObject o
|
||||||
|
|
||||||
@addAction: (a) ->
|
@addAction: (a) ->
|
||||||
log "Timer.addAction #{a.name}"
|
# log "Timer.addAction #{a.name}"
|
||||||
@event.addAction a
|
@event.addAction a
|
||||||
|
|
||||||
@removeAction: (a) ->
|
@removeAction: (a) ->
|
||||||
|
|
|
@ -4,15 +4,24 @@
|
||||||
# 000 000 0 000 000 000 000 000 000 000 000 000 000 000
|
# 000 000 0 000 000 000 000 000 000 000 000 000 000 000
|
||||||
# 000 000 000 000 0000000 0000000 0000000 00000000 0000000 000
|
# 000 000 000 000 0000000 0000000 0000000 00000000 0000000 000
|
||||||
|
|
||||||
|
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||||
|
|
||||||
Item = require './item'
|
Item = require './item'
|
||||||
|
|
||||||
class TmpObject extends Item
|
class TmpObject extends Item
|
||||||
|
|
||||||
|
@tmpID = 0
|
||||||
|
|
||||||
constructor: (o) ->
|
constructor: (o) ->
|
||||||
|
TmpObject.tmpID += 1
|
||||||
@time = 0
|
@time = 0
|
||||||
@object = o
|
@object = o
|
||||||
|
@name = "tmp#{TmpObject.tmpID}"
|
||||||
super
|
super
|
||||||
|
@setPos o.getPos()
|
||||||
|
|
||||||
del: ->
|
del: ->
|
||||||
|
# log "tmpObject -------- del #{@name}", @getPos()
|
||||||
|
super
|
||||||
|
|
||||||
module.exports = TmpObject
|
module.exports = TmpObject
|
||||||
|
|
|
@ -104,8 +104,8 @@ class World extends Actor
|
||||||
@cells = []
|
@cells = []
|
||||||
@size = new Pos()
|
@size = new Pos()
|
||||||
@depth = -Number.MAX_SAFE_INTEGER
|
@depth = -Number.MAX_SAFE_INTEGER
|
||||||
@camera_mode = World.CAMERA_INSIDE
|
# @camera_mode = World.CAMERA_INSIDE
|
||||||
# @camera_mode = World.CAMERA_BEHIND
|
@camera_mode = World.CAMERA_BEHIND
|
||||||
# @camera_mode = World.CAMERA_FOLLOW
|
# @camera_mode = World.CAMERA_FOLLOW
|
||||||
@edit_projection = null
|
@edit_projection = null
|
||||||
@raster_size = 0.1
|
@raster_size = 0.1
|
||||||
|
@ -382,9 +382,11 @@ class World extends Actor
|
||||||
|
|
||||||
decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2
|
decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2
|
||||||
|
|
||||||
isValidPos: (pos) -> pos.x >= 0 and pos.x < @size.x and pos.y >= 0 and pos.y < @size.y and pos.z >= 0 and pos.z < @size.z
|
isValidPos: (pos) ->
|
||||||
isInvalidPos: (pos) -> not @isValidPos pos
|
p = new Pos pos
|
||||||
|
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
|
||||||
|
|
||||||
# 0000000 0000000 000 00000000 0000000 000000000 000 000 000 000 00000000
|
# 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 000 000 000 000 000 000 000 000 0000 000 000
|
||||||
|
@ -392,7 +394,6 @@ class World extends Actor
|
||||||
# 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 0000 000
|
||||||
# 0000000 0000000 0000000 00000000 0000000 000 0000000 000 000 000 00000000
|
# 0000000 0000000 0000000 00000000 0000000 000 0000000 000 000 000 00000000
|
||||||
|
|
||||||
|
|
||||||
addObjectLine: (object, sx,sy,sz, ex,ey,ez) ->
|
addObjectLine: (object, sx,sy,sz, ex,ey,ez) ->
|
||||||
if sx instanceof Pos
|
if sx instanceof Pos
|
||||||
start = sx
|
start = sx
|
||||||
|
@ -556,7 +557,10 @@ class World extends Actor
|
||||||
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, pos
|
||||||
|
|
||||||
posToIndex: (pos) -> pos.x * @size.z * @size.y + pos.y * @size.z + pos.z
|
posToIndex: (pos) ->
|
||||||
|
p = new Pos pos
|
||||||
|
p.x * @size.z * @size.y + p.y * @size.z + p.z
|
||||||
|
|
||||||
indexToPos: (index) ->
|
indexToPos: (index) ->
|
||||||
lsize = @size.z * @size.y
|
lsize = @size.z * @size.y
|
||||||
lrest = index % lsize
|
lrest = index % lsize
|
||||||
|
@ -584,17 +588,14 @@ class World extends Actor
|
||||||
log "World.setObjectAtPos invalid pos:", pos
|
log "World.setObjectAtPos invalid pos:", pos
|
||||||
return
|
return
|
||||||
|
|
||||||
cell = @getCellAtPos pos
|
if object.isSpaceEgoistic()
|
||||||
if object.isSpaceEgoistic() and cell and cell.getOccupant()
|
if cell = @getCellAtPos pos
|
||||||
objectAtNewPos = cell.getOccupant()
|
if occupant = cell.getOccupant()
|
||||||
if objectAtNewPos instanceof TmpObject
|
if occupant instanceof TmpObject
|
||||||
if objectAtNewPos.time > 0
|
if occupant.time > 0
|
||||||
log "WARNING World.setObject already occupied pos:", pos
|
log "World.setObjectAtPos [WARNING] already occupied pos:", pos
|
||||||
# "already occupied by %s with time %d!",
|
log "World.setObjectAtPos [WARNING] already occupied time:", occupant.time
|
||||||
# object.getClassName(), pos.x, pos.y, pos.z,
|
occupant.del() # temporary object at new pos will vanish anyway . delete it
|
||||||
# cell.getOccupant().getClassName(),
|
|
||||||
# ((TmpObject*)objectAtNewPos).time)
|
|
||||||
objectAtNewPos.del() # temporary object at new pos will vanish anyway . delete it
|
|
||||||
|
|
||||||
cell = @getCellAtPos pos
|
cell = @getCellAtPos pos
|
||||||
if not cell?
|
if not cell?
|
||||||
|
@ -606,11 +607,14 @@ class World extends Actor
|
||||||
|
|
||||||
unsetObject: (object) ->
|
unsetObject: (object) ->
|
||||||
pos = object.getPos()
|
pos = object.getPos()
|
||||||
|
# log "world.unsetObject #{object.name} pos:", pos
|
||||||
if cell = @getCellAtPos pos
|
if cell = @getCellAtPos pos
|
||||||
cell.removeObject object
|
cell.removeObject object
|
||||||
if cell.isEmpty()
|
if cell.isEmpty()
|
||||||
# delete cell
|
# log 'world.unsetObject remove cell empty cell', pos
|
||||||
@cells[@posToIndex(pos)] = null
|
@cells[@posToIndex(pos)] = null
|
||||||
|
else
|
||||||
|
log 'world.unsetObject [WARNING] no cell at pos:', pos
|
||||||
|
|
||||||
newObject: (object) ->
|
newObject: (object) ->
|
||||||
if _.isString object
|
if _.isString object
|
||||||
|
@ -699,7 +703,6 @@ class World extends Actor
|
||||||
|
|
||||||
changeCameraMode: () -> @camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
changeCameraMode: () -> @camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
||||||
|
|
||||||
|
|
||||||
# 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
|
||||||
# 000 000 0000000 000 000000000 000 000 000 000 0000000
|
# 000 000 0000000 000 000000000 000 000 000 000 0000000
|
||||||
|
@ -719,6 +722,7 @@ class World extends Actor
|
||||||
|
|
||||||
if @isInvalidPos pos
|
if @isInvalidPos pos
|
||||||
log "objectWillMoveToPos invalid pos:", pos
|
log "objectWillMoveToPos invalid pos:", pos
|
||||||
|
return
|
||||||
|
|
||||||
if object.getPos().eql pos
|
if object.getPos().eql pos
|
||||||
log "WARNING objectWillMoveToPos equal pos:", pos
|
log "WARNING objectWillMoveToPos equal pos:", pos
|
||||||
|
@ -736,12 +740,12 @@ class World extends Actor
|
||||||
log "World.objectWillMoveToPos already occupied:", pos
|
log "World.objectWillMoveToPos already occupied:", pos
|
||||||
|
|
||||||
@unsetObject object # remove object from cell grid
|
@unsetObject object # remove object from cell grid
|
||||||
|
# log 'tmpObject at new pos', pos
|
||||||
tmpObject = new TmpObject object # insert temporary objects at new pos
|
tmpObject = new TmpObject object # insert temporary objects at new pos
|
||||||
tmpObject.setPosition pos
|
tmpObject.setPosition pos
|
||||||
tmpObject.time = duration
|
tmpObject.time = duration
|
||||||
@addObjectAtPos tmpObject, pos
|
@addObjectAtPos tmpObject, pos
|
||||||
|
# log 'tmpObject at old pos', object.position
|
||||||
tmpObject = new TmpObject object # insert temporary objects at old pos
|
tmpObject = new TmpObject object # insert temporary objects at old pos
|
||||||
tmpObject.setPosition object.position
|
tmpObject.setPosition object.position
|
||||||
tmpObject.time = -duration
|
tmpObject.time = -duration
|
||||||
|
@ -856,12 +860,13 @@ class World extends Actor
|
||||||
Math.min(size.y-1, Math.max(pos.y, 0)),
|
Math.min(size.y-1, Math.max(pos.y, 0)),
|
||||||
Math.min(size.z-1, Math.max(pos.z, 0))
|
Math.min(size.z-1, Math.max(pos.z, 0))
|
||||||
|
|
||||||
isUnoccupiedPos: (pos) ->
|
isUnoccupiedPos: (pos) -> not @isOccupiedPos pos
|
||||||
log 'world.isUnoccupiedPos', pos
|
isOccupiedPos: (pos) ->
|
||||||
return false if @isInvalidPos pos
|
if @isInvalidPos pos
|
||||||
not @getOccupantAtPos pos
|
return true
|
||||||
|
if @getOccupantAtPos pos
|
||||||
isOccupiedPos: (pos) -> not @isUnoccupiedPos pos
|
log 'isOccupiedPos occupant!', pos
|
||||||
|
return true
|
||||||
|
|
||||||
mayObjectPushToPos: (object, pos, duration) ->
|
mayObjectPushToPos: (object, pos, duration) ->
|
||||||
# returns true, if a pushable object is at pos and may be pushed
|
# returns true, if a pushable object is at pos and may be pushed
|
||||||
|
@ -922,9 +927,9 @@ class World extends Actor
|
||||||
planePos = new Vector -0.5, -0.5, -0.5
|
planePos = new Vector -0.5, -0.5, -0.5
|
||||||
if w >= 3 then planePos.add @size
|
if w >= 3 then planePos.add @size
|
||||||
f = Vector.rayPlaneIntersectionFactor pos, World.normals[w].neg(), planePos, World.normals[w]
|
f = Vector.rayPlaneIntersectionFactor pos, World.normals[w].neg(), planePos, World.normals[w]
|
||||||
log "getWallDistanceForPos w #{w} min_f #{min_f} f #{f}"
|
# log "getWallDistanceForPos w #{w} min_f #{min_f} f #{f}"
|
||||||
min_f = absMin min_f, f
|
min_f = absMin min_f, f
|
||||||
# log "getWallDistanceForPos #{min_f}", pos
|
log "getWallDistanceForPos #{min_f}", pos
|
||||||
min_f
|
min_f
|
||||||
|
|
||||||
getWallDistanceForRay: (rayPos, rayDirection) -> # distance to the next wall in rayDirection
|
getWallDistanceForRay: (rayPos, rayDirection) -> # distance to the next wall in rayDirection
|
||||||
|
@ -934,7 +939,7 @@ class World extends Actor
|
||||||
if w >= 3 then planePos.add @size
|
if w >= 3 then planePos.add @size
|
||||||
f = Vector.rayPlaneIntersectionFactor rayPos, rayDirection, planePos, World.normals[w]
|
f = Vector.rayPlaneIntersectionFactor rayPos, rayDirection, planePos, World.normals[w]
|
||||||
min_f = f if f >= 0.0 and f < min_f
|
min_f = f if f >= 0.0 and f < min_f
|
||||||
log "getWallDistanceForRay #{min_f}", rayDirection
|
# log "getWallDistanceForRay #{min_f}", rayDirection
|
||||||
min_f
|
min_f
|
||||||
|
|
||||||
displayLights: () ->
|
displayLights: () ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user