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

View File

@ -393,7 +393,7 @@ class Bot extends Pushable
# log 'bot.actionFinished below empty', world.isUnoccupiedPos(@position.plus @getDown()), @position.plus @getDown() # log 'bot.actionFinished 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
log 'bot.actionFinished forward empty' # log 'bot.actionFinished forward 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
occupant = world.getOccupantAtPos @position.plus @getDir().minus @getUp() occupant = world.getOccupantAtPos @position.plus @getDir().minus @getUp()
if not occupant? or not occupant?.isSlippery() if not occupant? or not occupant?.isSlippery()

View File

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

View File

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

View File

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

View File

@ -21,7 +21,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,4] position: [2,1,4]
orientation: rotx270 orientation: rotx270
exits: [ exits: [
name: "exit" name: "exit"

View File

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

View File

@ -216,7 +216,9 @@ class World extends Actor
for entry in @dict.exits for entry in @dict.exits
exit_gate = new Gate entry["active"] exit_gate = new Gate entry["active"]
exit_gate.name = entry["name"] ? "exit #{exit_id}" exit_gate.name = entry["name"] ? "exit #{exit_id}"
Action.id ?= 0
exitAction = new Action exitAction = new Action
id: Action.id
func: @exitLevel func: @exitLevel
name: "exit #{exit_id}" name: "exit #{exit_id}"
mode: Action.ONCE mode: Action.ONCE
@ -251,15 +253,9 @@ class World extends Actor
@getProjection().setPosition new Vector 0,0,0 @getProjection().setPosition new Vector 0,0,0
# ............................................................ init
# @init() # tell the world that we are finished
restart: () -> @create @dict restart: () -> @create @dict
finish: () -> # log 'world.levelFinished' finish: () -> # TODO: save progress
# saves the current level status in highscore file
# highscore.levelFinished world.level_name, Controller.player.getStatus().getMoves()
# 0000000 0000000 000 000 00000000 00 00 00000000 # 0000000 0000000 000 000 00000000 00 00 00000000
# 000 000 000 000 000 000 000 000 # 000 000 000 000 000 000 000 000
@ -321,14 +317,7 @@ class World extends Actor
# 000 000 0000000 000 000 0000000 000 000 # 000 000 0000000 000 000 0000000 000 000
exitLevel: (action) => exitLevel: (action) =>
log "world.exitLevel", action
@finish() @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]}" log "world.level_index #{world.level_index} nextLevel #{World.levels.list[world.level_index+1]}"
world.create World.levels.list[world.level_index+1] world.create World.levels.list[world.level_index+1]