orientation

This commit is contained in:
monsterkodi 2016-08-16 19:57:01 +02:00
parent e5d6ea65f1
commit 8fe52dbe50
17 changed files with 224 additions and 158 deletions

View File

@ -124,7 +124,7 @@ class Action
@last = 0 @last = 0
if @mode == Action.CONTINUOUS if @mode == Action.CONTINUOUS
log "action.performWithEvent #{@name} mode == Action.CONTINUOUS" # log "action.performWithEvent #{@name} mode == Action.CONTINUOUS"
@current = @rest @current = @rest
@start = eventTime @start = eventTime
@last = 0 @last = 0

View File

@ -21,6 +21,8 @@ class Actor extends Emitter
@events = [] @events = []
super super
del: -> Timer.removeActionsOfObject @
# 00000000 000 000 00000000 000 000 000000000 # 00000000 000 000 00000000 000 000 000000000
# 000 000 000 000 0000 000 000 # 000 000 000 000 0000 000 000
# 0000000 000 000 0000000 000 0 000 000 # 0000000 000 000 0000000 000 0 000 000

View File

@ -67,6 +67,9 @@ class Bot extends Pushable
@rightTire.rotation.set 0, Vector.DEG2RAD(-90), 0 @rightTire.rotation.set 0, Vector.DEG2RAD(-90), 0
@mesh.add @rightTire @mesh.add @rightTire
@mesh.castShadow = @rightTire.castShadow = @leftTire.castShadow = true
@mesh.receiveShadow = @leftTire.receiveShadow = @rightTire.receiveShadow = true
@left_tire_rot = 0.0 @left_tire_rot = 0.0
@right_tire_rot = 0.0 @right_tire_rot = 0.0
@last_fume = 0 @last_fume = 0
@ -112,13 +115,13 @@ class Bot extends Pushable
# 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 0000
# 0000000 000 000 000 00000000 0000000 000 000 0000000 000 000 # 0000000 000 000 000 00000000 0000000 000 000 0000000 000 000
getDown: -> @orientation.rotate new Vector 0,-1,0 getDown: -> @orientation.rotate Vector.minusY
getUp: -> @orientation.rotate new Vector 0,1,0 getUp: -> @orientation.rotate Vector.unitY
getDir: -> @orientation.rotate new Vector 0,0,@dir_sgn getDir: -> @orientation.rotate new Vector 0,0,@dir_sgn
getCurrentDir: -> @current_orientation.rotate(new Vector 0,0,1).normal() getCurrentDir: -> @current_orientation.rotate(Vector.unitZ).normal()
getCurrentUp: -> @current_orientation.rotate(new Vector 0,1,0).normal() getCurrentUp: -> @current_orientation.rotate(Vector.unitY).normal()
getCurrentLeft: -> @current_orientation.rotate(new Vector 1,0,0).normal() getCurrentLeft: -> @current_orientation.rotate(Vector.unitX).normal()
addMoves: (m) -> @moves += m addMoves: (m) -> @moves += m
addHealth: (h) -> @health = Math.max @health+h addHealth: (h) -> @health = Math.max @health+h
@ -254,6 +257,7 @@ class Bot extends Pushable
if not @direction.isZero() if not @direction.isZero()
super action super action
return return
log 'still needed?'
@current_position = @position.plus @getDown().mul(relTime) @current_position = @position.plus @getDown().mul(relTime)
return return
@ -261,7 +265,7 @@ class Bot extends Pushable
@left_tire_rot += @dir_sgn * dltTime/2 @left_tire_rot += @dir_sgn * dltTime/2
@right_tire_rot += @dir_sgn * dltTime/2 @right_tire_rot += @dir_sgn * dltTime/2
@climb_orientation = Quaternion.rotationAroundVector @dir_sgn * relTime * -90.0, new Vector 1,0,0 @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * relTime * -90.0, Vector.unitX
break break
when Action.CLIMB_DOWN when Action.CLIMB_DOWN
@ -271,11 +275,11 @@ class Bot extends Pushable
if relTime <= 0.2 if relTime <= 0.2
@current_position = @position.plus @getDir().mul (relTime/0.2)/2 @current_position = @position.plus @getDir().mul (relTime/0.2)/2
else if (relTime >= 0.8) else if (relTime >= 0.8)
@climb_orientation = Quaternion.rotationAroundVector @dir_sgn * 90.0, new Vector 1,0,0 @climb_orientation = Quaternion.rotationAroundVector @dir_sgn * 90.0, Vector.unitX
@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, Vector.unitX
rotVec = (@orientation.mul @climb_orientation).rotate new Vector 0,1,0 rotVec = (@orientation.mul @climb_orientation).rotate Vector.unitY
@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
@ -284,20 +288,20 @@ 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 action.id == 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, Vector.unitY
@rest_orientation = Quaternion.rotationAroundVector -90.0, new Vector 0,1,0 @rest_orientation = Quaternion.rotationAroundVector -90.0, Vector.unitY
else else
@orientation = @orientation.mul Quaternion.rotationAroundVector -90.0, new Vector 0,1,0 @orientation = @orientation.mul Quaternion.rotationAroundVector -90.0, Vector.unitY
@rest_orientation = Quaternion.rotationAroundVector 90.0, new Vector 0,1,0 @rest_orientation = Quaternion.rotationAroundVector 90.0, Vector.unitY
if action.id == 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, Vector.unitY
else else
@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, Vector.unitY
break break
else else
@ -315,12 +319,13 @@ class Bot extends Pushable
finishAction: (action) -> finishAction: (action) ->
log "Bot.finishAction #{action.id} #{action.name}" if action.name != 'noop' # 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
return return
when Action.PUSH when Action.PUSH, Action.FALL
@move_action = null
super action super action
return return
when Action.TURN_LEFT, Action.TURN_RIGHT when Action.TURN_LEFT, Action.TURN_RIGHT
@ -345,10 +350,10 @@ class Bot extends Pushable
# take over result of rotation to prevent sliding # take over result of rotation to prevent sliding
if @rotate_action.id == Action.TURN_LEFT if @rotate_action.id == Action.TURN_LEFT
@orientation = @orientation.mul Quaternion.rotationAroundVector(90.0, new Vector(0,1,0)).mul @rest_orientation @orientation = @orientation.mul Quaternion.rotationAroundVector(90.0, new Vector(0,1,0)).mul @rest_orientation
@rest_orientation = Quaternion.rotationAroundVector -90.0, new Vector 0,1,0 @rest_orientation = Quaternion.rotationAroundVector -90.0, Vector.unitY
else else
@orientation = @orientation.mul Quaternion.rotationAroundVector(-90.0, new Vector(0,1,0)).mul @rest_orientation @orientation = @orientation.mul Quaternion.rotationAroundVector(-90.0, new Vector(0,1,0)).mul @rest_orientation
@rest_orientation = Quaternion.rotationAroundVector 90.0, new Vector 0,1,0 @rest_orientation = Quaternion.rotationAroundVector 90.0, Vector.unitY
if action.id != Action.CLIMB_UP if action.id != Action.CLIMB_UP
targetPos = @current_position.round() targetPos = @current_position.round()
@ -366,7 +371,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}"
# if @isDead() # if @isDead()
# log "DIE!" # log "DIE!"
@ -404,6 +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 empty', world.isUnoccupiedPos(@position.plus @getDown()), @position.plus @getDown()
if @move # sticky if moving if @move # sticky if moving
if world.isUnoccupiedPos @position.plus @getDir() # forward will be empty if world.isUnoccupiedPos @position.plus @getDir() # forward will be empty
if world.isOccupiedPos @position.plus @getDir().minus @getUp() # below forward is solid if world.isOccupiedPos @position.plus @getDir().minus @getUp() # below forward is solid
@ -417,9 +423,10 @@ class Bot extends Pushable
if @move_action == null if @move_action == null
@move_action = @getActionWithId Action.FALL @move_action = @getActionWithId Action.FALL
@direction = @getDown()
else if action.id == Action.FALL or action.id == Action.FALL_FORWARD # landed else if action.id in [Action.FALL_FORWARD, Action.FALL] # landed
if @ == world.player if @name == 'player'
world.playSound 'BOT_LAND' world.playSound 'BOT_LAND'
else else
world.playSound 'BOT_LAND', @getPos() world.playSound 'BOT_LAND', @getPos()

