From 17dbe2b590c7fcc609de71d4926f5bdcbdfa1af4 Mon Sep 17 00:00:00 2001 From: monsterkodi Date: Fri, 12 Aug 2016 00:07:30 +0200 Subject: [PATCH] action --- coffee/action.coffee | 16 ++++- coffee/actor.coffee | 12 ++-- coffee/bot.coffee | 130 +++++++++++++++++++++-------------------- coffee/player.coffee | 71 +++++++++++----------- coffee/pushable.coffee | 26 +++++---- coffee/world.coffee | 16 +++-- 6 files changed, 151 insertions(+), 120 deletions(-) diff --git a/coffee/action.coffee b/coffee/action.coffee index 9456b31..4a6e99f 100644 --- a/coffee/action.coffee +++ b/coffee/action.coffee @@ -6,6 +6,20 @@ class Action + @NOOP = 0 + @PUSH = 1 + @FALL = 2 + @FORWARD = 3 + @CLIMB_UP = 4 + @CLIMB_DOWN = 5 + @TURN_LEFT = 6 + @TURN_RIGHT = 7 + @JUMP = 8 + @JUMP_FORWARD = 9 + @FALL_FORWARD = 10 + @SHOOT = 11 + @END = 12 + constructor: (o, i, n, d, m) -> @action_object = o @@ -66,7 +80,7 @@ class Action return @current / @getDuration() getDuration: () -> - return Controller.mapMsTime @duration + return world.mapMsTime @duration performWithEvent: (event) -> eventTime = event.getTime() diff --git a/coffee/actor.coffee b/coffee/actor.coffee index 53db60f..1193676 100644 --- a/coffee/actor.coffee +++ b/coffee/actor.coffee @@ -6,10 +6,11 @@ # 000 000 0000000 000 0000000 000 000 { last -} = require '/Users/kodi/s/ko/js/tools/tools' -log = require '/Users/kodi/s/ko/js/tools/log' -event = require 'events' -_ = require 'lodash' +} = require '/Users/kodi/s/ko/js/tools/tools' +log = require '/Users/kodi/s/ko/js/tools/log' +Action = require './action' +event = require 'events' +_ = require 'lodash' class Actor extends event @@ -72,4 +73,5 @@ class Actor extends event getEventWithId: (eventId) -> return @events[eventId] - \ No newline at end of file + +module.exports = Actor diff --git a/coffee/bot.coffee b/coffee/bot.coffee index 0d33972..5d191eb 100644 --- a/coffee/bot.coffee +++ b/coffee/bot.coffee @@ -26,8 +26,11 @@ class Bot extends Pushable @left_tire_rot = 0.0 @right_tire_rot = 0.0 @last_fume = 0 - - @status = new KikiBotStatus @ + + @moves = 0 + @health = 1 + @minMoves = 100 + @move = false @push = false @jump = false @@ -42,21 +45,24 @@ class Bot extends Pushable @dir_sgn = 1.0 - @addAction new KikiAction @, ACTION_NOOP, "noop", 0 - @addAction new KikiAction @, ACTION_FORWARD, "move forward", 200 - @addAction new KikiAction @, ACTION_CLIMB_UP, "climb up", 200 - @addAction new KikiAction @, ACTION_CLIMB_DOWN, "climb down", 500 - @addAction new KikiAction @, ACTION_TURN_LEFT, "turn left", 200 - @addAction new KikiAction @, ACTION_TURN_RIGHT, "turn right", 200 - @addAction new KikiAction @, ACTION_JUMP, "jump", 120 - @addAction new KikiAction @, ACTION_JUMP_FORWARD, "jump forward", 200 - @addAction new KikiAction @, ACTION_FALL_FORWARD, "fall forward", 200 - @addAction new KikiAction @, ACTION_SHOOT, "shoot", 200, KikiAction.REPEAT + @addAction new KikiAction @, Action.NOOP, "noop", 0 + @addAction new KikiAction @, Action.FORWARD, "move forward", 200 + @addAction new KikiAction @, Action.CLIMB_UP, "climb up", 200 + @addAction new KikiAction @, Action.CLIMB_DOWN, "climb down", 500 + @addAction new KikiAction @, Action.TURN_LEFT, "turn left", 200 + @addAction new KikiAction @, Action.TURN_RIGHT, "turn right", 200 + @addAction new KikiAction @, Action.JUMP, "jump", 120 + @addAction new KikiAction @, Action.JUMP_FORWARD, "jump forward", 200 + @addAction new KikiAction @, Action.FALL_FORWARD, "fall forward", 200 + @addAction new KikiAction @, Action.SHOOT, "shoot", 200, KikiAction.REPEAT - @getActionWithId(ACTION_FALL).setDuration 120 + @getActionWithId(Action.FALL).setDuration 120 @addEventWithName "died" - @startTimedAction @getActionWithId ACTION_NOOP, 500 + @startTimedAction @getActionWithId Action.NOOP, 500 + + addMoves: (m) -> @moves += m + addHealth: (h) -> @health = Math.max @health+h die: () -> # timer_event.removeActionsOfObject (@) @@ -91,20 +97,20 @@ class Bot extends Pushable @spiked = false @died = false - isFalling: -> @move_action and @move_action.getId() == ACTION_FALL + isFalling: -> @move_action and @move_action.getId() == Action.FALL initAction: (action) -> newPos = new KikiPos @position switch action.getId() - when ACTION_NOOP then return + when Action.NOOP then return - when ACTION_FORWARD then newPos += @getDir() - when ACTION_CLIMB_DOWN then newPos += @getDir() + @getDown() - when ACTION_JUMP then newPos += @getUp() - when ACTION_JUMP_FORWARD then newPos += @getUp() + @getDir() - when ACTION_FALL_FORWARD then newPos += @getDown() + @getDir() - when ACTION_FALL + when Action.FORWARD then newPos += @getDir() + when Action.CLIMB_DOWN then newPos += @getDir() + @getDown() + when Action.JUMP then newPos += @getUp() + when Action.JUMP_FORWARD then newPos += @getUp() + @getDir() + when Action.FALL_FORWARD then newPos += @getDown() + @getDir() + when Action.FALL if @direction != KVector() KikiPushable.initAction action return @@ -124,13 +130,13 @@ class Bot extends Pushable dltTime = action.getRelativeDelta() switch actionId - when ACTION_SHOOT + when Action.SHOOT if relTime == 0 KikiBullet.shootFromBot (@) - when ACTION_NOOP then return + when Action.NOOP then return - when ACTION_FORWARD + when Action.FORWARD @left_tire_rot += dir_sgn * dltTime @right_tire_rot += dir_sgn * dltTime @@ -138,24 +144,24 @@ class Bot extends Pushable return - when ACTION_JUMP + when Action.JUMP @current_position = @position + Math.cos(Math.PI/2 - Math.PI/2 * relTime) * @getUp() return - when ACTION_JUMP_FORWARD + when Action.JUMP_FORWARD @left_tire_rot += Math.cos(Math.PI/2 - Math.PI/2 * dltTime) @right_tire_rot += Math.cos(Math.PI/2 - Math.PI/2 * dltTime) @current_position = @position + (1.0 - Math.cos(Math.PI/2 * relTime)) * @getDir() + Math.cos(Math.PI/2 - Math.PI/2 * relTime) * @getUp() return - 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)) * @getDown() return - when ACTION_FALL + when Action.FALL if @direction != KVector() KikiPushable.performAction action @@ -163,14 +169,14 @@ class Bot extends Pushable @current_position = @position + relTime * @getDown() return - when ACTION_CLIMB_UP + when Action.CLIMB_UP @left_tire_rot += dir_sgn * dltTime/2 @right_tire_rot += dir_sgn * dltTime/2 @climb_orientation = KQuaternion.rotationAroundVector(dir_sgn * relTime * -90.0, KVector(1,0,0)) break - when ACTION_CLIMB_DOWN + when Action.CLIMB_DOWN @left_tire_rot += dir_sgn * dltTime @right_tire_rot += dir_sgn * dltTime @@ -185,18 +191,18 @@ class Bot extends Pushable @current_position = @position.plus @getDir().plus(@getDown()).plus(rotVec).mul 0.5 break - when ACTION_TURN_RIGHT, ACTION_TURN_LEFT + when Action.TURN_RIGHT, Action.TURN_LEFT 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 actionId == Action.TURN_LEFT @orientation *= KQuaternion.rotationAroundVector(90.0, KVector(0,1,0)) @rest_orientation = KQuaternion.rotationAroundVector(-90.0, KVector(0,1,0)) else @orientation *= KQuaternion.rotationAroundVector(-90.0, KVector(0,1,0)) @rest_orientation = KQuaternion.rotationAroundVector(90.0, KVector(0,1,0)) - if actionId == ACTION_TURN_LEFT + if actionId == Action.TURN_LEFT @left_tire_rot += -dltTime @right_tire_rot += dltTime @rotate_orientation = KQuaternion.rotationAroundVector(relTime * 90.0, KVector(0,1,0)) @@ -217,13 +223,13 @@ class Bot extends Pushable finishAction: (action) -> actionId = action.getId() - return if actionId == ACTION_NOOP or actionId == ACTION_SHOOT + return if actionId == Action.NOOP or actionId == Action.SHOOT - if actionId == ACTION_PUSH + if actionId == Action.PUSH KikiPushable.finishAction action return - if actionId == ACTION_TURN_LEFT or actionId == ACTION_TURN_RIGHT + if actionId == Action.TURN_LEFT or actionId == Action.TURN_RIGHT @rotate_action = null if move_action # bot currently performing a move action -> store rotation in @rest_orientation @@ -233,26 +239,26 @@ class Bot extends Pushable @orientation *= @rotate_orientation * @rest_orientation # update rotation matrix @rotate_orientation.reset() @rest_orientation.reset() - else if actionId < ACTION_END + else if actionId < Action.END @move_action = null @orientation *= @climb_orientation # update climb @orientation @climb_orientation.reset() - if @rotate_action and actionId != ACTION_JUMP_FORWARD # bot is currently performing a rotation -> + if @rotate_action and actionId != Action.JUMP_FORWARD # bot is currently performing a rotation -> # take over result of rotation to prevent sliding - if @rotate_action.getId() == ACTION_TURN_LEFT + if @rotate_action.getId() == Action.TURN_LEFT @orientation *= KQuaternion.rotationAroundVector(90.0, KVector(0,1,0)) * @rest_orientation @rest_orientation = KQuaternion.rotationAroundVector(-90.0, KVector(0,1,0)) else @orientation *= KQuaternion.rotationAroundVector(-90.0, KVector(0,1,0)) * @rest_orientation @rest_orientation = KQuaternion.rotationAroundVector(90.0, KVector(0,1,0)) - if actionId != ACTION_CLIMB_UP + if actionId != Action.CLIMB_UP world.objectMovedFromPos @, @position # update world @position @position = @current_position.round() - if actionId != ACTION_JUMP_FORWARD and @rotate_action == null # if not jumping forward + if actionId != Action.JUMP_FORWARD and @rotate_action == null # if not jumping forward @orientation *= @rest_orientation # update rotation @orientation @rest_orientation.reset() @@ -262,37 +268,37 @@ class Bot extends Pushable if @isDead() die() if not @died - if actionId != ACTION_PUSH and actionId != ACTION_FALL + if actionId != Action.PUSH and actionId != Action.FALL # dead player may only fall, nothing else return if spiked @move_action = null - @startTimedAction getActionWithId(ACTION_NOOP), 0 + @startTimedAction getActionWithId(Action.NOOP), 0 return - if actionId == ACTION_PUSH or @direction != KVector() + if actionId == Action.PUSH or @direction != KVector() KikiPushable.actionFinished (action) return return if @move_action # action was not a move action -> return # find next action depending on type of finished action and surrounding environment - if actionId == ACTION_JUMP_FORWARD + if actionId == Action.JUMP_FORWARD forwardPos = @position + @getDir() if world.isUnoccupiedPos forwardPos # forward will be empty if world.isUnoccupiedPos forwardPos.minus @getUp() # below forward will also be empty - @move_action = @getActionWithId ACTION_FALL_FORWARD + @move_action = @getActionWithId Action.FALL_FORWARD @move_action.takeRest (action) else - @move_action = @getActionWithId ACTION_FORWARD + @move_action = @getActionWithId Action.FORWARD playSoundAtPos(KikiSound.BOT_LAND, @getPos(), 0.25) else # forward will not be empty if world.isUnoccupiedPos position.minus @getUp() # below is empty - @move_action = @getActionWithId ACTION_CLIMB_UP + @move_action = @getActionWithId Action.CLIMB_UP playSoundAtPos KikiSound.BOT_LAND, @getPos(), 0.5 else if world.isUnoccupiedPos position.minus @getUp() # below will be empty if move # sticky if moving @@ -302,16 +308,16 @@ class Bot extends Pushable # below forward is solid KikiObject * occupant = world.getOccupantAtPos position.plus @getDir().minus @getUp() if occupant == null or not occupant.isSlippery() - @move_action = @getActionWithId (ACTION_FORWARD) + @move_action = @getActionWithId (Action.FORWARD) else KikiObject * occupant = world.getOccupantAtPos position.plus @getDir() if occupant == null or not occupant.isSlippery() - @move_action = @getActionWithId (ACTION_CLIMB_UP) + @move_action = @getActionWithId (Action.CLIMB_UP) if @move_action == null - @move_action = @getActionWithId ACTION_FALL + @move_action = @getActionWithId Action.FALL @move_action.takeRest action - else if actionId == ACTION_FALL or actionId == ACTION_FALL_FORWARD # landed + else if actionId == Action.FALL or actionId == Action.FALL_FORWARD # landed if @ == player playSound KikiSound.BOT_LAND else @@ -327,9 +333,9 @@ class Bot extends Pushable @moveBot() else dir_sgn = 1.0 - if actionId != ACTION_NOOP then jump_once = false + if actionId != Action.NOOP then jump_once = false # keep action chain flowing in order to detect environment changes - startTimedAction getActionWithId(ACTION_NOOP), 0 + startTimedAction getActionWithId(Action.NOOP), 0 moveBot: () -> @move_action = null @@ -341,26 +347,26 @@ class Bot extends Pushable world.isUnoccupiedPos position.plus @getUp() # and above empty if world.isUnoccupiedPos forwardPos.plus @getUp() and world.isUnoccupiedPos forwardPos # forward and above forward also empty - @move_action = @getActionWithId ACTION_JUMP_FORWARD + @move_action = @getActionWithId Action.JUMP_FORWARD else # no space to jump forward -> jump up - @move_action = @getActionWithId ACTION_JUMP + @move_action = @getActionWithId Action.JUMP else if world.isUnoccupiedPos forwardPos # forward is empty if world.isUnoccupiedPos forwardPos.plus @getDown() # below forward also empty - @move_action = @getActionWithId ACTION_CLIMB_DOWN + @move_action = @getActionWithId Action.CLIMB_DOWN else # forward down is solid - @move_action = @getActionWithId ACTION_FORWARD + @move_action = @getActionWithId Action.FORWARD else # forward is not empty - moveAction = @getActionWithId ACTION_FORWARD + moveAction = @getActionWithId Action.FORWARD if push and world.mayObjectPushToPos @, forwardPos, moveAction.getDuration() moveAction.reset() # player in push mode and pushing object is possible if world.isUnoccupiedPos forwardPos.plus @getDown() # below forward is empty - @move_action = @getActionWithId ACTION_CLIMB_DOWN + @move_action = @getActionWithId Action.CLIMB_DOWN else @move_action = moveAction else # just climb up - @move_action = @getActionWithId ACTION_CLIMB_UP + @move_action = @getActionWithId Action.CLIMB_UP # reset the jump once flag (either we jumped or it's not possible to jump at current @position) jump_once = false diff --git a/coffee/player.coffee b/coffee/player.coffee index 9e312dc..403b4ef 100644 --- a/coffee/player.coffee +++ b/coffee/player.coffee @@ -5,7 +5,8 @@ # 000 000 000 000 000 000 000 000 # 000 0000000 000 000 000 00000000 000 000 -Bot = require './bot' +Bot = require './bot' +Action = require './action' forward_key = "UP" backward_key = "DOWN" @@ -36,9 +37,9 @@ class Player extends Bot # @flags[KDL_KEYHANDLER_FLAG_HANDLES_RELEASE] = true - @addAction new KikiAction @, ACTION_LOOK_UP, "look up", 220 - @addAction new KikiAction @, ACTION_LOOK_DOWN, "look down", 220 - @addAction new KikiAction @, ACTION_LOOK_RESET, "look reset", 60 + @addAction new KikiAction @, Action.LOOK_UP, "look up", 220 + @addAction new KikiAction @, Action.LOOK_DOWN, "look down", 220 + @addAction new KikiAction @, Action.LOOK_RESET, "look reset", 60 @addEventWithName "keyset" @addEventWithName "keyset failed" @@ -94,13 +95,13 @@ class Player extends Bot relTime = (Controller.getTime() - move_action.getStart()) / move_action.getDuration() if relTime <= 1.0 switch move_action.getId() - when ACTION_FORWARD + when Action.FORWARD current_position = position + relTime * getDir() - when ACTION_FALL + when Action.FALL current_position = position - relTime * getUp() - 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() - 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() getProjection: () -> @@ -259,12 +260,12 @@ class Player extends Bot initAction: (action) -> actionId = action.getId() switch actionId - when ACTION_CLIMB_DOWN, ACTION_FORWARD - status.addMoves 1 - when ACTION_TURN_LEFT, ACTION_TURN_RIGHT + when Action.CLIMB_DOWN, Action.FORWARD + @status.addMoves 1 + when Action.TURN_LEFT, Action.TURN_RIGHT Controller.sound.playSound KikiSound.BOT_MOVE - when ACTION_JUMP, ACTION_JUMP_FORWARD - status.addMoves actionId == ACTION_JUMP and 1 or 2 + when Action.JUMP, Action.JUMP_FORWARD + @status.addMoves actionId == Action.JUMP and 1 or 2 Controller.sound.playSound KikiSound.BOT_JUMP KikiBot.initAction(action) @@ -273,15 +274,15 @@ class Player extends Bot relTime = action.getRelativeTime() switch action.getId() - when ACTION_NOOP then return + when Action.NOOP then return - when ACTION_LOOK_UP + when Action.LOOK_UP @look_angle = relTime * -90.0 - when ACTION_LOOK_DOWN + when Action.LOOK_DOWN @look_angle = relTime * 90.0 - when ACTION_LOOK_RESET + when Action.LOOK_RESET if @look_angle > 0 @look_angle = Math.min @look_angle, (1.0-relTime) * 90.0 else @@ -292,17 +293,17 @@ class Player extends Bot finishAction: (action) -> actionId = action.getId() - if actionId == ACTION_LOOK_RESET + if actionId == Action.LOOK_RESET @look_action = null @look_angle = 0.0 else if action == move_action # move finished, update direction dir_sgn = new_dir_sgn - if actionId != ACTION_LOOK_UP and actionId != ACTION_LOOK_DOWN + if actionId != Action.LOOK_UP and actionId != Action.LOOK_DOWN KikiBot.finishAction(action) - if actionId == ACTION_TURN_LEFT or actionId == ACTION_TURN_RIGHT + if actionId == Action.TURN_LEFT or actionId == Action.TURN_RIGHT if rotate rotate_action = getActionWithId rotate rotate_action.reset() @@ -313,7 +314,7 @@ class Player extends Bot KikiBot.die() Controller.displayText("game over") Controller.sound.playSound (KikiSound.BOT_DEATH) - world.setCameraMode (KikiWorld.CAMERA_FOLLOW) + world.setCameraMode (world.CAMERA_FOLLOW) reborn: () -> Controller.addKeyHandler (this) @@ -361,7 +362,7 @@ class Player extends Bot return keyHandled() if keyName == turn_left_key or keyName == turn_right_key - rotate = (keyName == turn_left_key) ? ACTION_TURN_LEFT : ACTION_TURN_RIGHT + rotate = (keyName == turn_left_key) and Action.TURN_LEFT or Action.TURN_RIGHT if (rotate_action == null and spiked == false) # player is not performing a rotation and unspiked rotate_action = getActionWithId rotate @@ -381,15 +382,15 @@ class Player extends Bot if keyName == shoot_key if not shoot shoot = true - Controller.timer_event.addAction (getActionWithId (ACTION_SHOOT)) + Controller.timer_event.addAction @getActionWithId Action.SHOOT return keyHandled() if keyName == look_up_key or keyName == look_down_key if not @look_action - @look_action = getActionWithId ((key.name == look_up_key) ? ACTION_LOOK_UP : ACTION_LOOK_DOWN) + @look_action = @getActionWithId (key.name == look_up_key) and Action.LOOK_UP or Action.LOOK_DOWN @look_action.reset() - Controller.timer_event.addAction (@look_action) + Controller.timer_event.addAction @look_action return keyHandled() if keyName == view_key @@ -405,7 +406,7 @@ class Player extends Bot true if keyName == shoot_key - Controller.timer_event.removeAction getActionWithId ACTION_SHOOT + Controller.timer_event.removeAction getActionWithId Action.SHOOT shoot = false return releaseHandled() @@ -418,8 +419,8 @@ class Player extends Bot if jump_once if move_action == null and world.isUnoccupiedPos position.plus getUp() jump_once = false - move_action = getActionWithId ACTION_JUMP - Controller.sound.playSound (KikiSound.BOT_JUMP) + move_action = getActionWithId Action.JUMP + Controller.sound.playSound KikiSound.BOT_JUMP Controller.timer_event.addAction (move_action) return releaseHandled() @@ -432,9 +433,9 @@ class Player extends Bot return releaseHandled() if keyName == look_down_key or keyName == look_up_key - if @look_action and @look_action.getId() != ACTION_LOOK_RESET + if @look_action and @look_action.getId() != Action.LOOK_RESET Controller.timer_event.removeAction @look_action - @look_action = getActionWithId ACTION_LOOK_RESET + @look_action = getActionWithId Action.LOOK_RESET Controller.timer_event.addAction @look_action return releaseHandled() @@ -444,14 +445,11 @@ class Player extends Bot return false display: () -> - if world.getCameraMode() != KikiWorld.CAMERA_INSIDE or world.getEditMode() - # glPushMatrix() - # current_position.glTranslate() + if world.getCameraMode() != world.CAMERA_INSIDE or world.getEditMode() render() - # glPopMatrix() getBodyColor: () -> - if world.getCameraMode() == KikiWorld.CAMERA_BEHIND + if world.getCameraMode() == world.CAMERA_BEHIND # static bodyColor bodyColor = colors[KikiPlayer_base_color] bodyColor.setAlpha(kMin(0.7, (projection.getPosition()-current_position).length()-0.4)) @@ -460,7 +458,7 @@ class Player extends Bot return colors[KikiPlayer_base_color] getTireColor: () -> - if world.getCameraMode() == KikiWorld.CAMERA_BEHIND + if world.getCameraMode() == world.CAMERA_BEHIND # static tireColor tireColor = colors[KikiPlayer_tire_color] tireColor.setAlpha(kMin(1.0, (projection.getPosition()-current_position).length()-0.4)) @@ -473,3 +471,4 @@ class Player extends Bot rotate = false finishAction(rotate_action) +module.exports = Player diff --git a/coffee/pushable.coffee b/coffee/pushable.coffee index 1acab05..5db284b 100644 --- a/coffee/pushable.coffee +++ b/coffee/pushable.coffee @@ -4,21 +4,23 @@ # 000 000 000 000 000 000 000 000 000 000 000 000 # 000 0000000 0000000 000 000 000 000 0000000 0000000 00000000 -Item = require './item' +Item = require './item' +Action = require './action' +Vector = require './lib/vector' class Pushable extends Item constructor: () -> super @pusher = null - @direction = new KVector() + @direction = new Vector() - @addAction new KikiAction @, ACTION_PUSH, "push" - @addAction new KikiAction @, ACTION_FALL, "fall", 40 + @addAction new Action @, Action.PUSH, "push" + @addAction new Action @, Action.FALL, "fall", 40 pushedByObjectInDirection: (object, dir, duration) -> - pushAction = @getActionWithId ACTION_PUSH + pushAction = @getActionWithId Action.PUSH @pusher = object @move_action = pushAction @@ -29,28 +31,28 @@ class Pushable extends Item initAction: (action) -> # switch action->getId() - # when ACTION_FALL + # when Action.FALL # Controller.world->objectWillMoveToPos @, @position + @direction, action->getDuration() performAction: (action) -> switch action.getId() - when ACTION_PUSH, ACTION_FALL + when Action.PUSH, Action.FALL @setCurrentPosition @position + action.getRelativeTime() * @direction finishAction: (action) -> switch action.getId() - when ACTION_PUSH, ACTION_FALL + when Action.PUSH, Action.FALL @move_action = null world.objectMovedFromPos @, @position @setPosition @current_position - actionFinished (action) -> + actionFinished: (action) -> actionId = action.getId() - if actionId == ACTION_PUSH or actionId == ACTION_FALL + if actionId == Action.PUSH or actionId == Action.FALL gravityDir = @direction - if actionId == ACTION_PUSH + if actionId == Action.PUSH if @pusher instanceof KikiBot gravityDir = pusher.getDown() else if pusher instanceof KikiBomb @@ -67,7 +69,7 @@ class Pushable extends Item if world.isUnoccupiedPos @position + gravityDir @direction = gravityDir - @move_action = @getActionWithId ACTION_FALL + @move_action = @getActionWithId Action.FALL # Controller.timer_event->addAction (move_action) else @direction.reset() diff --git a/coffee/world.coffee b/coffee/world.coffee index 1b13b03..9b31972 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -12,6 +12,7 @@ log = require "/Users/kodi/s/ko/js/tools/log" Pos = require './lib/pos' KikiCell = require './cell' KikiLight = require './light' +Player = require './player' KQuaternion = require './lib/quaternion' KVector = require './lib/vector' Pos = require './lib/pos' @@ -246,7 +247,7 @@ class KikiWorld # ............................................................ player - # player = Controller.player + player = new Player # # player_dict = @dict["player"] # @@ -282,8 +283,8 @@ class KikiWorld restart: (self) -> # restores the player status and restarts the current level - Controller.player.getStatus().setMoves (0) - Controller.player.reborn() + @player.status.setMoves 0 + @player.reborn() @create() finish: (self) -> @@ -312,7 +313,7 @@ class KikiWorld # action callback. used to exit current world if name.find ("exit") == 0 @finish() - Controller.player.getStatus().setMoves (0) + @player.status.setMoves 0 if "world" in @dict["exits"][parseInt name.slice 5] w = @dict["exits"][parseInt name.slice 5]["world"] if w instanceof KikiWorld @@ -710,6 +711,13 @@ class KikiWorld @sun.position.copy @camera.position @renderer.render @scene, @camera + setSpeed: (s) -> @speed = s + getSpeed: -> @speed + mapMsTime: (unmapped) -> parseInt 10.0 * unmapped/speed + unmapMsTime: (mapped) -> parseInt mapped * speed/10.0 + getRelativeTime: -> @frame_time % (10000/@speed)/(10000.0/@speed) + getRelativeDelta: -> (@frame_time - @last_time)/(10000.0/@speed) + resized: (w,h) -> # log "world.resized w:#{w} h:#{h}" @aspect = w/h