This commit is contained in:
monsterkodi 2016-08-23 22:30:49 +02:00
parent 1d8f52dcfe
commit f97ac83d63
9 changed files with 36 additions and 68 deletions

View File

@ -1 +1,4 @@
![kiki](img/kiki.png)
![kiki](img/shot06.png)
![kiki](img/shot05.png)

View File

@ -4,7 +4,6 @@
# 000 000 000 000 000 000 000 000 0000
# 000 000 0000000 000 000 0000000 000 000
log = require '/Users/kodi/s/ko/js/tools/log'
_ = require 'lodash'
class Action
@ -34,18 +33,19 @@ class Action
@ONCE = 0
@CONTINUOUS = 1
@REPEAT = 2
@TIMED = 3
constructor: (o, i, n, d, m) ->
if _.isPlainObject o
i = o.id ? -1
n = o.name
d = o.duration ? 0
m = o.mode ? Action.ONCE
m = o.mode ? (d and Action.TIMED or Action.ONCE)
o = o.func
else
i ?= -1
m ?= Action.ONCE
d ?= 0
m ?= (d and Action.TIMED or Action.ONCE)
# log "Action.constructor #{i} #{n} #{d} #{m}"
@object = o
@name = n
@ -62,21 +62,18 @@ class Action
if @object? then @object.removeAction @
@deleted = true
perform: () ->
# log "Action.perform #{@name} action? #{@object.performAction?} #{@object.name}" if @name == 'push'
perform: ->
log "Action.perform #{@name} action? #{@object.performAction?} #{@object.name}" if not @name in ['noop', 'rotation']
if @object.performAction?
@object.performAction @
else if _.isFunction @object
@object()
init: () -> @object.initAction? @
finish: () -> @object.finishAction? @
finished: () ->
# log "Action.finished #{@name} #{@object?.actionFinished?}"
if _.isFunction @object
@object @
else
@object.actionFinished @
init: -> @object.initAction? @
finish: -> @object.finishAction? @
finished: ->
# log "Action.finished #{@name} #{@object?.actionFinished?}"
@object?.actionFinished? @
return if @deleted
@reset()
# if @current >= @getDuration() # if keepRest wasn't called -> reset start and current values
@ -84,7 +81,7 @@ class Action
# else
# log 'keeping rest', @current
reset: () ->
reset: ->
# log "action.reset #{@name}"
@start = 0 # world time
@rest = 0
@ -93,7 +90,7 @@ class Action
#@event = null
takeOver: (action) ->
log "takeOver #{action.rest} from #{action.name} this: #{@name}"
# log "takeOver #{action.rest} from #{action.name} this: #{@name}"
@current = action.current
@start = action.start
@last = action.last
@ -110,16 +107,18 @@ class Action
performWithEvent: (event) ->
eventTime = event.getTime()
# log "action.performWithEvent #{@name} eventTime #{eventTime} start #{@start}" if @name != 'noop'
# log "action.performWithEvent #{@name} #{@id} eventTime #{eventTime} start #{@start}" if @name.startsWith 'exit'
if @start == 0
@start = eventTime
@current = 0
@rest = 0
@last = 0
event.removeAction @ if @duration == 0 and @mode == Action.ONCE
# event.removeAction @ if @duration == 0 and @mode == Action.ONCE
event.removeAction @ if @mode == Action.ONCE
@perform()
@last = @current
@finished() if @duration == 0 and @mode == Action.ONCE
# @finished() if @duration == 0 and @mode == Action.ONCE
@finished() if @mode == Action.ONCE
else
currentDiff = eventTime - @start
msDur = @getDuration()
@ -138,7 +137,7 @@ class Action
@last = 0
@rest = 0
return
event.removeAction @ if @mode == Action.ONCE
event.removeAction @ if @mode in [Action.ONCE, Action.TIMED]
@finish()

View File

@ -393,7 +393,7 @@ class Bot extends Pushable
# log 'bot.actionFinished below empty', world.isUnoccupiedPos(@position.plus @getDown()), @position.plus @getDown()
if @move # sticky if moving
if world.isUnoccupiedPos @position.plus @getDir() # forward will be empty
log 'bot.actionFinished forward empty'
# log 'bot.actionFinished forward empty'
if world.isOccupiedPos @position.plus @getDir().minus @getUp() # below forward is solid
occupant = world.getOccupantAtPos @position.plus @getDir().minus @getUp()
if not occupant? or not occupant?.isSlippery()

View File

@ -6,7 +6,6 @@
{
last
} = require '/Users/kodi/s/ko/js/tools/tools'
log = require '/Users/kodi/s/ko/js/tools/log'
Action = require './action'
_ = require 'lodash'
@ -17,7 +16,6 @@ class Event
@name = name
@time = 0
@actions = []
@save_actions = []
@finished_actions = []
getTime: -> @time
@ -54,20 +52,18 @@ class Event
action.event = null
action.reset()
_.pull @actions, action
_.pull @save_actions, action
_.pull @finished_actions, action
triggerActions: () ->
return if not @actions.length
@time = world.getTime()
# log "event.triggerActions event name: #{@name} num actions: #{@actions.length}"
@save_actions = _.clone @actions
while @save_actions.length
action = last @save_actions
# log "event.triggerActions action #{action.name}" if action.name != 'noop'
# log "event.triggerActions event name: #{@name} num actions: #{@actions.length}" if @name != 'timer'
save_actions = _.clone @actions
while save_actions.length
action = last save_actions
# log "event.triggerActions action: #{action.name}" if @name != 'timer' and action.name != 'noop'
action.performWithEvent @
if @save_actions.length and action == last @save_actions
@save_actions.pop()
save_actions.pop()
addFinishedAction: (action) ->
# log "Event.addFinishedAction #{action.name} #{@finished_actions.length}"