View File

@ -27,6 +27,7 @@ class Cage
@raster.translateX -0.5 @raster.translateX -0.5
@raster.translateY -0.5 @raster.translateY -0.5
@raster.translateZ -0.5 @raster.translateZ -0.5
@raster.receiveShadow = true
world.scene.add @raster world.scene.add @raster
geom = @wallTiles @gap geom = @wallTiles @gap
@ -34,6 +35,7 @@ class Cage
@cage.translateX -0.5 @cage.translateX -0.5
@cage.translateY -0.5 @cage.translateY -0.5
@cage.translateZ -0.5 @cage.translateZ -0.5
@cage.receiveShadow = true
world.scene.add @cage world.scene.add @cage
del: -> del: ->

View File

@ -39,7 +39,9 @@ class Gate extends Switch
t3.rotateX Vector.DEG2RAD 90 t3.rotateX Vector.DEG2RAD 90
t2.merge t3 t2.merge t3
@tors = new THREE.Mesh t2, @mat @tors = new THREE.Mesh t2, @mat
@tors.castShadow = true
@mesh.add @tors @mesh.add @tors
@mesh.castShadow = true
@mesh @mesh
bulletImpact: -> bulletImpact: ->

View File

@ -23,8 +23,9 @@ class Item extends Actor
@direction = new Vector @direction = new Vector
@move_action = null @move_action = null
del: -> del: ->
log "item del!!!!!!!!!!!!!!!!!!!!!! #{@name}" super
log "item del !!!!!!!!!!!!!!!!!!!!!! #{@name}"
world.scene.remove @mesh if @mesh? world.scene.remove @mesh if @mesh?
world.removeObject @ world.removeObject @
@emit 'deleted' @emit 'deleted'
@ -47,7 +48,11 @@ class Item extends Actor
p = new Pos x,y,z p = new Pos x,y,z
@position = @current_position = new Vector p @position = @current_position = new Vector p
setOrientation: (q) -> @current_orientation = @orientation = new Quaternion q setOrientation: (q) ->
@current_orientation = @orientation = new Quaternion q
# log "item.setOrientation:", @orientation
@orientation
setCurrentPosition: (p) -> @current_position = p setCurrentPosition: (p) -> @current_position = p
setCurrentOrientation: (q) -> @current_orientation = q setCurrentOrientation: (q) -> @current_orientation = q

