diff --git a/coffee/bullet.coffee b/coffee/bullet.coffee index 9b7a760..142ded0 100644 --- a/coffee/bullet.coffee +++ b/coffee/bullet.coffee @@ -56,8 +56,11 @@ class Bullet extends Item @mesh.scale.set @size, @size, @size hitObjectAtPos: (pos) -> - if world.isInvalidPos(pos) or world.isOccupiedPos pos - hitObject = world.getRealOccupantAtPos pos + + world.switchAtPos(pos)?.bulletImpact() + + if world.isInvalidPos(pos) or world.isOccupiedPos pos + hitObject = world.getRealOccupantAtPos pos if hitObject != @src_object if hitObject? hitObject.bulletImpact() diff --git a/coffee/cell.coffee b/coffee/cell.coffee index 08ac773..0d15543 100644 --- a/coffee/cell.coffee +++ b/coffee/cell.coffee @@ -5,7 +5,6 @@ # 000 000 000 000 # 0000000 00000000 0000000 0000000 -log = require '/Users/kodi/s/ko/js/tools/log' TmpObject = require './tmpobject' _ = require 'lodash' diff --git a/coffee/levels.coffee b/coffee/levels.coffee index e1b4a95..b46e107 100644 --- a/coffee/levels.coffee +++ b/coffee/levels.coffee @@ -10,7 +10,6 @@ class Levels @dict = {} @list = [ # "test", - "invisimaze", # --- introduction "steps", # ok "start", # ok @@ -24,9 +23,9 @@ class Levels "gold", "escape", "gears", - "gamma", # scheme change doesn't work + "gamma", "cube", - "switch", # exit doesnt open, other scheme + "switch" # # "borg", "mini", "bombs", diff --git a/coffee/levels/cheese.coffee b/coffee/levels/cheese.coffee index 32dad3d..ed6c222 100644 --- a/coffee/levels/cheese.coffee +++ b/coffee/levels/cheese.coffee @@ -61,19 +61,20 @@ module.exports = world.switch_counter = 0 switched = (swtch) -> - world.switch_counter += swtch.active and 1 or -1 + world.switch_counter += (swtch.active and 1 or -1) + log "world.switch_counter #{swtch} #{world.switch_counter}" exit = world.getObjectWithName "exit" exit.setActive world.switch_counter == 4 Switch = require '../switch' switch1 = new Switch - switch1.getEventWithName("switched").addAction world.continuous (s=switch1) -> switched s + switch1.getEventWithName("switched").addAction world.continuous -> switched switch1 switch2 = new Switch - switch2.getEventWithName("switched").addAction world.continuous (s=switch2) -> switched s + switch2.getEventWithName("switched").addAction world.continuous -> switched switch2 switch3 = new Switch - switch3.getEventWithName("switched").addAction world.continuous (s=switch3) -> switched s + switch3.getEventWithName("switched").addAction world.continuous -> switched switch3 switch4 = new Switch - switch4.getEventWithName("switched").addAction world.continuous (s=switch4) -> switched s + switch4.getEventWithName("switched").addAction world.continuous -> switched switch4 world.addObjectAtPos switch1, 1, 0 ,2 world.addObjectAtPos switch2, 7, 1, 0 diff --git a/coffee/levels/gamma.coffee b/coffee/levels/gamma.coffee index 24f3163..30070d1 100644 --- a/coffee/levels/gamma.coffee +++ b/coffee/levels/gamma.coffee @@ -5,8 +5,7 @@ # 000 000 000 000 000 0 000 000 0 000 000 000 # 0000000 000 000 000 000 000 000 000 000 -# schemes=[test_scheme, tron_scheme,candy_scheme, default_scheme, - # green_scheme, yellow_scheme, blue_scheme, red_scheme, metal_scheme, bronze_scheme] +schemes = ['tron', 'candy', 'default', 'green', 'yellow', 'blue', 'red', 'metal', 'bronze', 'crazy'] module.exports = name: "gamma" @@ -17,7 +16,7 @@ module.exports = $scale(1.5)mission: activate the exit! - shoot at the 3 switches to activate the exit + shoot at the 4 switches to activate the exit """ player: coordinates: [5,5,4] @@ -25,57 +24,47 @@ module.exports = exits: [ name: "exit" active: 0 - coordinates: [2,7,4] #absolute coord + coordinates: [2,7,4] ] create: -> s = world.size - world.switch_countera = 0 + world.scheme_counter = 0 world.switch_counter = 0 {Switch} = require '../items' - aswitched = () -> - # applyColorScheme(schemes[world.switch_countera]) - # if world.switch_countera==schemes.length-1 - # world.switch_countera=0 - # else - # world.switch_countera+=1 + schemesw = -> + world.scheme_counter = (world.scheme_counter+1) % schemes.length + world.applyScheme schemes[world.scheme_counter] switched = (swtch) -> world.switch_counter += swtch.active and 1 or -1 exit = world.getObjectWithName "exit" exit.setActive world.switch_counter == 4 - aswitch = new Switch() - bswitch = new Switch() - cswitch = new Switch() - dswitch = new Switch() - eswitch = new Switch() + a = new Switch + b = new Switch + c = new Switch + d = new Switch + e = new Switch - aswitch.getEventWithName("switched").addAction(world.continuous(aswitched)) - bswitch.getEventWithName("switched").addAction(world.continuous((s=bswitch) -> switched(s))) - cswitch.getEventWithName("switched").addAction(world.continuous((s=cswitch) -> switched(s))) - dswitch.getEventWithName("switched").addAction(world.continuous((s=dswitch) -> switched(s))) - eswitch.getEventWithName("switched").addAction(world.continuous((s=eswitch) -> switched(s))) + a.getEventWithName("switched").addAction world.continuous schemesw + b.getEventWithName("switched").addAction world.continuous -> switched(b) + c.getEventWithName("switched").addAction world.continuous -> switched(c) + d.getEventWithName("switched").addAction world.continuous -> switched(d) + e.getEventWithName("switched").addAction world.continuous -> switched(e) - world.addObjectAtPos aswitch, s.x-1,0,0 - world.addObjectAtPos bswitch, 0,0,0 - - world.addObjectAtPos 'Mutant', s.x/2,0,0 - world.addObjectLine 'Wall', 0,0,1, s.x,0,1 - world.addObjectLine 'Wall', 0,1,0, s.x,1,0 + world.addObjectAtPos a, s.x-1,0,0 + world.addObjectAtPos b, 0,0,0 + world.addObjectAtPos c , s.x-3,4,4 + world.addObjectAtPos d , 4,4,s.z-3 + world.addObjectAtPos e , 4,s.y-3,6 + + world.addObjectAtPos 'Mutant', s.x/2,0,0 + world.addObjectLine 'Wall', 0,0,1, s.x,0,1 + world.addObjectLine 'Wall', 0,1,0, s.x,1,0 + world.addObjectLine 'Wall', 0,2,2, s.x-3,2,2 + world.addObjectLine 'Wall', 2,2,2, 2,2,s.z-3 + world.addObjectLine 'Wall', 2,2,4, 2,s.y-3,4 + world.addObjectLine 'Wall', 2,4,4, s.x-4,4,4 + world.addObjectLine 'Wall', 4,4,4, 4,4,s.z-4 + world.addObjectLine 'Wall', 4,4,6, 4,s.y-4,6 - world.addObjectLine 'Wall', 0,2,2, s.x-3,2,2 - world.addObjectAtPos 'Switch', s.x-3,2,2 - world.addObjectLine 'Wall', 2,2,2, 2,2,s.z-3 - world.addObjectAtPos 'Switch', 2,2,s.z-3 - world.addObjectLine 'Wall', 2,2,4, 2,s.y-3,4 - #exit - world.addObjectAtPos 'Switch' , 2,s.y-3,4 - - world.addObjectLine 'Wall', 2,4,4, s.x-4,4,4 - world.addObjectAtPos cswitch , s.x-3,4,4 - - world.addObjectLine 'Wall', 4,4,4, 4,4,s.z-4 - world.addObjectAtPos dswitch , 4,4,s.z-3 - - world.addObjectLine 'Wall', 4,4,6, 4,s.y-4,6 - world.addObjectAtPos eswitch , 4,s.y-3,6 \ No newline at end of file diff --git a/coffee/levels/switch.coffee b/coffee/levels/switch.coffee index 8b395a3..2fed333 100644 --- a/coffee/levels/switch.coffee +++ b/coffee/levels/switch.coffee @@ -14,17 +14,7 @@ module.exports = activate the exit! to activate the exit, - activate the 4 switches - - to activate the switches, - shoot them - - to be able to shoot the switches, - move the center stone - to move the center stone, - use the bomb. - - the bomb will detonate if you shoot it + activate the 4 switches. """ player: coordinates: [3,4,3] @@ -38,15 +28,13 @@ module.exports = s = world.size h = 0 - # bomb and stones world.addObjectAtPos 'Stone', s.x/2, s.y/2, s.z/2 world.addObjectAtPos 'Stone', s.x/2, s.y-2, s.z/2 - # world.addObjectAtPos 'Bomb', s.x/2, 1, s.z/2 + world.addObjectAtPos 'Bomb', s.x/2, 1, s.z/2 # stone frames for switches - world.addObjectAtPos 'Wall', world.decenter 0, h-1, s.z/2 world.addObjectAtPos 'Wall', world.decenter 0, h+1, s.z/2 world.addObjectAtPos 'Wall', world.decenter 1, h, s.z/2 @@ -77,17 +65,17 @@ module.exports = exit.setActive world.switch_counter == 4 Switch = require '../switch' - switch1 = new Switch() - switch1.getEventWithName("switched").addAction(world.continuous((s=switch1) -> switched(s))) - switch2 = new Switch() - switch2.getEventWithName("switched").addAction(world.continuous((s=switch2) -> switched(s))) - switch3 = new Switch() - switch3.getEventWithName("switched").addAction(world.continuous((s=switch3) -> switched(s))) - switch4 = new Switch() - switch4.getEventWithName("switched").addAction(world.continuous((s=switch4) -> switched(s))) + s1 = new Switch() + s1.getEventWithName("switched").addAction world.continuous -> switched s1 + s2 = new Switch() + s2.getEventWithName("switched").addAction world.continuous -> switched s2 + s3 = new Switch() + s3.getEventWithName("switched").addAction world.continuous -> switched s3 + s4 = new Switch() + s4.getEventWithName("switched").addAction world.continuous -> switched s4 - world.addObjectAtPos switch1, world.decenter -s.x/2+1, 0, 0 - world.addObjectAtPos switch2, world.decenter s.x/2, 0, 0 - world.addObjectAtPos switch3, world.decenter 0, 0, -s.z/2+1 - world.addObjectAtPos switch4, world.decenter 0, 0, s.z/2 + world.addObjectAtPos s1, world.decenter -s.x/2+1, 0, 0 + world.addObjectAtPos s2, world.decenter s.x/2, 0, 0 + world.addObjectAtPos s3, world.decenter 0, 0, -s.z/2+1 + world.addObjectAtPos s4, world.decenter 0, 0, s.z/2 \ No newline at end of file diff --git a/coffee/scheme.coffee b/coffee/scheme.coffee index 002c6f4..cb23ac0 100644 --- a/coffee/scheme.coffee +++ b/coffee/scheme.coffee @@ -395,9 +395,9 @@ module.exports = color: rgb 1, 1, 1 opacity: 0.6 switch: - color: rgb 0.9, 1, 0.9 + color: rgb 1, 1, 1 gate: - color: rgb 1, 1, 1, 0.8 + color: rgb 1, 1, 1 player: color: rgb 0.6, 0.6, 0.6 tire: diff --git a/coffee/switch.coffee b/coffee/switch.coffee index 545d144..da87485 100644 --- a/coffee/switch.coffee +++ b/coffee/switch.coffee @@ -14,7 +14,7 @@ Material = require './material' class Switch extends Item - isSpaceEgoistic: -> true + isSpaceEgoistic: -> false # true? constructor: (active=false) -> diff --git a/coffee/world.coffee b/coffee/world.coffee index dc8a904..c49e291 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -38,6 +38,7 @@ now = require 'performance-now' Wire, Gear, Stone, +Switch, MotorGear, MotorCylinder, Face} = require './items' @@ -456,7 +457,7 @@ class World extends Actor occupant.object else occupant - + switchAtPos: (pos) -> @getObjectOfTypeAtPos Switch, pos setObjectAtPos: (object, pos) -> pos = new Pos pos if @isInvalidPos pos diff --git a/levels.txt b/levels.txt index 3c829b9..55fb567 100644 --- a/levels.txt +++ b/levels.txt @@ -39,10 +39,9 @@ 39 size: 11 11 11 'grasp' scheme: 'blue' 40 size: 13 15 13 'fallen' scheme: 'blue' 41 size: 11 12 7 'cheese' scheme: 'yellow' -42 size: 9 5 5 'invisimaze' scheme: 'yellow' 43 size: 5 25 5 'spiral' scheme: 'zen' 44 size: 9 9 9 'hidden' scheme: 'metal' -45 size: 5 7 5 'church' scheme: 'yellow' +45 size: 5 7 5 'church' scheme: 'bronze' 46 size: 11 11 11 'mesh' scheme: 'default' 47 size: 7 9 7 'columns' scheme: 'green' 48 size: 5 5 9 'machine' scheme: 'tron'