diff --git a/coffee/face.coffee b/coffee/face.coffee new file mode 100644 index 0000000..9b49b08 --- /dev/null +++ b/coffee/face.coffee @@ -0,0 +1,29 @@ +# 00000000 0000000 0000000 00000000 +# 000 000 000 000 000 +# 000000 000000000 000 0000000 +# 000 000 000 000 000 +# 000 000 000 0000000 00000000 + +Quaternion = require './lib/quaternion' +Vector = require './lib/vector' + +class Face + + @orientationForFace: (face) -> + switch face % 6 + when 0 then return Quaternion.rot_90_Y + when 1 then return Quaternion.rot_0 + when 2 then return Quaternion.rot_270_X + when 3 then return Quaternion.rot_270_Y + when 4 then return Quaternion.rot_90_X + when 5 then return Quaternion.rot_180_X + + @normalVectorForFace: (face) -> + o = (face < 3) and -1 or 1 + switch face % 3 + when 0 then return new Vector o, 0, 0 + when 1 then return new Vector 0, o, 0 + when 2 then return new Vector 0, 0, o + new Vector + +module.exports = Face diff --git a/coffee/gear.coffee b/coffee/gear.coffee new file mode 100644 index 0000000..64ab4c9 --- /dev/null +++ b/coffee/gear.coffee @@ -0,0 +1,76 @@ +# 0000000 00000000 0000000 00000000 +# 000 000 000 000 000 000 +# 000 0000 0000000 000000000 0000000 +# 000 000 000 000 000 000 000 +# 0000000 00000000 000 000 000 000 + +Valve = require './valve' + +class Gear extends Valve + + constructor: (face) -> super face + + getNeighborDirections: (face) -> + neighbors = [ + [0,1,0], [0,-1,0], [0,0,1], [0,0,-1] + [1,0,0], [-1,0,0], [0,0,1], [0,0,-1] + [1,0,0], [-1,0,0], [0,1,0], [0,-1,0] + ] + neighbors[face % 3] + + getNeighborGears: -> + neighbor_dirs = @getNeighborDirections() + pos = @getPos() + gears = [] + for i in [0...4] + neighbor = world.getOccupantAtPos pos.plus neighbor_dirs[i] + if neighbor? and neighbor instanceof Gear + if neighbor.face == face + gears.push neighbor + gears + + initAction: (action) -> + super action + + if action.id == Action.PUSH + @setActive false + + actionFinished: (action) -> + super action + + if action.id == Action.PUSH or actionId == Action.FALL + if not @move_action? + @updateActive() + + updateActive: -> + @setActive false + for gear in @getNeighborGears() + if gear.active + @setActive true + return + + setActive: (active) -> + if @active != active + @active = active + + world.playSound @active and 'GEAR_ON' or 'GEAR_OFF' + + for gear in @getNeighborGears() + if @active + gear.setActive true + else + gear.updateActive() + + render: -> + # if (@active) + # glRotatef (clockwise ? angle : -angle, 0.0, 0.0, 1.0); +# + # KikiValve::colors[0].glColor(); + # render_valve; +# + # glTranslatef (0.0, 0.0, 0.4); +# + # colors[0].glColor(); + # render_gear; + +module.exports = Gear diff --git a/coffee/generator.coffee b/coffee/generator.coffee new file mode 100644 index 0000000..456e13c --- /dev/null +++ b/coffee/generator.coffee @@ -0,0 +1,41 @@ +# 0000000 00000000 000 000 00000000 00000000 0000000 000000000 0000000 00000000 +# 000 000 0000 000 000 000 000 000 000 000 000 000 000 000 +# 000 0000 0000000 000 0 000 0000000 0000000 000000000 000 000 000 0000000 +# 000 000 000 000 0000 000 000 000 000 000 000 000 000 000 000 +# 0000000 00000000 000 000 00000000 000 000 000 000 000 0000000 000 000 + +Gear = require './gear' +Wire = require './wire' + +class Generator extends Gear + + constructor: (face) -> + super face + + activateWires: -> + wires = world.getObjectsOfTypeAtPos Wire, @getPos() + + for wire in wires + wire.setActive active + + setActive: (active) -> + if @active != active + super active + @activateWires() + world.playSound @active and 'GENERATOR_ON' or 'GENERATOR_OFF' + + render: -> + # if (active) + # glRotatef (clockwise ? angle : -angle, 0.0, 0.0, 1.0); +# + # colors[0].glColor(); +# + # render_generator; +# + # KikiGear::colors[0].glColor(); +# + # glTranslatef (0.0, 0.0, 0.4); +# + # render_gear; + +module.exports = Generator diff --git a/coffee/levels.coffee b/coffee/levels.coffee index eaab60e..8c15a3d 100644 --- a/coffee/levels.coffee +++ b/coffee/levels.coffee @@ -23,7 +23,7 @@ class Levels # "cube", # "switch", # "borg", - "mini", + # "mini", # "blocks", # "bombs", # "sandbox", @@ -33,7 +33,11 @@ class Levels # medium # "towers", "edge", "random", "plate", "nice", "entropy", # owen hay's levels (TODO: sort in) - "grasp", "fallen", "cheese", "invisimaze", "spiral", + # "grasp", + # "fallen", + # "cheese", + # "invisimaze", + "spiral", # difficult "slick", "bridge", "flower", "stones", "walls", "grid", "rings", diff --git a/coffee/levels/cheese.coffee b/coffee/levels/cheese.coffee index 743abd7..1480aec 100644 --- a/coffee/levels/cheese.coffee +++ b/coffee/levels/cheese.coffee @@ -1,23 +1,22 @@ -# level design by Owen Hay + +# 0000000 000 000 00000000 00000000 0000000 00000000 +# 000 000 000 000 000 000 000 +# 000 000000000 0000000 0000000 0000000 0000000 +# 000 000 000 000 000 000 000 +# 0000000 000 000 00000000 00000000 0000000 00000000 module.exports = name: "cheese" + design: "Owen Hay" scheme: "yellow_scheme" size: [11,12,7] intro: "cheese" help: """ $scale(1.5)mission: - activate the exit! + activate the exit. - 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 + to activate the exit, + activate all switches. """ player: coordinates: [3, 4,3] @@ -30,53 +29,52 @@ module.exports = create: -> s = world.size h = 0 - # bomb and stones for i in [1, 2] - world.addObjectAtPos 'KikiWall', 1, i, 1 - world.addObjectAtPos 'KikiWall', 1, i, 3 - world.addObjectAtPos 'KikiWall', 2, i, 1 - world.addObjectAtPos 'KikiWall', 2, i, 2 - world.addObjectAtPos 'KikiWall', 2, i, 5 - world.addObjectAtPos 'KikiWall', 3, i, 1 - world.addObjectAtPos 'KikiWall', 3, i, 2 - world.addObjectAtPos 'KikiWall', 3, i, 4 - world.addObjectAtPos 'KikiWall', 3, i, 5 - world.addObjectAtPos 'KikiWall', 5, i, 0 - world.addObjectAtPos 'KikiWall', 5, i, 2 - world.addObjectAtPos 'KikiWall', 5, i, 3 - world.addObjectAtPos 'KikiWall', 5, i, 4 - world.addObjectAtPos 'KikiWall', 6, i, 1 - world.addObjectAtPos 'KikiWall', 6, i, 2 - world.addObjectAtPos 'KikiWall', 7, i, 2 - world.addObjectAtPos 'KikiWall', 7, i, 4 - world.addObjectAtPos 'KikiWall', 7, i, 5 - world.addObjectAtPos 'KikiWall', 8, i, 0 - world.addObjectAtPos 'KikiWall', 8, i, 2 - world.addObjectAtPos 'KikiWall', 8, i, 4 - world.addObjectAtPos 'KikiWall', 8, i, 5 - world.addObjectAtPos 'KikiWall', 9, i, 2 - world.addObjectAtPos 'KikiWall', 9, i, 4 - world.addObjectAtPos 'KikiWall', 10, i, 3 + world.addObjectAtPos 'Wall', 1, i, 1 + world.addObjectAtPos 'Wall', 1, i, 3 + world.addObjectAtPos 'Wall', 2, i, 1 + world.addObjectAtPos 'Wall', 2, i, 2 + world.addObjectAtPos 'Wall', 2, i, 5 + world.addObjectAtPos 'Wall', 3, i, 1 + world.addObjectAtPos 'Wall', 3, i, 2 + world.addObjectAtPos 'Wall', 3, i, 4 + world.addObjectAtPos 'Wall', 3, i, 5 + world.addObjectAtPos 'Wall', 5, i, 0 + world.addObjectAtPos 'Wall', 5, i, 2 + world.addObjectAtPos 'Wall', 5, i, 3 + world.addObjectAtPos 'Wall', 5, i, 4 + world.addObjectAtPos 'Wall', 6, i, 1 + world.addObjectAtPos 'Wall', 6, i, 2 + world.addObjectAtPos 'Wall', 7, i, 2 + world.addObjectAtPos 'Wall', 7, i, 4 + world.addObjectAtPos 'Wall', 7, i, 5 + world.addObjectAtPos 'Wall', 8, i, 0 + world.addObjectAtPos 'Wall', 8, i, 2 + world.addObjectAtPos 'Wall', 8, i, 4 + world.addObjectAtPos 'Wall', 8, i, 5 + world.addObjectAtPos 'Wall', 9, i, 2 + world.addObjectAtPos 'Wall', 9, i, 4 + world.addObjectAtPos 'Wall', 10, i, 3 for i in [0...s.x] for j in [0...s.z] - world.addObjectAtPos 'KikiStone', i,2,j + world.addObjectAtPos 'Stone', i,2,j world.switch_counter = 0 - switched = (swtch) -> world.switch_counter += swtch.active and 1 or -1 - exit = kikiObjectToGate(world.getObjectWithName("exit")) - exit.setActive(world.switch_counter == 4) + exit = world.getObjectWithName "exit" + exit.setActive world.switch_counter == 4 - switch1 = KikiSwitch() - # switch1.getEventWithName("switched").addAction(continuous(() -> s=switch1: switched(s))) - switch2 = KikiSwitch() - # switch2.getEventWithName("switched").addAction(continuous(() -> s=switch2: switched(s))) - switch3 = KikiSwitch() - # switch3.getEventWithName("switched").addAction(continuous(() -> s=switch3: switched(s))) - switch4 = KikiSwitch() - # switch4.getEventWithName("switched").addAction(continuous(() -> s=switch4: switched(s))) + 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 world.addObjectAtPos switch1, 1, 0 ,2 world.addObjectAtPos switch2, 7, 1, 0 diff --git a/coffee/levels/energy.coffee b/coffee/levels/energy.coffee index 8fbd0f0..55cda7f 100644 --- a/coffee/levels/energy.coffee +++ b/coffee/levels/energy.coffee @@ -22,66 +22,67 @@ module.exports = s = world.size - world.addObjectLine('KikiWall', [0, s.y/2, s.z/2], [s.x, s.y/2, s.z/2]) - world.addObjectLine('KikiWall', [s.x/2, s.y/2, 0], [s.x/2, s.y/2, s.z]) - world.deleteObject(world.getOccupantAtPos(world.decenter(0,0,0))) + world.addObjectLine 'Wall', [0, s.y/2, s.z/2], [s.x, s.y/2, s.z/2] + world.addObjectLine 'Wall', [s.x/2, s.y/2, 0], [s.x/2, s.y/2, s.z] + world.deleteObject world.getOccupantAtPos world.decenter 0,0,0 - world.addObjectAtPos('KikiWall', world.decenter(0, 3, 0)) - world.addObjectAtPos('KikiWall', world.decenter(0, 6, 0)) + world.addObjectAtPos 'Wall', world.decenter 0, 3, 0 + world.addObjectAtPos 'Wall', world.decenter 0, 6, 0 + + world.addObjectAtPos 'Wall', world.decenter 0, -4, 0 + world.addObjectAtPos 'Wall', world.decenter 2,-5, 1 + world.addObjectAtPos 'Wall', world.decenter -1,-5, 2 + world.addObjectAtPos 'Wall', world.decenter -2,-5,-1 + world.addObjectAtPos 'Wall', world.decenter 1,-5,-2 - world.addObjectAtPos('KikiWall', world.decenter(0, -4, 0)) - world.addObjectAtPos('KikiWall', world.decenter( 2,-5, 1)) - world.addObjectAtPos('KikiWall', world.decenter(-1,-5, 2)) - world.addObjectAtPos('KikiWall', world.decenter(-2,-5,-1)) - world.addObjectAtPos('KikiWall', world.decenter( 1,-5,-2)) - - world.addObjectAtPos('KikiMutant', world.decenter( 2,-5, 2)) - world.addObjectAtPos('KikiMutant', world.decenter(-2,-5,-2)) - world.addObjectAtPos('KikiMutant', world.decenter( 1,-5, 1)) - world.addObjectAtPos('KikiMutant', world.decenter(-1,-5,-1)) - world.addObjectAtPos('KikiMutant', world.decenter( 2,-5,-2)) - world.addObjectAtPos('KikiMutant', world.decenter(-2,-5, 2)) - world.addObjectAtPos('KikiMutant', world.decenter( 1,-5,-1)) - world.addObjectAtPos('KikiMutant', world.decenter(-1,-5, 1)) + world.addObjectAtPos 'Mutant', world.decenter 2,-5, 2 + world.addObjectAtPos 'Mutant', world.decenter -2,-5,-2 + world.addObjectAtPos 'Mutant', world.decenter 1,-5, 1 + world.addObjectAtPos 'Mutant', world.decenter -1,-5,-1 + world.addObjectAtPos 'Mutant', world.decenter 2,-5,-2 + world.addObjectAtPos 'Mutant', world.decenter -2,-5, 2 + world.addObjectAtPos 'Mutant', world.decenter 1,-5,-1 + world.addObjectAtPos 'Mutant', world.decenter -1,-5, 1 - world.addObjectAtPos('KikiWall', world.decenter( 0, 3, s.z/2)) - world.addObjectAtPos('KikiWall', world.decenter( 0, 5, s.z/2)) - world.addObjectAtPos('KikiWall', world.decenter( 1, 4, s.z/2)) - world.addObjectAtPos('KikiWall', world.decenter(-1, 4, s.z/2)) - - world.addObjectAtPos('KikiWall', world.decenter(s.x/2, 3, 0)) - world.addObjectAtPos('KikiWall', world.decenter(s.x/2, 5, 0)) - world.addObjectAtPos('KikiWall', world.decenter(s.x/2, 4, 1)) - world.addObjectAtPos('KikiWall', world.decenter(s.x/2, 4, -1)) - - world.addObjectAtPos('KikiWall', world.decenter( 0, 3, -s.z/2+1)) - world.addObjectAtPos('KikiWall', world.decenter( 0, 5, -s.z/2+1)) - world.addObjectAtPos('KikiWall', world.decenter( 1, 4, -s.z/2+1)) - world.addObjectAtPos('KikiWall', world.decenter(-1, 4, -s.z/2+1)) - - world.addObjectAtPos('KikiWall', world.decenter(-s.x/2+1, 3, 0)) - world.addObjectAtPos('KikiWall', world.decenter(-s.x/2+1, 5, 0)) - world.addObjectAtPos('KikiWall', world.decenter(-s.x/2+1, 4, 1)) - world.addObjectAtPos('KikiWall', world.decenter(-s.x/2+1, 4, -1)) + world.addObjectAtPos 'Wall', world.decenter 0, 3, s.z/2 + world.addObjectAtPos 'Wall', world.decenter 0, 5, s.z/2 + world.addObjectAtPos 'Wall', world.decenter 1, 4, s.z/2 + world.addObjectAtPos 'Wall', world.decenter -1, 4, s.z/2 + + world.addObjectAtPos 'Wall', world.decenter s.x/2, 3, 0 + world.addObjectAtPos 'Wall', world.decenter s.x/2, 5, 0 + world.addObjectAtPos 'Wall', world.decenter s.x/2, 4, 1 + world.addObjectAtPos 'Wall', world.decenter s.x/2, 4, -1 + + world.addObjectAtPos 'Wall', world.decenter 0, 3, -s.z/2+1 + world.addObjectAtPos 'Wall', world.decenter 0, 5, -s.z/2+1 + world.addObjectAtPos 'Wall', world.decenter 1, 4, -s.z/2+1 + world.addObjectAtPos 'Wall', world.decenter -1, 4, -s.z/2+1 + + world.addObjectAtPos 'Wall', world.decenter -s.x/2+1, 3, 0 + world.addObjectAtPos 'Wall', world.decenter -s.x/2+1, 5, 0 + world.addObjectAtPos 'Wall', world.decenter -s.x/2+1, 4, 1 + world.addObjectAtPos 'Wall', world.decenter -s.x/2+1, 4, -1 world.switch_counter = 0 switched = (swtch) -> world.switch_counter += swtch.active and 1 or -1 - exit = kikiObjectToGate (world.getObjectWithName("exit")) - exit.setActive(world.switch_counter == 4) + exit = world.getObjectWithName "exit" + exit.setActive world.switch_counter == 4 - switch1 = KikiSwitch() - switch1.getEventWithName("switched").addAction(continuous(()-> sw=switch1: switched(sw))) - switch2 = KikiSwitch() - switch2.getEventWithName("switched").addAction(continuous(()-> sw=switch2: switched(sw))) - switch3 = KikiSwitch() - switch3.getEventWithName("switched").addAction(continuous(()-> sw=switch3: switched(sw))) - switch4 = KikiSwitch() - switch4.getEventWithName("switched").addAction(continuous(()-> sw=switch4: switched(sw))) + Switch = require '../switch' + switch1 = new Switch + switch1.getEventWithName("switched").addAction world.continuous (sw=switch1) -> switched sw + switch2 = new Switch + switch2.getEventWithName("switched").addAction world.continuous (sw=switch2) -> switched sw + switch3 = new Switch + switch3.getEventWithName("switched").addAction world.continuous (sw=switch3) -> switched sw + switch4 = new Switch + switch4.getEventWithName("switched").addAction world.continuous (sw=switch4) -> switched sw - world.addObjectAtPos(switch1, world.decenter(-s.x/2+1, 4, 0)) - world.addObjectAtPos(switch2, world.decenter( s.x/2, 4, 0)) - world.addObjectAtPos(switch3, world.decenter(0, 4, -s.z/2+1)) - world.addObjectAtPos(switch4, world.decenter(0, 4, s.z/2)) + world.addObjectAtPos switch1, world.decenter -s.x/2+1, 4, 0 + world.addObjectAtPos switch2, world.decenter s.x/2, 4, 0 + world.addObjectAtPos switch3, world.decenter 0, 4, -s.z/2+1 + world.addObjectAtPos switch4, world.decenter 0, 4, s.z/2 \ No newline at end of file diff --git a/coffee/levels/grasp.coffee b/coffee/levels/grasp.coffee index f7d044f..4c1aed5 100644 --- a/coffee/levels/grasp.coffee +++ b/coffee/levels/grasp.coffee @@ -47,6 +47,6 @@ module.exports = Switch = require '../switch' exit_switch = new Switch - exit_switch.getEventWithName("switched").addAction continuous -> world.toggle "exit" + exit_switch.getEventWithName("switched").addAction world.continuous -> world.toggle "exit" world.addObjectAtPos exit_switch, s.x/2, s.y/2, 0 \ No newline at end of file diff --git a/coffee/levels/hidden.coffee b/coffee/levels/hidden.coffee index d9ec2f6..b46dea6 100644 --- a/coffee/levels/hidden.coffee +++ b/coffee/levels/hidden.coffee @@ -22,13 +22,14 @@ module.exports = ], create: -> s = world.size + Switch = require '../switch' world.addObjectAtPos('KikiStone', 0,0,1) world.addObjectAtPos('KikiStone', 0,1,0) world.addObjectAtPos('KikiStone', 1,0,1) world.addObjectAtPos('KikiStone', 1,1,0) world.addObjectAtPos('KikiStone', 2,0,0) - switch1 = KikiSwitch() + switch1 = new Switch world.addObjectAtPos(switch1, 1,0,0) world.addObjectAtPos('KikiStone', s.x-1,0,1) @@ -36,7 +37,7 @@ module.exports = world.addObjectAtPos('KikiStone', s.x-2,0,1) world.addObjectAtPos('KikiStone', s.x-2,1,0) world.addObjectAtPos('KikiStone', s.x-3,0,0) - switch2 = KikiSwitch() + switch2 = new Switch world.addObjectAtPos(switch2, s.x-2,0,0) world.addObjectAtPos('KikiStone', 0,0,s.z-2) @@ -44,7 +45,7 @@ module.exports = world.addObjectAtPos('KikiStone', 1,0,s.z-2) world.addObjectAtPos('KikiStone', 1,1,s.z-1) world.addObjectAtPos('KikiStone', 2,0,s.z-1) - switch3 = KikiSwitch() + switch3 = new Switch world.addObjectAtPos(switch3, 1,0,s.z-1) world.addObjectAtPos('KikiStone', s.x-1,0,s.z-2) @@ -52,11 +53,11 @@ module.exports = world.addObjectAtPos('KikiStone', s.x-2,0,s.z-2) world.addObjectAtPos('KikiStone', s.x-2,1,s.z-1) world.addObjectAtPos('KikiStone', s.x-3,0,s.z-1) - switch4 = KikiSwitch() + switch4 = new Switch world.addObjectAtPos(switch4, s.x-2,0,s.z-1) world.addObjectPoly('KikiStone', [ [s.x/2-1,s.y-1,s.z/2-1], [s.x/2-1,s.y-1,s.z/2+1], [s.x/2+1,s.y-1,s.z/2+1], [s.x/2+1,s.y-1,s.z/2-1]]) - switch5 = KikiSwitch() + switch5 = new Switch world.addObjectAtPos('KikiStone', s.x/2,s.y-2,s.z/2) world.addObjectAtPos(switch5, s.x/2,s.y-1,s.z/2) diff --git a/coffee/levels/invisimaze.coffee b/coffee/levels/invisimaze.coffee index 9aea07f..5b9cf93 100644 --- a/coffee/levels/invisimaze.coffee +++ b/coffee/levels/invisimaze.coffee @@ -25,11 +25,12 @@ module.exports = create: -> s = world.size + Switch = require '../switch' switched = (swtch) -> world.switch_counter += swtch.active and 1 or -1 - exit = kikiObjectToGate(world.getObjectWithName("exit")) - exit.setActive(world.switch_counter == 5) + exit = world.getObjectWithName "exit" + exit.setActive world.switch_counter == 5 switchBoth = () -> world.toggle("exit1") @@ -37,7 +38,7 @@ module.exports = #randomly assign the switches to different locations tup_array = [[0,0,0], [2,1,-2], [-2,-2,0], [-1,2,1], [-2,-2,-1], [1,-1,2]] - random.shuffle(tup_array) + # random.shuffle(tup_array) i0 = tup_array[0] i1 = tup_array[1] @@ -46,25 +47,25 @@ module.exports = i4 = tup_array[4] i5 = tup_array[5] - exit_switch = KikiSwitch() - exit_switch.getEventWithName("switched").addAction(continuous(() -> switchBoth())) - world.addObjectAtPos(exit_switch, world.decenter(i0)) + exit_switch = new Switch + exit_switch.getEventWithName("switched").addAction world.continuous -> switchBoth() + world.addObjectAtPos exit_switch, world.decenter(i0) - exit2_switch = KikiSwitch() - exit2_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit2"))) - world.addObjectAtPos(exit2_switch, world.decenter(i1)) + exit2_switch = new Switch + exit2_switch.getEventWithName("switched").addAction world.continuous -> world.toggle "exit2" + world.addObjectAtPos exit2_switch, world.decenter(i1) - exit3_switch = KikiSwitch() - exit3_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit1"))) - world.addObjectAtPos(exit3_switch, world.decenter(i2)) + exit3_switch = new Switch + exit3_switch.getEventWithName("switched").addAction world.continuous -> world.toggle "exit1" + world.addObjectAtPos exit3_switch, world.decenter(i2) - exit4_switch = KikiSwitch() - exit4_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit1"))) - world.addObjectAtPos(exit4_switch, world.decenter(i3)) + exit4_switch = new Switch + exit4_switch.getEventWithName("switched").addAction world.continuous -> world.toggle "exit1" + world.addObjectAtPos exit4_switch, world.decenter(i3) - exit5_switch = KikiSwitch() - exit5_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit1"))) - world.addObjectAtPos(exit5_switch, world.decenter(i4)) + exit5_switch = new Switch + exit5_switch.getEventWithName("switched").addAction world.continuous -> world.toggle "exit1" + world.addObjectAtPos exit5_switch, world.decenter(i4) # Invisimaze for y in [0, 1] @@ -73,56 +74,56 @@ module.exports = # for y in [0] # for x in [2] - world.addObjectPoly('KikiStone', [world.decenter(-2, 0, -2), world.decenter(-2, 0, 2), world.decenter(2, 0, 2), world.decenter(2, 0, -2)]) + world.addObjectPoly 'KikiStone', [world.decenter(-2, 0, -2), world.decenter(-2, 0, 2), world.decenter(2, 0, 2), world.decenter(2, 0, -2)] - world.addObjectPoly('KikiStone', [[2, 4, 2], [2, 4, 4], [4, 4, 4], [4, 4, 2]]) + world.addObjectPoly 'KikiStone', [[2, 4, 2], [2, 4, 4], [4, 4, 4], [4, 4, 2]] - world.addObjectAtPos('KikiStone', 2, 3, 2) - world.addObjectAtPos('KikiStone', 6, 3, 1) - world.addObjectAtPos('KikiStone', 6, 3, 3) - world.addObjectAtPos('KikiStone', 2, 1, 1) - world.addObjectAtPos('KikiStone', 3, 0, 1) - world.addObjectAtPos('KikiStone', 2, 1, 2) - world.addObjectAtPos('KikiStone', 2, 0, 2) - world.addObjectAtPos('KikiStone', 4, 2, 3) - world.addObjectAtPos('KikiStone', 5, 2, 2) - world.addObjectAtPos('KikiStone', 5, 2, 1) - world.addObjectAtPos('KikiStone', 4, 2, 1) - world.addObjectAtPos('KikiStone', 3, 2, 2) - world.addObjectAtPos('KikiStone', 3, 2, 3) - world.addObjectAtPos('KikiStone', 5, 3, 0) + world.addObjectAtPos 'KikiStone', 2, 3, 2 + world.addObjectAtPos 'KikiStone', 6, 3, 1 + world.addObjectAtPos 'KikiStone', 6, 3, 3 + world.addObjectAtPos 'KikiStone', 2, 1, 1 + world.addObjectAtPos 'KikiStone', 3, 0, 1 + world.addObjectAtPos 'KikiStone', 2, 1, 2 + world.addObjectAtPos 'KikiStone', 2, 0, 2 + world.addObjectAtPos 'KikiStone', 4, 2, 3 + world.addObjectAtPos 'KikiStone', 5, 2, 2 + world.addObjectAtPos 'KikiStone', 5, 2, 1 + world.addObjectAtPos 'KikiStone', 4, 2, 1 + world.addObjectAtPos 'KikiStone', 3, 2, 2 + world.addObjectAtPos 'KikiStone', 3, 2, 3 + world.addObjectAtPos 'KikiStone', 5, 3, 0 - world.addObjectAtPos('KikiStone', 6, 4, 0) + world.addObjectAtPos 'KikiStone', 6, 4, 0 #the bombLock - world.addObjectAtPos('KikiStone', 7, 1, 2) - world.addObjectAtPos('KikiStone', 7, 1, 3) - world.addObjectAtPos('KikiStone', 7, 3, 2) - world.addObjectAtPos('KikiStone', 7, 2, 1) - world.addObjectAtPos('KikiStone', 7, 2, 2) - world.addObjectAtPos('KikiBomb', 7, 2, 2) + world.addObjectAtPos 'KikiStone', 7, 1, 2 + world.addObjectAtPos 'KikiStone', 7, 1, 3 + world.addObjectAtPos 'KikiStone', 7, 3, 2 + world.addObjectAtPos 'KikiStone', 7, 2, 1 + world.addObjectAtPos 'KikiStone', 7, 2, 2 + world.addObjectAtPos 'KikiBomb', 7, 2, 2 # Exit 1 is blocked!!! - world.addObjectAtPos('KikiMotorCylinder', 1, 2, 2) + # world.addObjectAtPos 'KikiMotorCylinder', 1, 2, 2 # Walls # for y in [-4,] y = -4 for x in [1, -1] - world.addObjectPoly('KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)]) + world.addObjectPoly 'KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)] # for y in [-3] y = -3 for x in [2, -2] - world.addObjectPoly('KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)]) + world.addObjectPoly 'KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)] # for y in [4,] y = 4 for x in [1, -1] - world.addObjectPoly('KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)]) + world.addObjectPoly 'KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)] # for y in [3] y = 3 for x in [2, -2] - world.addObjectPoly('KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)]) + world.addObjectPoly 'KikiWall', [world.decenter(y, -x, -x), world.decenter(y, -x, x), world.decenter(y, x, x), world.decenter(y, x, -x)] \ No newline at end of file diff --git a/coffee/levels/move.coffee b/coffee/levels/move.coffee index 7ac42ea..8a3df73 100644 --- a/coffee/levels/move.coffee +++ b/coffee/levels/move.coffee @@ -42,6 +42,7 @@ module.exports = world.addObjectAtPos('KikiStone', s.x/2, s.y/2, 1) - # exit_switch = KikiSwitch() + # Switch = require '../switch' + # exit_switch = new Switch # exit_switch.getEventWithName("switched").addAction(continuous(()-> world.toggle("exit"))) # world.addObjectAtPos(exit_switch, s.x/2, s.y/2, 0)) diff --git a/coffee/levels/spiral.coffee b/coffee/levels/spiral.coffee index 3194620..dd1ca1b 100644 --- a/coffee/levels/spiral.coffee +++ b/coffee/levels/spiral.coffee @@ -1,7 +1,13 @@ -# level design by Owen Hay + +# 0000000 00000000 000 00000000 0000000 000 +# 000 000 000 000 000 000 000 000 000 +# 0000000 00000000 000 0000000 000000000 000 +# 000 000 000 000 000 000 000 000 +# 0000000 000 000 000 000 000 000 0000000 module.exports = name: "spiral" + design: "Owen Hay" scheme: "zen_scheme" intro: "spiral" size: [5,25,5] @@ -20,29 +26,27 @@ module.exports = for y in [ -7, -3, 1, 5] x = 1 - world.addObjectPoly(KikiStone, [world.decenter(-x, y, -x), world.decenter(-x, y, x), world.decenter(x, y, x), ]) + world.addObjectPoly 'Stone', [world.decenter(-x, y, -x), world.decenter(-x, y, x), world.decenter(x, y, x), ] for y in [-9, -5, -1, 3] x = 1 - world.addObjectPoly(KikiStone, [world.decenter(x, y, x), world.decenter(x, y, -x), world.decenter(-x, y, -x), ]) + world.addObjectPoly 'Stone', [world.decenter(x, y, x), world.decenter(x, y, -x), world.decenter(-x, y, -x), ] for y in [12, 11] x = 2 - world.addObjectPoly(KikiWireStone, [world.decenter(-x, y, -x), world.decenter(-x, y, x), world.decenter(x, y, x), world.decenter(x, y, -x)]) + world.addObjectPoly 'WireStone', [world.decenter(-x, y, -x), world.decenter(-x, y, x), world.decenter(x, y, x), world.decenter(x, y, -x)] # KEY GEAR - world.addObjectAtPos(KikiGear(KikiFace.NY), world.decenter(0, -10, 0)) - + world.addObjectAtPos 'KikiGear(KikiFace.NY)', world.decenter 0, -10, 0 # LOCK MECHANISM - world.addObjectAtPos(KikiGenerator(KikiFace.NY), world.decenter(-1, 12, 0)) - world.addObjectAtPos(KikiGenerator(KikiFace.NY), world.decenter(-1, 11, 0)) + world.addObjectAtPos 'Generator(KikiFace.NY)', world.decenter -1, 12, 0 + world.addObjectAtPos 'Generator(KikiFace.NY)', world.decenter -1, 11, 0 + + world.addObjectAtPos 'MotorCylinder(KikiFace.NY)', world.decenter 1, 11, 0 + world.addObjectAtPos 'MotorGear(KikiFace.NY)', world.decenter 1, 12, 0 - world.addObjectAtPos(KikiMotorCylinder(KikiFace.NY), world.decenter(1, 11, 0)) - world.addObjectAtPos(KikiMotorGear(KikiFace.NY), world.decenter(1, 12, 0)) - - world.addObjectAtPos(KikiWireStone(), world.decenter(0, 11, 1)) - world.addObjectAtPos(KikiWireStone(), world.decenter(0, 12, 1)) - - world.addObjectAtPos(KikiWireStone(), world.decenter(0, 11, -1)) - world.addObjectAtPos(KikiWireStone(), world.decenter(0, 12, -1)) + world.addObjectAtPos 'WireStone', world.decenter 0, 11, 1 + world.addObjectAtPos 'WireStone', world.decenter 0, 12, 1 + world.addObjectAtPos 'WireStone', world.decenter 0, 11, -1 + world.addObjectAtPos 'WireStone', world.decenter 0, 12, -1 \ No newline at end of file diff --git a/coffee/lib/quaternion.coffee b/coffee/lib/quaternion.coffee index 18b34f8..da9093e 100644 --- a/coffee/lib/quaternion.coffee +++ b/coffee/lib/quaternion.coffee @@ -205,8 +205,8 @@ class Quaternion scale0 * @y + scale1 * to1[1], scale0 * @z + scale1 * to1[2] - @rotationAroundVector: (theta, vector) -> - v = new Vector vector + @rotationAroundVector: (theta, x,y,z) -> + v = new Vector x,y,z v.normalize() t = Vector.DEG2RAD(theta)/2.0 s = Math.sin t diff --git a/coffee/lib/vector.coffee b/coffee/lib/vector.coffee index 1c42306..a6fac7d 100644 --- a/coffee/lib/vector.coffee +++ b/coffee/lib/vector.coffee @@ -116,7 +116,7 @@ class Vector rayDot = rayDir.dot planeNormal if Number.isNaN rayDot throw new Error - return 0 if rayDot == 0 + return 2 if rayDot == 0 r = planePos.minus(rayPos).dot(planeNormal) / rayDot if Number.isNaN r log 'rayPos', rayPos diff --git a/coffee/valve.coffee b/coffee/valve.coffee new file mode 100644 index 0000000..a31f884 --- /dev/null +++ b/coffee/valve.coffee @@ -0,0 +1,53 @@ +# 000 000 0000000 000 000 000 00000000 +# 000 000 000 000 000 000 000 000 +# 000 000 000000000 000 000 000 0000000 +# 000 000 000 000 000 000 +# 0 000 000 0000000 0 00000000 + +Pushable = require './pushable' +Action = require './action' + +class Valve extends Pushable + + constructor: (face) -> + @face = face + @angle = 0.0 + @active = false + @clockwise = false + @addAction new Action @, Action.ROTATE, "rotation", 2000, Action.REPEAT + @startTimedAction @getActionWithId Action.ROTATE + + updateMesh: -> + @mesh.rotation.copy Quaternion.rotationAroundVector (@clockwise and 1 or -1) * @angle, 0,0,1 + + # display: () -> + # KikiObject::preDisplay(); +# + # KMatrix m (KikiFace::orientationForFace (face)); + # m.glMultMatrix(); +# + # render(); +# + # KikiObject::postDisplay(); + + setPosition: (pos) -> + super pos + p = @getPos() + dir = @face % 3 + sum = ((dir == Face.Y or dir == Face.Z) and p.x or 0) + ((dir == Face.X or dir == Face.Z) and p.y or 0) + ((dir == Face.X or dir == Face.Y) and p.z or 0) + @clockwise = sum % 2 + + performAction: (action) -> + switch action.id + when Action.ROTATE + @angle += action.getRelativeDelta() * 360 + @updateMesh() + else super action + + render: -> + # colors[0].glColor(); +# + # glRotatef (clockwise ? angle : -angle, 0.0, 0.0, 1.0); + # render_valve; + +module.exports = Valve diff --git a/coffee/wire.coffee b/coffee/wire.coffee new file mode 100644 index 0000000..79bb962 --- /dev/null +++ b/coffee/wire.coffee @@ -0,0 +1,136 @@ +# 000 000 000 00000000 00000000 +# 000 0 000 000 000 000 000 +# 000000000 000 0000000 0000000 +# 000 000 000 000 000 000 +# 00 00 000 000 000 00000000 + +Item = require './item' + +class Wire extends Item + + constructor: (@face, @connections) -> + + @active = false + @value = 1.0 + + @SWITCH_OFF_EVENT = @addEventWithName "off" + @SWITCH_ON_EVENT = @addEventWithName "on" + @SWITCHED_EVENT = @addEventWithName "switched" + + @updateActive: -> + for wire in @getNeighborWires() + @setActive true if wire.active + + setActive: (active) -> + if @active != active + @active = active + neighbors = @getNeighborWires() + + active_neighbor = false + if @active + for wire in neighbors + if wire.active + active_neighbor = true + break + + for wire in wires + wire.setActive active + + cellSwitch = world.getObjectOfTypeAtPos KikiSwitch, @getPos() + if cellSwitch? + cellSwitch.setActive active + + @events[@active and @SWITCH_ON_EVENT or @SWITCH_OFF_EVENT].triggerActions() + @events[@SWITCHED_EVENT].triggerActions() + + getNeighborWires: -> + wires = [] + points = @getConnectionPoints() + neighbor_dirs = [] + + rot = Face.orientationForFace @face + n = Face.normalVectorForFace @face + + neighbor_dirs.push_back new Vector + + if @connections & RIGHT + neighbor_dirs.push_back rot.rotate new Vector(1,0,0) + neighbor_dirs.push_back rot.rotate new Vector(1,0,0) + n + if @connections & LEFT + neighbor_dirs.push_back rot.rotate new Vector(-1,0,0) + neighbor_dirs.push_back rot.rotate new Vector(-1,0,0) + n + if @connections & UP + neighbor_dirs.push_back rot.rotate new Vector(0,1,0) + neighbor_dirs.push_back rot.rotate new Vector(0,1,0) + n + if @connections & DOWN + neighbor_dirs.push_back rot.rotate new Vector(0,-1,0) + neighbor_dirs.push_back rot.rotate new Vector(0,-1,0) + n + + for i in [0...neighbor_dirs.length] + neighbors = world.getObjectsOfTypeAtPos Wire, @position.plus neighbor_dirs[i] + for iter in neighbors + continue if iter == @ + neighbor_points = iter.getConnectionPoints() + for point in points + for neighbor_point in neighbor_points + if (neighbor_point.minus point).length() < 0.1 + wires.push iter + + wires + + getConnectionPoints: -> + points = [] + to_border = 0.5 * Face.normalVectorForFace @face + rot = Face.orientationForFace @face + + if (connections & RIGHT) + points.push position.plus to_border.plus rot.rotate new Vector 0.5, 0, 0 + if (connections & LEFT) + points.push position.plus to_border.plus rot.rotate new Vector -0.5, 0, 0 + if (connections & UP) + points.push position.plus to_border.plus rot.rotate new Vector 0, 0.5, 0 + if (connections & DOWN) + points.push position.plus to_border.plus rot.rotate new Vector 0, -0.5, 0 + + points + + display: -> + # KikiObject::preDisplay(); + # KVector face_normal = KikiFace::normalVectorForFace (face); + # float o = 0.005; + # ((0.5-o) * face_normal).glTranslate(); +# + # glPushMatrix(); +# + # KMatrix mat(KikiFace::orientationForFace (face)); + # mat.glMultMatrix(); +# + # colors[KikiWire_base_color].glColor(); +# + # render_wire; +# + # glDisable (GL_CULL_FACE); + # float h = 0.05; + # float s = 0.5+o; + # glNormal3f(0.0, 0.0, 1.0); + # if (connections & RIGHT) glRectf ( 0.0, -h, s, h); + # if (connections & LEFT) glRectf (-s, -h, 0.0, h); + # if (connections & UP) glRectf (-h, 0.0, h, s); + # if (connections & DOWN) glRectf (-h, -s, h, 0.0); + # glEnable (GL_CULL_FACE); +# + # glPopMatrix(); +# + # if (active) + # KColor c (colors[KikiWire_light_color]); + # c.setAlpha (value); + # c.glColor(); +# + # (face_normal * -0.1).glTranslate(); +# + # KikiBillBoard::displayTextureWithSize + # (Controller.world->getTextureId(KikiWorld::TEXTURE_GRADIENT), 0.15); +# + # KikiObject::postDisplay(); + +module.exports = Wire diff --git a/coffee/wirestone.coffee b/coffee/wirestone.coffee new file mode 100644 index 0000000..7a313b4 --- /dev/null +++ b/coffee/wirestone.coffee @@ -0,0 +1,67 @@ +# 000 000 000 00000000 00000000 0000000 000000000 0000000 000 000 00000000 +# 000 0 000 000 000 000 000 000 000 000 000 0000 000 000 +# 000000000 000 0000000 0000000 0000000 000 000 000 000 0 000 0000000 +# 000 000 000 000 000 000 000 000 000 000 000 0000 000 +# 00 00 000 000 000 00000000 0000000 000 0000000 000 000 00000000 + +Stone = require './stone' +Wall = require './wall' +Face = require './face' +Generator = require './generator' + +class WireStone extends Stone + + constructor: () -> + @wires = [null, null, null, null, null, null] + + initAction: (action) -> + + switch action.id + + when Action.FALL, Action.PUSH + + for i in [0...6] + if @wires[i]? + world.unsetObject @wires[i] + @wires[i].setActive false + + for generator in world.getObjectsOfType Generator + if generator.isActive() + generator.activateWires() + + super action + + setPosition: (pos) -> + for i in [0...6] + newPos = pos - Face.normalVectorForFace (i); + if @isFreePos newPos + if not @wires[i]? + @wires[i] = new KikiWire i + world.addObjectAtPos @wires[i], newPos + else + world.setObjectAtPos @wires[i], newPos + @wires[i].updateActive() + else if @wires[i]? + @wires[i].del() + @wires[i] = null + + for generator in world.getObjectsOfType Generator + if generator.isActive() + generator.activateWires() + + super pos + + setCurrentPosition: (pos) -> + super pos + for i in [0...6] + @wires[i]?.setPosition pos.minus Face.normalVectorForFace i + + isFreePos: (pos) -> + if world.isUnoccupiedPos pos + return true + if world.isValidPos pos + occupant = world.getOccupantAtPos pos + return (occupant instanceof Wall) or not (occupant instanceof Stone) + return false + +module.exports = WireStone diff --git a/coffee/world.coffee b/coffee/world.coffee index 6c5f8e5..1939505 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -52,7 +52,7 @@ class World extends Actor constructor: (@view) -> - @speed = 2 + @speed = 6 @raster_size = 0.05 # @camera_mode = World.CAMERA_INSIDE