48
coffee/levels.coffee Normal file
View File

@ -0,0 +1,48 @@
# 000 00000000 000 000 00000000 000 0000000
# 000 000 000 000 000 000 000
# 000 0000000 000 000 0000000 000 0000000
# 000 000 000 000 000 000
# 0000000 00000000 0 00000000 0000000 0000000
class Levels
constructor: () ->
@dict = {}
@list = [
# intro
# "steps",
"start",
#"move", "electro", "elevate",
# "throw",
# easy
# "gold",
"jump", "escape", "gears",
# "gamma",
"cube", "switch", "borg",
"mini",
# "blocks",
"bombs", "sandbox", "energy", "maze", "love",
# medium
"towers", "edge", "random", "plate", "nice", "entropy",
# owen hay's levels (TODO: sort in)
"grasp", "fallen", "cheese", "invisimaze", "spiral",
# difficult
"slick", "bridge", "flower", "stones", "walls", "grid",
"rings",
# "core",
"bronze", "pool",
# tough
"hidden", "church",
# "strange",
"mesh", "columns", "machine",
# very hard
# "neutron",
"captured", "circuit", "regal", "conductor", "evil",
# outro
"mutants"]
# import the levels
for levelName in @list
@dict[levelName] = require "./levels/#{levelName}"
module.exports = Levels

View File