View File

@ -54,6 +54,8 @@ class Gate extends Switch
newCellMate: (object) ->
if object.name == 'player' and @active
world.playSound 'GATE_WARP'
log 'gate trigger enter event', @events[@ENTER_EVENT].actions.length
@events[@ENTER_EVENT].triggerActions()
@active = false
module.exports = Gate

View File

@ -10,7 +10,6 @@ class Levels
@dict = {}
@list = [
# "test",
"electro",
# --- introduction
"steps",
"start",

View File

@ -21,7 +21,7 @@ module.exports =
to turn, press "$key(turn left)" or "$key(turn right)"
"""
player:
position: [0,0,4]
position: [2,1,4]
orientation: rotx270
exits: [
name: "exit"

View File

@ -59,8 +59,6 @@ module.exports =
tron:
plate:
color: rgb 0.05, 0.05, 0.2
# raster:
# color: rgb 0, 0, 0.3
bulb:
color: rgb 0, 0, 1
bomb:
@ -99,8 +97,6 @@ module.exports =
neutron:
plate:
color: rgb 0.5, 0.5, 0.5
# raster:
# color: rgb 0.13, 0.13, 0.13
bulb:
color: rgb 0, 0, 0
bomb:
@ -140,8 +136,6 @@ module.exports =
test:
plate:
color: rgb 0.08, 0.08, 0.08
# raster:
# color: rgb 1, 1, 1
bulb:
color: rgb 0, 0, 0
bomb:
@ -181,8 +175,6 @@ module.exports =
candy:
plate:
color: rgb 0.8, 0, 0.9
# raster:
# color: rgb 0.35, 0, 0.35
bulb:
color: rgb 0, 0, 0
text:
@ -301,8 +293,6 @@ module.exports =
blue:
plate:
color: rgb 0.1, 0.1, 0.6
# raster:
# color: rgb 0, 0, 0.2
bulb:
color: rgb 0.1, 0.1, 0.1
stone:
@ -343,8 +333,6 @@ module.exports =
yellow:
plate:
color: rgb 0.9, 0.9, 0
# raster:
# color: rgb 0.34, 0.34, 0
bulb:
color: rgb 0, 0, 0
bomb:
@ -384,8 +372,6 @@ module.exports =
green:
plate:
color: rgb 0.1, 0.6, 0.1
# raster:
# color: rgb 0, 0.2, 0
bulb:
color: rgb 0, 0, 0
stone:
@ -424,8 +410,6 @@ module.exports =
metal:
plate:
color: rgb 0.7,0.7,0.7
# raster:
# color: rgb 0.2, 0.2, 0.2
bulb:
color: rgb 1, 1, 1
stone:
@ -463,8 +447,6 @@ module.exports =
# 0000000 000 000 000 000 0000000 000
crazy:
# plate:
# color: rgb 0, 0.51, 0.82
raster:
color: rgb 0.84, 0.22, 0.20
bulb:
@ -507,8 +489,6 @@ module.exports =
zen:
plate:
color: rgb 0.36, 0.45, 0.30
# raster:
# color: rgb 0.75, 0.95, 0.64
bulb:
color: rgb 0, 0, 0
stone:

View File

@ -216,7 +216,9 @@ class World extends Actor
for entry in @dict.exits
exit_gate = new Gate entry["active"]
exit_gate.name = entry["name"] ? "exit #{exit_id}"
Action.id ?= 0
exitAction = new Action
id: Action.id
func: @exitLevel
name: "exit #{exit_id}"
mode: Action.ONCE
@ -250,16 +252,10 @@ class World extends Actor
@addObjectAtPos @player, new Pos @dict.player.coordinates
@getProjection().setPosition new Vector 0,0,0
# ............................................................ init
# @init() # tell the world that we are finished
restart: () -> @create @dict
finish: () -> # log 'world.levelFinished'
# saves the current level status in highscore file
# highscore.levelFinished world.level_name, Controller.player.getStatus().getMoves()
finish: () -> # TODO: save progress
# 0000000 0000000 000 000 00000000 00 00 00000000
# 000 000 000 000 000 000 000 000
@ -321,14 +317,7 @@ class World extends Actor
# 000 000 0000000 000 000 0000000 000 000
exitLevel: (action) =>
log "world.exitLevel", action
@finish()
# exitIndex = parseInt action.name?.slice 5
# log "world.exitLevel exitIndex:#{exitIndex}"
# if @dict.exits[exitIndex]?.world?
# w = @dict.exits[exitIndex].world
# w() if _.isFunction w
# else
log "world.level_index #{world.level_index} nextLevel #{World.levels.list[world.level_index+1]}"
world.create World.levels.list[world.level_index+1]