This commit is contained in:
monsterkodi 2016-08-19 22:48:19 +02:00
parent c953279c39
commit f0d7bf95ee
8 changed files with 28 additions and 25 deletions

View File

@ -45,7 +45,7 @@ class Action
i ?= -1 i ?= -1
m ?= Action.ONCE m ?= Action.ONCE
d ?= 0 d ?= 0
log "newAction #{i} #{n} #{d} #{m}" # log "Action.constructor #{i} #{n} #{d} #{m}"
@object = o @object = o
@name = n @name = n
@id = i @id = i
@ -62,7 +62,7 @@ class Action
@deleted = true @deleted = true
perform: () -> perform: () ->
# log "action.perform #{@name} action? #{@object.performAction?} #{@object.name}" # log "Action.perform #{@name} action? #{@object.performAction?} #{@object.name}" if @name == 'push'
if @object.performAction? if @object.performAction?
@object.performAction @ @object.performAction @
else if _.isFunction @object else if _.isFunction @object

View File

@ -20,8 +20,8 @@ class Bomb extends Pushable
@size = 0.55 @size = 0.55
@splitted = false @splitted = false
geom = new THREE.DodecahedronGeometry @size geom = new THREE.DodecahedronGeometry 1
geom2 = new THREE.DodecahedronGeometry @size geom2 = new THREE.DodecahedronGeometry 1
geom2.rotateX Vector.DEG2RAD 90 geom2.rotateX Vector.DEG2RAD 90
geom.merge geom2 geom.merge geom2
@ -34,6 +34,7 @@ class Bomb extends Pushable
shininess: 20 shininess: 20
@mesh = new THREE.Mesh geom, @mat @mesh = new THREE.Mesh geom, @mat
@updateMesh()
super super
@addEventWithName 'explode' @addEventWithName 'explode'

View File

@ -40,19 +40,18 @@ class Item extends Actor
setPosition: (x,y,z) -> setPosition: (x,y,z) ->
@position = new Vector x,y,z @position = new Vector x,y,z
@current_position = new Vector x,y,z @setCurrentPosition @position
@mesh?.position.copy @position
getPos: -> new Pos @current_position getPos: -> new Pos @current_position
setPos: (x,y,z) -> setPos: (x,y,z) -> @setPosition new Pos x,y,z
p = new Pos x,y,z
@position = @current_position = new Vector p
setOrientation: (q) -> setOrientation: (q) ->
@current_orientation = @orientation = new Quaternion q @current_orientation = @orientation = new Quaternion q
# log "item.setOrientation:", @orientation
setCurrentPosition: (p) -> @current_position = p setCurrentPosition: (p) ->
@current_position = new Vector p
@mesh?.position.copy @current_position
setCurrentOrientation: (q) -> @current_orientation = q setCurrentOrientation: (q) -> @current_orientation = q
module.exports = Item module.exports = Item

View File

@ -23,9 +23,9 @@ class Levels
# "cube", # "cube",
# "switch", # "switch",
# "borg", # "borg",
# "mini", "mini",
# "blocks", # "blocks",
"bombs", # "bombs",
# "sandbox", # "sandbox",
# "energy", # "energy",
# "maze", # "maze",

View File

@ -1,7 +1,13 @@
# level design by Owen Hay
# 0000000 00000000 0000000 0000000 00000000
# 000 000 000 000 000 000 000 000
# 000 0000 0000000 000000000 0000000 00000000
# 000 000 000 000 000 000 000 000
# 0000000 000 000 000 000 0000000 000
module.exports = module.exports =
name: "grasp" name: "grasp"
design: "Owen Hay"
scheme: "blue_scheme" scheme: "blue_scheme"
intro: "grasp" intro: "grasp"
size: [11,11,11] size: [11,11,11]
@ -39,7 +45,8 @@ module.exports =
world.addObjectAtPos('KikiStone', s.x/2+2, s.y/2, 4) world.addObjectAtPos('KikiStone', s.x/2+2, s.y/2, 4)
world.addObjectAtPos('KikiStone', s.x/2-2, s.y/2, 4) world.addObjectAtPos('KikiStone', s.x/2-2, s.y/2, 4)
exit_switch = KikiSwitch() Switch = require '../switch'
exit_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit"))) exit_switch = new Switch
world.addObjectAtPos(exit_switch, s.x/2, s.y/2, 0) exit_switch.getEventWithName("switched").addAction continuous -> world.toggle "exit"
world.addObjectAtPos exit_switch, s.x/2, s.y/2, 0

View File

@ -43,23 +43,19 @@ class Pushable extends Item
initAction: (action) -> initAction: (action) ->
switch action.id switch action.id
when Action.PUSH, Action.FALL when Action.PUSH, Action.FALL
# log 'Pushable.initAction FALL direction:', @direction
world.objectWillMoveToPos @, @position.plus(@direction), action.getDuration() world.objectWillMoveToPos @, @position.plus(@direction), action.getDuration()
performAction: (action) -> performAction: (action) ->
# log "Pushable.performAction action #{action.name}"
switch action.id switch action.id
when Action.PUSH, Action.FALL when Action.PUSH, Action.FALL
@setCurrentPosition @position.plus @direction.mul action.getRelativeTime() @setCurrentPosition @position.plus @direction.mul action.getRelativeTime()
finishAction: (action) -> finishAction: (action) ->
# log "Pushable.finishAction #{action.name}"
switch action.id switch action.id
when 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 setPosition:", targetPos
@setPosition targetPos @setPosition targetPos
actionFinished: (action) -> actionFinished: (action) ->

View File

@ -22,7 +22,7 @@ class Timer
@event.removeActionsOfObject o @event.removeActionsOfObject o
@addAction: (a) -> @addAction: (a) ->
log "Timer.addAction #{a.name}" # log "Timer.addAction #{a.name} duration: #{a.duration}"
@event.addAction a @event.addAction a
@removeAction: (a) -> @removeAction: (a) ->

View File

@ -61,7 +61,7 @@ class World extends Actor
super super
@noRotations = false @noRotations = true
@screenSize = new Size @view.clientWidth, @view.clientHeight @screenSize = new Size @view.clientWidth, @view.clientHeight
# log "view @screenSize:", @screenSize # log "view @screenSize:", @screenSize
@ -365,7 +365,7 @@ class World extends Actor
pos = new Pos x, y, z pos = new Pos x, y, z
object = @newObject object object = @newObject object
@setObjectAtPos object, pos @setObjectAtPos object, pos
log "addObjectAtPos #{object.name}", pos # log "addObjectAtPos #{object.name}", pos
@addObject object @addObject object
addObjectLine: (object, sx,sy,sz, ex,ey,ez) -> addObjectLine: (object, sx,sy,sz, ex,ey,ez) ->