@ -33,33 +33,33 @@ module.exports =
exit_switch.getEventWithName("switched").addAction world.continuous () -> world.toggle "exit" exit_switch.getEventWithName("switched").addAction world.continuous () -> world.toggle "exit"
world.addObjectAtPos(exit_switch, world.decenter( 0, -2, 0)) world.addObjectAtPos(exit_switch, world.decenter( 0, -2, 0))
world.addObjectAtPos('KikiStone', world.decenter( 0, s.y/2, 0)) world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2, 0
world.addObjectAtPos('KikiStone', world.decenter( 1, s.y/2, 0)) world.addObjectAtPos 'KikiStone', world.decenter 1, s.y/2, 0
world.addObjectAtPos('KikiStone', world.decenter( 0, s.y/2, 1)) world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2, 1
world.addObjectAtPos('KikiStone', world.decenter( 0, s.y/2,-1)) world.addObjectAtPos 'KikiStone', world.decenter 0, s.y/2,-1
world.addObjectAtPos('KikiStone', world.decenter(-1, s.y/2, 0)) world.addObjectAtPos 'KikiStone', world.decenter -1, s.y/2, 0
world.addObjectLine('KikiStone', world.decenter(-2, s.y/2,-2), world.decenter( 2, s.y/2,-2)) world.addObjectLine 'KikiStone', world.decenter(-2, s.y/2,-2), world.decenter( 2, s.y/2,-2)
world.addObjectLine('KikiStone', world.decenter( 2, s.y/2,-2), world.decenter( 2, s.y/2, 2)) world.addObjectLine 'KikiStone', world.decenter( 2, s.y/2,-2), world.decenter( 2, s.y/2, 2)
world.addObjectLine('KikiStone', world.decenter( 2, s.y/2, 2), world.decenter(-2, s.y/2, 2)) world.addObjectLine 'KikiStone', world.decenter( 2, s.y/2, 2), world.decenter(-2, s.y/2, 2)
world.addObjectLine('KikiStone', world.decenter(-2, s.y/2, 2), world.decenter(-2, s.y/2,-2)) world.addObjectLine 'KikiStone', world.decenter(-2, s.y/2, 2), world.decenter(-2, s.y/2,-2)
world.addObjectAtPos('KikiWall', world.decenter( 1, 0, 0)) world.addObjectAtPos 'KikiWall', world.decenter 1, 0, 0
world.addObjectAtPos('KikiWall', world.decenter( 0, 0, 1)) world.addObjectAtPos 'KikiWall', world.decenter 0, 0, 1
world.addObjectAtPos('KikiWall', world.decenter(-1, 0, 0)) world.addObjectAtPos 'KikiWall', world.decenter -1, 0, 0
world.addObjectAtPos('KikiWall', world.decenter( 0, 0,-1)) world.addObjectAtPos 'KikiWall', world.decenter 0, 0,-1
world.addObjectAtPos('KikiWall', world.decenter( 1,-1, 0)) world.addObjectAtPos 'KikiWall', world.decenter 1,-1, 0
world.addObjectAtPos('KikiWall', world.decenter( 0,-1, 1)) world.addObjectAtPos 'KikiWall', world.decenter 0,-1, 1
world.addObjectAtPos('KikiWall', world.decenter(-1,-1, 0)) world.addObjectAtPos 'KikiWall', world.decenter -1,-1, 0
world.addObjectAtPos('KikiWall', world.decenter( 0,-1,-1)) world.addObjectAtPos 'KikiWall', world.decenter 0,-1,-1
world.addObjectAtPos('KikiWall', world.decenter( 1,-1, 1)) world.addObjectAtPos 'KikiWall', world.decenter 1,-1, 1
world.addObjectAtPos('KikiWall', world.decenter(-1,-1, 1)) world.addObjectAtPos 'KikiWall', world.decenter -1,-1, 1
world.addObjectAtPos('KikiWall', world.decenter(-1,-1,-1)) world.addObjectAtPos 'KikiWall', world.decenter -1,-1,-1
world.addObjectAtPos('KikiWall', world.decenter( 1,-1,-1)) world.addObjectAtPos 'KikiWall', world.decenter 1,-1,-1
world.addObjectAtPos('KikiWall', world.decenter( 1,-2, 0)) world.addObjectAtPos 'KikiWall', world.decenter 1,-2, 0
world.addObjectAtPos('KikiWall', world.decenter( 0,-2, 1)) world.addObjectAtPos 'KikiWall', world.decenter 0,-2, 1
world.addObjectAtPos('KikiWall', world.decenter(-1,-2, 0)) world.addObjectAtPos 'KikiWall', world.decenter -1,-2, 0
world.addObjectAtPos('KikiWall', world.decenter( 0,-2,-1)) world.addObjectAtPos 'KikiWall', world.decenter 0,-2,-1

View File

