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