misc
This commit is contained in:
parent
96e4680904
commit
85ecf428ce
|
@ -36,7 +36,6 @@ class Bot extends Pushable
|
||||||
@jump = false
|
@jump = false
|
||||||
@shoot = false
|
@shoot = false
|
||||||
@jump_once = false
|
@jump_once = false
|
||||||
@spiked = false
|
|
||||||
@died = false
|
@died = false
|
||||||
|
|
||||||
@move_action = null
|
@move_action = null
|
||||||
|
@ -162,7 +161,6 @@ class Bot extends Pushable
|
||||||
@jump = false
|
@jump = false
|
||||||
@shoot = false
|
@shoot = false
|
||||||
@jump_once = false
|
@jump_once = false
|
||||||
@spiked = false
|
|
||||||
@died = false
|
@died = false
|
||||||
|
|
||||||
isFalling: -> @move_action and @move_action.id == Action.FALL
|
isFalling: -> @move_action and @move_action.id == Action.FALL
|
||||||
|
@ -362,12 +360,6 @@ class Bot extends Pushable
|
||||||
actionFinished: (action) ->
|
actionFinished: (action) ->
|
||||||
# log "bot.actionFinished #{action.name} #{action.id}"
|
# log "bot.actionFinished #{action.name} #{action.id}"
|
||||||
|
|
||||||
if @spiked
|
|
||||||
log 'spiked!'
|
|
||||||
@move_action = null
|
|
||||||
@startTimedAction @getActionWithId(Action.NOOP), 0
|
|
||||||
return
|
|
||||||
|
|
||||||
if action.id == Action.PUSH and not @direction.isZero()
|
if action.id == Action.PUSH and not @direction.isZero()
|
||||||
log 'super (Pushable) action!'
|
log 'super (Pushable) action!'
|
||||||
super action
|
super action
|
||||||
|
@ -427,6 +419,8 @@ class Bot extends Pushable
|
||||||
else
|
else
|
||||||
@dir_sgn = 1
|
@dir_sgn = 1
|
||||||
@jump_once = false if action.id != Action.NOOP
|
@jump_once = false if action.id != Action.NOOP
|
||||||
|
log "bot.actionFinished '#{action.name}' position:", @position if action.id in [Action.FORWARD, Action.JUMP_FORWARD, Action.CLIMB_DOWN]
|
||||||
|
log "bot.actionFinished '#{action.name}' orientation:", @orientation.rounded().name if action.id in [Action.TURN_LEFT, Action.TURN_RIGHT, Action.CLIMB_UP]
|
||||||
# keep action chain flowinwg in order to detect environment changes
|
# keep action chain flowinwg in order to detect environment changes
|
||||||
# @startTimedAction @getActionWithId(Action.NOOP), 0
|
# @startTimedAction @getActionWithId(Action.NOOP), 0
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ clamp
|
||||||
log = require '/Users/kodi/s/ko/js/tools/log'
|
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||||
Matrix = require './lib/matrix'
|
Matrix = require './lib/matrix'
|
||||||
Vector = require './lib/vector'
|
Vector = require './lib/vector'
|
||||||
|
Quaternion = require './lib/quaternion'
|
||||||
|
|
||||||
class Camera extends Matrix
|
class Camera extends Matrix
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ class Event
|
||||||
|
|
||||||
addAction: (action) ->
|
addAction: (action) ->
|
||||||
if action? and not @hasAction action
|
if action? and not @hasAction action
|
||||||
# log "Event.addAction #{action.name}"
|
|
||||||
return if world.noRotations and action.id == Action.ROTATE
|
return if world.noRotations and action.id == Action.ROTATE
|
||||||
@actions.push action
|
@actions.push action
|
||||||
action.event = @
|
action.event = @
|
||||||
|
@ -57,21 +56,15 @@ class Event
|
||||||
triggerActions: () ->
|
triggerActions: () ->
|
||||||
return if not @actions.length
|
return if not @actions.length
|
||||||
@time = world.getTime()
|
@time = world.getTime()
|
||||||
# log "event.triggerActions event name: #{@name} num actions: #{@actions.length}" if @name != 'timer'
|
actions = _.clone @actions
|
||||||
save_actions = _.clone @actions
|
while actions.length
|
||||||
while save_actions.length
|
actions.pop().performWithEvent @
|
||||||
action = last save_actions
|
|
||||||
# log "event.triggerActions action: #{action.name}" if @name != 'timer' and action.name != 'noop'
|
|
||||||
action.performWithEvent @
|
|
||||||
save_actions.pop()
|
|
||||||
|
|
||||||
addFinishedAction: (action) ->
|
addFinishedAction: (action) ->
|
||||||
# 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
|
|
||||||
@finished_actions.pop().finished()
|
@finished_actions.pop().finished()
|
||||||
|
|
||||||
module.exports = Event
|
module.exports = Event
|
||||||
|
|
|
@ -45,12 +45,15 @@ class Item extends Actor
|
||||||
@setCurrentPosition @position
|
@setCurrentPosition @position
|
||||||
|
|
||||||
getPos: -> new Pos @current_position
|
getPos: -> new Pos @current_position
|
||||||
setPos: (x,y,z) -> @setPosition new Pos x,y,z
|
setPos: (x,y,z) ->
|
||||||
|
log "item.setPos #{@name} #{x} #{y} #{z}"
|
||||||
|
@setPosition newPos x,y,z
|
||||||
|
|
||||||
setOrientation: (q) ->
|
setOrientation: (q) ->
|
||||||
@current_orientation = @orientation = new Quaternion q
|
@current_orientation = @orientation = new Quaternion q
|
||||||
|
|
||||||
setCurrentPosition: (p) ->
|
setCurrentPosition: (p) ->
|
||||||
|
# log "item.setCurrentPosition #{@name}", p
|
||||||
@current_position = new Vector p
|
@current_position = new Vector p
|
||||||
@mesh?.position.copy @current_position
|
@mesh?.position.copy @current_position
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Levels
|
||||||
@dict = {}
|
@dict = {}
|
||||||
@list = [
|
@list = [
|
||||||
# "test",
|
# "test",
|
||||||
|
"start",
|
||||||
# --- introduction
|
# --- introduction
|
||||||
"steps",
|
"steps",
|
||||||
"start",
|
"start",
|
||||||
|
|
|
@ -18,8 +18,8 @@ module.exports =
|
||||||
to shoot, press "$key(shoot)"
|
to shoot, press "$key(shoot)"
|
||||||
"""
|
"""
|
||||||
player:
|
player:
|
||||||
coordinates: [3,5,5]
|
coordinates: [3,3,5]
|
||||||
orientation: roty180
|
orientation: rotx90
|
||||||
nostatus: 0
|
nostatus: 0
|
||||||
exits: [
|
exits: [
|
||||||
name: "exit"
|
name: "exit"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
module.exports =
|
module.exports =
|
||||||
name: "start"
|
name: "start"
|
||||||
scheme: "default"
|
scheme: "default"
|
||||||
size: [7,7,11]
|
size: [7,5,11]
|
||||||
help: """
|
help: """
|
||||||
$scale(1.5)mission:
|
$scale(1.5)mission:
|
||||||
get to the exit!
|
get to the exit!
|
||||||
|
@ -21,8 +21,8 @@ module.exports =
|
||||||
to turn, press "$key(turn left)" or "$key(turn right)"
|
to turn, press "$key(turn left)" or "$key(turn right)"
|
||||||
"""
|
"""
|
||||||
player:
|
player:
|
||||||
position: [2,1,4]
|
coordinates: [1,0,4]
|
||||||
orientation: rotx270
|
orientation: minusXupY
|
||||||
exits: [
|
exits: [
|
||||||
name: "exit"
|
name: "exit"
|
||||||
active: 1
|
active: 1
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.exports =
|
||||||
to turn, press "$key(turn left)" or "$key(turn right)"
|
to turn, press "$key(turn left)" or "$key(turn right)"
|
||||||
"""
|
"""
|
||||||
player:
|
player:
|
||||||
position: [0,0,-5]
|
coordinates: [3,0,1]
|
||||||
orientation: rot0
|
orientation: rot0
|
||||||
exits: [
|
exits: [
|
||||||
name: "exit"
|
name: "exit"
|
||||||
|
|
|
@ -42,8 +42,7 @@ class Quaternion
|
||||||
@w = q.w
|
@w = q.w
|
||||||
@
|
@
|
||||||
|
|
||||||
round: ->
|
rounded: ->
|
||||||
@normalize()
|
|
||||||
minDist = 1000
|
minDist = 1000
|
||||||
minQuat = null
|
minQuat = null
|
||||||
up = @rotate Vector.unitY
|
up = @rotate Vector.unitY
|
||||||
|
@ -76,14 +75,14 @@ class Quaternion
|
||||||
upDiff = 1 - up.dot q.rotate Vector.unitY
|
upDiff = 1 - up.dot q.rotate Vector.unitY
|
||||||
backDiff = 1 - back.dot q.rotate Vector.unitZ
|
backDiff = 1 - back.dot q.rotate Vector.unitZ
|
||||||
l = upDiff + backDiff
|
l = upDiff + backDiff
|
||||||
# log "length #{upDiff} #{backDiff} #{q.name} #{l}"
|
|
||||||
if l < minDist
|
if l < minDist
|
||||||
minDist = l
|
minDist = l
|
||||||
minQuat = q
|
minQuat = q
|
||||||
if l < 0.0001
|
if l < 0.0001
|
||||||
break
|
break
|
||||||
log "differ a lot! #{minDist}" if minDist > 0.05
|
minQuat
|
||||||
return @clone minQuat
|
|
||||||
|
round: -> @clone @normalize().rounded()
|
||||||
|
|
||||||
euler: -> [
|
euler: -> [
|
||||||
Vector.RAD2DEG Math.atan2 2*(@w*@x+@y*@z), 1-2*(@x*@x+@y*@y)
|
Vector.RAD2DEG Math.atan2 2*(@w*@x+@y*@z), 1-2*(@x*@x+@y*@y)
|
||||||
|
|
|
@ -154,7 +154,7 @@ class Player extends Bot
|
||||||
|
|
||||||
when @key.left, @key.right
|
when @key.left, @key.right
|
||||||
@rotate = (key == @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
|
if not @rotate_action? # player is not performing a rotation
|
||||||
@rotate_action = @getActionWithId @rotate
|
@rotate_action = @getActionWithId @rotate
|
||||||
Timer.addAction @rotate_action
|
Timer.addAction @rotate_action
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
# 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 0000000 000 000 000 000 0000000 0000000 00000000
|
# 000 0000000 0000000 000 000 000 000 0000000 0000000 00000000
|
||||||
|
|
||||||
log = require '/Users/kodi/s/ko/js/tools/log'
|
|
||||||
Vector = require './lib/vector'
|
Vector = require './lib/vector'
|
||||||
Item = require './item'
|
Item = require './item'
|
||||||
Action = require './action'
|
Action = require './action'
|
||||||
|
@ -22,49 +21,51 @@ class Pushable extends Item
|
||||||
@pushing_sound = 'STONE_MOVE'
|
@pushing_sound = 'STONE_MOVE'
|
||||||
|
|
||||||
@addAction new Action @, Action.NOOP, "noop"
|
@addAction new Action @, Action.NOOP, "noop"
|
||||||
@addAction new Action @, Action.PUSH, "push"
|
@addAction new Action @, Action.PUSH, "push", 1 # set duration to make it TIMED
|
||||||
@addAction new Action @, Action.FALL, "fall", 40
|
@addAction new Action @, Action.FALL, "fall", 40
|
||||||
|
|
||||||
setOrientation: (q) ->
|
setOrientation: (q) ->
|
||||||
super q
|
super q
|
||||||
if not @pusher?
|
if not @pusher?
|
||||||
@direction = @orientation.rotate Vector.minusZ
|
@direction = @orientation.rotate Vector.minusZ
|
||||||
# log "Pushable.setOrientation direction:", @direction
|
|
||||||
|
|
||||||
pushedByObjectInDirection: (object, dir, duration) ->
|
pushedByObjectInDirection: (object, dir, duration) ->
|
||||||
# log "pushedByObjectInDirection #{object.name} duration:#{duration}"
|
# log "pushable.pushedByObjectInDirection #{@name} pusher:#{object.name} duration:#{duration}"
|
||||||
pushAction = @getActionWithId Action.PUSH
|
pushAction = @getActionWithId Action.PUSH
|
||||||
|
|
||||||
@pusher = object
|
@pusher = object
|
||||||
@move_action = pushAction
|
@move_action = pushAction
|
||||||
@direction = dir
|
@direction = dir
|
||||||
|
|
||||||
pushAction.duration = world.unmapMsTime duration
|
pushAction.duration = world.unmapMsTime duration
|
||||||
Timer.addAction pushAction
|
Timer.addAction pushAction
|
||||||
|
|
||||||
initAction: (action) ->
|
initAction: (action) ->
|
||||||
switch action.id
|
if action.id in [Action.PUSH, Action.FALL]
|
||||||
when Action.PUSH, Action.FALL
|
|
||||||
world.playSound @pushing_sound if action.id == Action.PUSH
|
world.playSound @pushing_sound if action.id == Action.PUSH
|
||||||
world.objectWillMoveToPos @, @position.plus(@direction), action.getDuration()
|
world.objectWillMoveToPos @, @position.plus(@direction), action.getDuration()
|
||||||
|
return
|
||||||
|
super action
|
||||||
|
|
||||||
performAction: (action) ->
|
performAction: (action) ->
|
||||||
switch action.id
|
if action.id in [Action.PUSH, Action.FALL]
|
||||||
when Action.PUSH, Action.FALL
|
# log "pushable.performAction #{@name} #{action.id}", @position, @direction
|
||||||
@setCurrentPosition @position.plus @direction.mul action.getRelativeTime()
|
@setCurrentPosition @position.plus @direction.mul action.getRelativeTime()
|
||||||
|
return
|
||||||
|
super action
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
switch action.id
|
if action.id in [Action.PUSH, Action.FALL]
|
||||||
when Action.PUSH, Action.FALL
|
|
||||||
@move_action = null
|
@move_action = null
|
||||||
targetPos = @current_position.round()
|
targetPos = @current_position.round()
|
||||||
world.objectMoved @, @position, targetPos
|
world.objectMoved @, @position, targetPos
|
||||||
|
# log "pushable.finishAction #{action.id}", targetPos
|
||||||
@setPosition targetPos
|
@setPosition targetPos
|
||||||
|
return
|
||||||
|
super action
|
||||||
|
|
||||||
actionFinished: (action) ->
|
actionFinished: (action) ->
|
||||||
|
if action.id in [Action.PUSH, Action.FALL]
|
||||||
Bot = require './bot'
|
Bot = require './bot'
|
||||||
Bomb = require './bomb'
|
Bomb = require './bomb'
|
||||||
if action.id in [Action.PUSH, Action.FALL]
|
|
||||||
gravityDir = @direction
|
gravityDir = @direction
|
||||||
if action.id == Action.PUSH
|
if action.id == Action.PUSH
|
||||||
if @pusher instanceof Bot
|
if @pusher instanceof Bot
|
||||||
|
@ -90,4 +91,7 @@ class Pushable extends Item
|
||||||
@direction.reset()
|
@direction.reset()
|
||||||
world.playSound @landing_sound, @position
|
world.playSound @landing_sound, @position
|
||||||
|
|
||||||
|
return
|
||||||
|
super action
|
||||||
|
|
||||||
module.exports = Pushable
|
module.exports = Pushable
|
||||||
|
|
|
@ -139,6 +139,31 @@ class World extends Actor
|
||||||
global.roty270 = Quaternion.rot_270_Y
|
global.roty270 = Quaternion.rot_270_Y
|
||||||
global.rotz270 = Quaternion.rot_270_Z
|
global.rotz270 = Quaternion.rot_270_Z
|
||||||
|
|
||||||
|
global.XupY = Quaternion.XupY
|
||||||
|
global.XupZ = Quaternion.XupZ
|
||||||
|
global.XdownY = Quaternion.XdownY
|
||||||
|
global.XdownZ = Quaternion.XdownZ
|
||||||
|
global.YupX = Quaternion.YupX
|
||||||
|
global.YupZ = Quaternion.YupZ
|
||||||
|
global.YdownX = Quaternion.YdownX
|
||||||
|
global.YdownZ = Quaternion.YdownZ
|
||||||
|
global.ZupX = Quaternion.ZupX
|
||||||
|
global.ZupY = Quaternion.ZupY
|
||||||
|
global.ZdownX = Quaternion.ZdownX
|
||||||
|
global.ZdownY = Quaternion.ZdownY
|
||||||
|
global.minusXupY = Quaternion.minusXupY
|
||||||
|
global.minusXupZ = Quaternion.minusXupZ
|
||||||
|
global.minusXdownY = Quaternion.minusXdownY
|
||||||
|
global.minusXdownZ = Quaternion.minusXdownZ
|
||||||
|
global.minusYupX = Quaternion.minusYupX
|
||||||
|
global.minusYupZ = Quaternion.minusYupZ
|
||||||
|
global.minusYdownX = Quaternion.minusYdownX
|
||||||
|
global.minusYdownZ = Quaternion.minusYdownZ
|
||||||
|
global.minusZupX = Quaternion.minusZupX
|
||||||
|
global.minusZupY = Quaternion.minusZupY
|
||||||
|
global.minusZdownX = Quaternion.minusZdownX
|
||||||
|
global.minusZdownY = Quaternion.minusZdownY
|
||||||
|
|
||||||
@levels = new Levels
|
@levels = new Levels
|
||||||
|
|
||||||
# 0000000 00000000 00000000 0000000 000000000 00000000
|
# 0000000 00000000 00000000 0000000 000000000 00000000
|
||||||
|
|
Loading…
Reference in New Issue
Block a user