@ -17,14 +17,13 @@ module.exports =
to get to the exit, to get to the exit,
jump on the stone jump on the stone
to jump, to jump,
press "$key(jump)" press "$key(jump)" while moving
while movin
to move, press "$key(move forward)" or "$key(move backward)" to move, press "$key(move forward)" or "$key(move backward)"
to turn, press "$key(turn left)" or "$key(turn right)" to turn, press "$key(turn left)" or "$key(turn right)"
""" """
player: player:
coordinates: [3,0,3] position: [0,0,4]
nostatus: 0 orientation: rotx270
exits: [ exits: [
name: "exit" name: "exit"
active: 1 active: 1

View File

@ -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:
coordinates: [4,4,8] position: [0,0,-5]
nostatus: 0 orientation: roty0
exits: [ exits: [
name: "exit" name: "exit"
active: 1 active: 1

View File

@ -125,11 +125,18 @@ class Vector
@DEG2RAD: (d) -> Math.PI*d/180.0 @DEG2RAD: (d) -> Math.PI*d/180.0
@RAD2DEG: (r) -> r*180.0/Math.PI @RAD2DEG: (r) -> r*180.0/Math.PI
@unitX = new Vector 1,0,0
@unitY = new Vector 0,1,0
@unitZ = new Vector 0,0,1
@minusX = new Vector -1,0,0
@minusY = new Vector 0,-1,0
@minusZ = new Vector 0,0,-1
@X = 0 @X = 0
@SX = 0
@Y = 1 @Y = 1
@Z = 2 @Z = 2
@W = 3 @W = 3
@SX = 0
@SY = 5 @SY = 5
@SZ = 10 @SZ = 10
@TX = 12 @TX = 12

View File

@ -15,6 +15,10 @@ class Light extends Item
# @diffuse_color = colors[KikiLight_diffuse_color] # @diffuse_color = colors[KikiLight_diffuse_color]
# @specular_color = colors[KikiLight_specular_color] # @specular_color = colors[KikiLight_specular_color]
@point = new THREE.PointLight 0xffffff, @intensity, @radius, 2 @point = new THREE.PointLight 0xffffff, @intensity, @radius, 2
@point.castShadow = true
@point.shadowDarkness = 0.5
@point.shadow.mapSize = new THREE.Vector2 2048, 2048
@point.shadow.bias = 0.01
geom = new THREE.SphereGeometry 0.3, 16, 16 geom = new THREE.SphereGeometry 0.3, 16, 16
mat = new THREE.MeshLambertMaterial mat = new THREE.MeshLambertMaterial
color: 0xffffff color: 0xffffff
@ -27,10 +31,12 @@ class Light extends Item
@mesh = new THREE.Mesh geom, mat @mesh = new THREE.Mesh geom, mat
world.scene.add @point world.scene.add @point
world.addLight @
@setPosition pos if pos? @setPosition pos if pos?
super super
del: -> del: ->
world.removeLight @
world.scene.remove @point world.scene.remove @point
super super

View File

@ -251,10 +251,10 @@ class Player extends Bot
super action super action
finishRotateAction: () -> # finishRotateAction: () ->
if @rotate_action # if @rotate_action
@rotate = false # @rotate = false
@finishAction @rotate_action # @finishAction @rotate_action
# 00000000 00000000 00000000 00000000 0000000 00000000 00 00 # 00000000 00000000 00000000 00000000 0000000 00000000 00 00
# 000 000 000 000 000 000 000 000 000 000 000 000 # 000 000 000 000 000 000 000 000 000 000 000 000
@ -307,14 +307,14 @@ class Player extends Bot
reborn: () -> reborn: () ->
@died = false @died = false
reset: () -> # reset: () ->
super # super
Timer.removeActionsOfObject @ # Timer.removeActionsOfObject @
#
@look_action = null # @look_action = null
@look_angle = 0.0 # @look_angle = 0.0
@new_dir_sgn = 1.0 # @new_dir_sgn = 1.0
@rotate = 0 # @rotate = 0
# 000 000 00000000 000 000 # 000 000 00000000 000 000
# 000 000 000 000 000 # 000 000 000 000 000
@ -356,8 +356,8 @@ class Player extends Bot
@moveBot() # perform new move action (depending on environment) @moveBot() # perform new move action (depending on environment)
@jump_once = false @jump_once = false
else else
if @move_action.name == 'move forward' and @move_action.getRelativeTime() < 0.6 or if @move_action.id == Action.MOVE and @move_action.getRelativeTime() < 0.6 or
@move_action.name == 'climb down' and @move_action.getRelativeTime() < 0.4 @move_action.id == Action.CLIMB_DOWN and @move_action.getRelativeTime() < 0.4
if world.isUnoccupiedPos @position.plus @getUp() if world.isUnoccupiedPos @position.plus @getUp()
if world.isUnoccupiedPos @position.plus @getUp().plus @getDir() if world.isUnoccupiedPos @position.plus @getUp().plus @getDir()
action = @getActionWithId Action.JUMP_FORWARD action = @getActionWithId Action.JUMP_FORWARD
@ -367,8 +367,8 @@ class Player extends Bot
Timer.removeAction @move_action Timer.removeAction @move_action
@move_action = action @move_action = action
Timer.addAction @move_action Timer.addAction @move_action
else else if @move_action.id in [Action.JUMP, Action.JUMP_FORWARD]
log "cant jump #{@move_action.name}" @jump_once = false
return true return true
when @key.push when @key.push

View File

@ -16,15 +16,21 @@ class Pushable extends Item
constructor: () -> constructor: () ->
super super
@pusher = null @pusher = null
@direction = new Vector @direction = Vector.minusY
@addAction new Action @, Action.NOOP, "noop" @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
setOrientation: (q) ->
super q
if not @pusher?
@direction = @orientation.rotate Vector.minusZ
# log "Pushable.setOrientation direction:", @direction
pushedByObjectInDirection: (object, dir, duration) -> pushedByObjectInDirection: (object, dir, duration) ->
pushAction = @getActionWithId Action.PUSH pushAction = @getActionWithId Action.PUSH
@pusher = object @pusher = object
@move_action = pushAction @move_action = pushAction
@ -50,12 +56,13 @@ class Pushable extends Item
switch action.id switch action.id
when Action.PUSH, Action.FALL when Action.PUSH, Action.FALL
@move_action = null @move_action = null
world.objectMoved @, @position, @current_position targetPos = @current_position.round()
# log "Pushable.finishAction setPosition #{@current_position}" world.objectMoved @, @position, targetPos
@setPosition @current_position log "Pushable.finishAction setPosition:", targetPos
@setPosition targetPos
actionFinished: (action) -> actionFinished: (action) ->
if action.id == Action.PUSH or actionId == Action.FALL if action.id in [Action.PUSH, Action.FALL]
gravityDir = @direction gravityDir = @direction
if action.id == Action.PUSH if action.id == Action.PUSH
@ -76,6 +83,7 @@ class Pushable extends Item
if world.isUnoccupiedPos @position.plus gravityDir if world.isUnoccupiedPos @position.plus gravityDir
@direction = gravityDir @direction = gravityDir
@move_action = @getActionWithId Action.FALL @move_action = @getActionWithId Action.FALL
log 'Pushable.actionFinished below empty, fall!'
Timer.addAction @move_action Timer.addAction @move_action
else else
@direction.reset() @direction.reset()

View File

@ -34,6 +34,10 @@ class Switch extends Item
@setActive active @setActive active
del: () ->
super
@light?.del()
createMesh: () -> createMesh: () ->
torusRadius = 0.05 torusRadius = 0.05
t1 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32 t1 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32
@ -43,6 +47,7 @@ class Switch extends Item
shading: THREE.SmoothShading shading: THREE.SmoothShading
shininess: 5 shininess: 5
@mesh = new THREE.Mesh t1, @mat @mesh = new THREE.Mesh t1, @mat
@mesh.castShadow = true
t2 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32 t2 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32
t3 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32 t3 = new THREE.TorusGeometry 0.5-torusRadius, torusRadius, 16, 32
@ -50,13 +55,12 @@ class Switch extends Item
t3.rotateX Vector.DEG2RAD 90 t3.rotateX Vector.DEG2RAD 90
t2.merge t3 t2.merge t3
@tors = new THREE.Mesh t2, @mat @tors = new THREE.Mesh t2, @mat
@tors.castShadow = true
@mesh.add @tors @mesh.add @tors
@mesh @mesh
bulletImpact: -> @setActive not @active bulletImpact: -> @setActive not @active
del: () -> @light?.del()
lightDeleted: () -> @light = null lightDeleted: () -> @light = null
setActive: (status) -> setActive: (status) ->
@ -89,9 +93,9 @@ class Switch extends Item
animate: (f) -> animate: (f) ->
@angle += f * 360 @angle += f * 360
@mesh.quaternion.copy Quaternion.rotationAroundVector @angle, new Vector 0,1,0 @mesh.quaternion.copy Quaternion.rotationAroundVector @angle, Vector.unitY
@tors.quaternion.copy Quaternion.rotationAroundVector @angle/2, new Vector 0,0,1 @tors.quaternion.copy Quaternion.rotationAroundVector @angle/2, Vector.unitZ
# @tort.quaternion.copy Quaternion.rotationAroundVector @angle/2, new Vector 0,0,1 # @tort.quaternion.copy Quaternion.rotationAroundVector @angle/2, Vector.unitZ
performAction: (action) -> performAction: (action) ->

View File

@ -22,6 +22,8 @@ class Wall extends Item
opacity: 0.85 opacity: 0.85
shininess: 5 shininess: 5
@mesh = new THREE.Mesh @geom, @mat @mesh = new THREE.Mesh @geom, @mat
@mesh.castShadow = true
@mesh.receiveShadow = true
super super
# s = 0.45 # s = 0.45

View File

@ -15,6 +15,7 @@ Size = require './lib/size'
Cell = require './cell' Cell = require './cell'
Gate = require './gate' Gate = require './gate'
Light = require './light' Light = require './light'
Levels = require './levels'
Player = require './player' Player = require './player'
Cage = require './cage' Cage = require './cage'
Timer = require './timer' Timer = require './timer'
@ -35,8 +36,7 @@ class World extends Actor
@CAMERA_BEHIND = 1 @CAMERA_BEHIND = 1
@CAMERA_FOLLOW = 2 @CAMERA_FOLLOW = 2
@levelList = [] @levels = null
@levelDict = []
@normals = [ @normals = [
new Vector 1, 0, 0 new Vector 1, 0, 0
@ -67,6 +67,7 @@ class World extends Actor
@renderer.setClearColor 0x000000 @renderer.setClearColor 0x000000
@renderer.setSize @view.offsetWidth, @view.offsetHeight @renderer.setSize @view.offsetWidth, @view.offsetHeight
@renderer.shadowMap.type = THREE.PCFSoftShadowMap
# 0000000 0000000 00 00 00000000 00000000 0000000 # 0000000 0000000 00 00 00000000 00000000 0000000
# 000 000 000 000 000 000 000 000 000 000 # 000 000 000 000 000 000 000 000 000 000
@ -124,66 +125,26 @@ class World extends Actor
world.name = 'world' world.name = 'world'
global.world = world global.world = world
Timer.init() Timer.init()
world.create first @levelList world.create first @levels.list
world world
@initGlobal: () -> @initGlobal: () ->
return if @levelList.length return if @levels?
global.rot0 = new Quaternion() global.rot0 = new Quaternion()
global.rotz180 = Quaternion.rotationAroundVector 180, new Vector 0,0,1 global.rotz90 = Quaternion.rotationAroundVector 90, Vector.unitZ
global.rotz90 = Quaternion.rotationAroundVector 90, new Vector 0,0,1 global.rotz180 = Quaternion.rotationAroundVector 180, Vector.unitZ
global.roty270 = Quaternion.rotationAroundVector 270, new Vector 0,1,0 global.roty0 = Quaternion.rotationAroundVector 0, Vector.unitY
global.roty180 = Quaternion.rotationAroundVector 180, new Vector 0,1,0 global.roty90 = Quaternion.rotationAroundVector 90, Vector.unitY
global.roty90 = Quaternion.rotationAroundVector 90, new Vector 0,1,0 global.roty180 = Quaternion.rotationAroundVector 180, Vector.unitY
global.roty0 = Quaternion.rotationAroundVector 0, new Vector 0,1,0 global.roty270 = Quaternion.rotationAroundVector 270, Vector.unitY
global.rotx180 = Quaternion.rotationAroundVector 180, new Vector 1,0,0 global.rotx90 = Quaternion.rotationAroundVector 90, Vector.unitX
global.rotx90 = Quaternion.rotationAroundVector 90, new Vector 1,0,0 global.rotx180 = Quaternion.rotationAroundVector 180, Vector.unitX
global.rotx270 = Quaternion.rotationAroundVector 270, Vector.unitX
# 000 00000000 000 000 00000000 000 0000000
# 000 000 000 000 000 000 000
# 000 0000000 000 000 0000000 000 0000000
# 000 000 000 000 000 000
# 0000000 00000000 0 00000000 0000000 0000000
@levelList = [
# intro
"steps",
# "start",
#"move", "electro", "elevate",
# "throw",
# easy
# "gold",
"jump", "escape", "gears",
# "gamma",
"cube", "switch", "borg",
"mini",
# "blocks",
"bombs", "sandbox", "energy", "maze", "love",
# medium
"towers", "edge", "random", "plate", "nice", "entropy",
# owen hay's levels (TODO: sort in)
"grasp", "fallen", "cheese", "invisimaze", "spiral",
# difficult
"slick", "bridge", "flower", "stones", "walls", "grid",
"rings",
# "core",
"bronze", "pool",
# tough
"hidden", "church",
# "strange",
"mesh", "columns", "machine",
# very hard
# "neutron",
"captured", "circuit", "regal", "conductor", "evil",
# outro
"mutants"]
# import the levels
for levelName in @levelList
@levelDict[levelName] = require "./levels/#{levelName}"
@levels = new Levels
# 0000000 00000000 00000000 0000000 000000000 00000000 # 0000000 00000000 00000000 0000000 000000000 00000000
# 000 000 000 000 000 000 000 000 # 000 000 000 000 000 000 000 000
# 000 0000000 0000000 000000000 000 0000000 # 000 0000000 0000000 000000000 000 0000000
@ -196,9 +157,9 @@ class World extends Actor
if worldDict if worldDict
if _.isString worldDict if _.isString worldDict
@level_index = World.levelList.indexOf worldDict @level_index = World.levels.list.indexOf worldDict
@level_name = worldDict @level_name = worldDict
@dict = World.levelDict[worldDict] @dict = World.levels.dict[worldDict]
else else
@dict = worldDict @dict = worldDict
@ -272,7 +233,7 @@ class World extends Actor
@player = new Player @player = new Player
# log "player_dict", player_dict # log "player_dict", player_dict
@player.setOrientation @dict.player.orientation ? roty90 @player.setOrientation @dict.player.orientation ? rotx90
if @dict.player.position? if @dict.player.position?
@addObjectAtPos @player, @decenter @dict.player.position @addObjectAtPos @player, @decenter @dict.player.position
@ -329,16 +290,32 @@ class World extends Actor
world.moveObjectToPos @player, world.decenter @dict.player.resetPosition world.moveObjectToPos @player, world.decenter @dict.player.resetPosition
else else
world.moveObjectToPos @player, world.decenter @dict.player.position world.moveObjectToPos @player, world.decenter @dict.player.position
# 000 000 0000000 000 000 000000000
# 000 000 000 000 000 000
# 000 000 000 0000 000000000 000
# 000 000 000 000 000 000 000
# 0000000 000 0000000 000 000 000
addLight: (light) ->
@lights.push light
@enableShadows true
removeLight: (light) ->
_.pull @lights, light
@enableShadows false if not @lights.length
enableShadows: (enable) ->
@renderer.shadowMap.enabled = enable
# 0000000 0000000 000000000 000 0000000 000 000 # 0000000 0000000 000000000 000 0000000 000 000
# 000 000 000 000 000 000 000 0000 000 # 000 000 000 000 000 000 000 0000 000
# 000000000 000 000 000 000 000 000 0 000 # 000000000 000 000 000 000 000 000 0 000
# 000 000 000 000 000 000 000 000 0000 # 000 000 000 000 000 000 000 000 0000
# 000 000 0000000 000 000 0000000 000 000 # 000 000 0000000 000 000 0000000 000 000
exitLevel: (action) => exitLevel: (action) =>
log "world.exitLevel #{action}" log "world.exitLevel", action
@finish() @finish()
# @player.status.setMoves 0 # @player.status.setMoves 0
exitIndex = parseInt action.name.slice 5 exitIndex = parseInt action.name.slice 5
@ -347,9 +324,8 @@ class World extends Actor
# w = @dict.exits[exitIndex].world # w = @dict.exits[exitIndex].world
# w() if _.isFunction w # w() if _.isFunction w
# else # else
# world = world.create levelList[world.level_index+1] log "world.level_index #{world.level_index} nextLevel #{World.levels.list[world.level_index+1]}"
log "world.level_index #{world.level_index} nextLevel #{World.levelList[world.level_index+1]}" world.create World.levels.list[world.level_index+1]
world.create World.levelList[world.level_index+1]
activate: (objectName) -> activate: (objectName) ->
# activates object with name objectName # activates object with name objectName
@ -645,13 +621,11 @@ class World extends Actor
deleteAllObjects: () -> deleteAllObjects: () ->
log 'world.deleteAllObjects' log 'world.deleteAllObjects'
Timer.removeAllActions()
if @player? if @player?
@player.finishRotateAction() @player.del()
@removeObject @player # remove the player first, to keep it's state
Timer.removeAllActions()
# Controller.removeKeyHandler (Controller.player) # prevent keyboard input while building world
@player.reset()
while @lights.length while @lights.length
oldSize = @lights.length oldSize = @lights.length
@ -664,7 +638,7 @@ class World extends Actor
oldSize = @objects.length oldSize = @objects.length
last(@objects).del() # destructor will call remove object last(@objects).del() # destructor will call remove object
if oldSize == @objects.length if oldSize == @objects.length
log "WARNING World.deleteAllObjects object no auto remove" log "WARNING World.deleteAllObjects object no auto remove #{last(@objects).name}"
@objects.pop() @objects.pop()
deleteObjectsWithClassName: (className) -> deleteObjectsWithClassName: (className) ->