diff --git a/coffee/item.coffee b/coffee/item.coffee new file mode 100644 index 0000000..7418eec --- /dev/null +++ b/coffee/item.coffee @@ -0,0 +1,12 @@ + +# 000 000000000 00000000 00 00 +# 000 000 000 000 000 +# 000 000 0000000 000000000 +# 000 000 000 000 0 000 +# 000 000 00000000 000 000 + +class Item + + isSpaceEgoistic: -> true + +module.exports = Item \ No newline at end of file diff --git a/coffee/levels/bridge.coffee b/coffee/levels/bridge.coffee index d7ec2d8..0a3bad3 100644 --- a/coffee/levels/bridge.coffee +++ b/coffee/levels/bridge.coffee @@ -30,7 +30,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos KikiMotorGear(KikiFace.NY), KikiPos s.x/2-1, s.y-1, s.z/2 world.addObjectAtPos KikiMotorCylinder(KikiFace.NY), KikiPos s.x/2-1, s.y-2, s.z/2 diff --git a/coffee/levels/bronze.coffee b/coffee/levels/bronze.coffee index 470d28a..0c8e18d 100644 --- a/coffee/levels/bronze.coffee +++ b/coffee/levels/bronze.coffee @@ -24,7 +24,7 @@ module.exports = position: [0,0,0] ] create: -> - s = world.getSize() + s = world.size d = 2 world.addObjectAtPos(KikiMotorCylinder(KikiFace.PY), KikiPos(s.x/2, 1, s.z/2)) diff --git a/coffee/levels/captured.coffee b/coffee/levels/captured.coffee index 0c15e8b..658d757 100644 --- a/coffee/levels/captured.coffee +++ b/coffee/levels/captured.coffee @@ -20,7 +20,7 @@ module.exports = position: [0,0,0] ] create: -> - s = world.getSize() + s = world.size for i in [-2, 2] world.addObjectPoly(KikiStone, [world.decenter(1, 1, i), world.decenter(1, -1, i), world.decenter(-1, -1, i), world.decenter(-1, 1, i)]) diff --git a/coffee/levels/chain.coffee b/coffee/levels/chain.coffee index 0ae0f12..01c9865 100644 --- a/coffee/levels/chain.coffee +++ b/coffee/levels/chain.coffee @@ -24,7 +24,7 @@ module.exports = position: [0,-1,0] ], create: -> - s = world.getSize() + s = world.size d = s.z/2 world.addObjectAtPos(KikiWall(), KikiPos(0, 0, d)) diff --git a/coffee/levels/cheese.coffee b/coffee/levels/cheese.coffee index e8d6198..b43875a 100644 --- a/coffee/levels/cheese.coffee +++ b/coffee/levels/cheese.coffee @@ -28,7 +28,7 @@ module.exports = position: [-1,0,0] ] create: -> - s = world.getSize() + s = world.size h = 0 # bomb and stones for i in [1, 2] diff --git a/coffee/levels/church.coffee b/coffee/levels/church.coffee index e9caab4..1064138 100644 --- a/coffee/levels/church.coffee +++ b/coffee/levels/church.coffee @@ -23,7 +23,7 @@ module.exports = position: [0,-1,0] ] create: -> - s = world.getSize() + s = world.size world.addObjectLine("KikiWireStone()", KikiPos(0, 0, 0), KikiPos(0, s.y-2, 0)) world.addObjectLine("KikiWireStone()", KikiPos(s.x-1, 0, 0), KikiPos(s.x-1, s.y-2, 0)) diff --git a/coffee/levels/circuit.coffee b/coffee/levels/circuit.coffee index 18b35d9..2656e77 100644 --- a/coffee/levels/circuit.coffee +++ b/coffee/levels/circuit.coffee @@ -23,7 +23,7 @@ module.exports = coordinates: [8,8,8] ] create: -> - s=world.getSize() + s=world.size mx=s.x/2 my=s.y/2 mz=s.z/2 diff --git a/coffee/levels/columns.coffee b/coffee/levels/columns.coffee index 2f8a454..6641300 100644 --- a/coffee/levels/columns.coffee +++ b/coffee/levels/columns.coffee @@ -19,7 +19,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size for y in range(-s.y/2+1, s.y/2+1) for x in range(-s.x/2+1, s.x/2+1, 2) diff --git a/coffee/levels/edge.coffee b/coffee/levels/edge.coffee index 1a6c781..05d786c 100644 --- a/coffee/levels/edge.coffee +++ b/coffee/levels/edge.coffee @@ -16,7 +16,7 @@ module.exports = position: [0,0,0] ] create: -> - s=world.getSize() + s=world.size # for (i,j,l) in [ (m,n,o) for m in range(3) for n in range(3) for o in range(3)] for i in [0...3] diff --git a/coffee/levels/electro.coffee b/coffee/levels/electro.coffee index c048f03..ce992e7 100644 --- a/coffee/levels/electro.coffee +++ b/coffee/levels/electro.coffee @@ -23,7 +23,7 @@ module.exports = position: [0,0,0] ], create: -> - s = world.getSize() + s = world.size d = 2 world.addObjectLine(KikiWireStone, world.decenter(-d, s.y/2, 0), world.decenter(-d, 0, 0)) diff --git a/coffee/levels/elevate.coffee b/coffee/levels/elevate.coffee index 13d8b7a..4cee77f 100644 --- a/coffee/levels/elevate.coffee +++ b/coffee/levels/elevate.coffee @@ -26,7 +26,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiMotorGear(KikiFace.NY), KikiPos(s.x/2-3, s.y-1, s.z/2)) world.addObjectAtPos(KikiMotorCylinder(KikiFace.NY), KikiPos(s.x/2-3, s.y-2, s.z/2)) diff --git a/coffee/levels/energy.coffee b/coffee/levels/energy.coffee index 9358899..2244dcc 100644 --- a/coffee/levels/energy.coffee +++ b/coffee/levels/energy.coffee @@ -20,7 +20,7 @@ module.exports = ], create: -> - s = world.getSize() + 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]) diff --git a/coffee/levels/entropy.coffee b/coffee/levels/entropy.coffee index c5cf9f9..3783e88 100644 --- a/coffee/levels/entropy.coffee +++ b/coffee/levels/entropy.coffee @@ -21,7 +21,7 @@ module.exports = position: [0,0,0] ] create: -> - s=world.getSize() + s=world.size d=2 # for (i,j,l) in [ (m,n,o) for m in range(s.x) for n in range(s.y) for o in range(s.z)] for i in [0...s.x] diff --git a/coffee/levels/escape.coffee b/coffee/levels/escape.coffee index fa09d0d..f13e74a 100644 --- a/coffee/levels/escape.coffee +++ b/coffee/levels/escape.coffee @@ -27,7 +27,7 @@ module.exports = ] create: -> # - s = world.getSize() + s = world.size exit_switch = KikiSwitch() exit_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit"))) diff --git a/coffee/levels/fallen.coffee b/coffee/levels/fallen.coffee index bb65eee..4372d49 100644 --- a/coffee/levels/fallen.coffee +++ b/coffee/levels/fallen.coffee @@ -31,7 +31,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size #hop back on world.addObjectAtPos(KikiWall(), KikiPos(2, 12, 12)) diff --git a/coffee/levels/flower.coffee b/coffee/levels/flower.coffee index a387283..98d4c06 100644 --- a/coffee/levels/flower.coffee +++ b/coffee/levels/flower.coffee @@ -23,7 +23,7 @@ module.exports = position: [0,0,0] ] create: -> - s = world.getSize() + s = world.size for m in [[1,KikiWall], [2,KikiStone]] for k in [-1*m[0],1*m[0]] for l in [-1*m[0],1*m[0]] diff --git a/coffee/levels/gamma.coffee b/coffee/levels/gamma.coffee index 4db47b7..88cc43b 100644 --- a/coffee/levels/gamma.coffee +++ b/coffee/levels/gamma.coffee @@ -23,7 +23,7 @@ module.exports = coordinates: [2,7,4] #absolute coord ] create: -> - s = world.getSize() + s = world.size world.switch_countera = 0 world.switch_counter = 0 diff --git a/coffee/levels/gears.coffee b/coffee/levels/gears.coffee index 622ef08..de71345 100644 --- a/coffee/levels/gears.coffee +++ b/coffee/levels/gears.coffee @@ -22,7 +22,7 @@ module.exports = position: [0,4,0] ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiWireStone(), world.decenter(-1, 0, 0)) world.addObjectAtPos(KikiWireStone(), world.decenter( 1, 0, 0)) diff --git a/coffee/levels/gold.coffee b/coffee/levels/gold.coffee index 340bbee..5c8eaae 100644 --- a/coffee/levels/gold.coffee +++ b/coffee/levels/gold.coffee @@ -17,7 +17,7 @@ module.exports = position: [0,4,0] ] create: -> - s = world.getSize() + s = world.size for y in range(-s.y/2+3, s.y/2, 2) for x in range(-s.x/2+1, s.x/2+1) for z in range(-s.z/2+1, s.z/2+1) diff --git a/coffee/levels/grasp.coffee b/coffee/levels/grasp.coffee index b844138..b57474d 100644 --- a/coffee/levels/grasp.coffee +++ b/coffee/levels/grasp.coffee @@ -20,7 +20,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 0)) world.addObjectAtPos(KikiStone(), KikiPos(s.x/2+1, s.y/2+1, 0)) diff --git a/coffee/levels/grid.coffee b/coffee/levels/grid.coffee index 7667d43..185ec25 100644 --- a/coffee/levels/grid.coffee +++ b/coffee/levels/grid.coffee @@ -17,7 +17,7 @@ module.exports = ] create: -> # - s = world.getSize() + s = world.size for y in [-1, 1] for x in range(-s.x/2+3, s.x/2-1, 2) diff --git a/coffee/levels/hidden.coffee b/coffee/levels/hidden.coffee index 1c26fdd..f5f880e 100644 --- a/coffee/levels/hidden.coffee +++ b/coffee/levels/hidden.coffee @@ -21,7 +21,7 @@ module.exports = position: [0,0,0] ], create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiStone(), KikiPos(0,0,1)) world.addObjectAtPos(KikiStone(), KikiPos(0,1,0)) diff --git a/coffee/levels/invisimaze.coffee b/coffee/levels/invisimaze.coffee index 735f12a..db1efaa 100644 --- a/coffee/levels/invisimaze.coffee +++ b/coffee/levels/invisimaze.coffee @@ -24,7 +24,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size switched = (swtch) -> world.switch_counter += swtch.isActive() and 1 or -1 diff --git a/coffee/levels/jump.coffee b/coffee/levels/jump.coffee index b4616f0..580e1ac 100644 --- a/coffee/levels/jump.coffee +++ b/coffee/levels/jump.coffee @@ -20,7 +20,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiWall(), world.decenter(0,0,1 - s.z/2)) world.addObjectAtPos(KikiWall(), world.decenter(0,0,3 - s.z/2)) diff --git a/coffee/levels/machine.coffee b/coffee/levels/machine.coffee index ed51400..58bc050 100644 --- a/coffee/levels/machine.coffee +++ b/coffee/levels/machine.coffee @@ -15,7 +15,7 @@ module.exports = coordinates: [1,2,8] ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiMotorGear(KikiFace.X), KikiPos(0,2,4)) world.addObjectAtPos(KikiWall(), KikiPos(0,2,3)) world.addObjectAtPos(KikiWall(), KikiPos(0,2,5)) diff --git a/coffee/levels/mesh.coffee b/coffee/levels/mesh.coffee index d15e0f8..3e54998 100644 --- a/coffee/levels/mesh.coffee +++ b/coffee/levels/mesh.coffee @@ -15,15 +15,15 @@ module.exports = ] create: -> - s=world.getSize() + s=world.size middlemax = (u,v,w) -> - s=world.getSize() + s=world.size d= 3.0/( (u-s.x/2.0)**2+ (v-s.y/2.0)**2 + (w-s.z/2.0)**2 + 1 ) return min(1.0 ,max(0.2,d)) middlemin = (u,v,w) -> - s=world.getSize() + s=world.size d= ( (u-s.x/2.0)**2+ (v-s.y/2.0)**2 + (w-s.z/2.0)**2 )/25 return min(1.0 ,max(0.4,d)) diff --git a/coffee/levels/move.coffee b/coffee/levels/move.coffee index 7ca6599..b9b32e3 100644 --- a/coffee/levels/move.coffee +++ b/coffee/levels/move.coffee @@ -22,7 +22,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 0)) world.addObjectAtPos(KikiStone(), KikiPos(s.x/2+1, s.y/2+1, 0)) diff --git a/coffee/levels/mutants.coffee b/coffee/levels/mutants.coffee index 7feb468..337e657 100644 --- a/coffee/levels/mutants.coffee +++ b/coffee/levels/mutants.coffee @@ -23,7 +23,7 @@ module.exports = ] create: -> # - s = world.getSize() + s = world.size world.addObjectLine(KikiWall, [2, 2, 2], [s.x - 3, 2, 2]) world.addObjectLine(KikiWall, [s.x - 3, 2, 2], [s.x - 3, s.y - 3, 2]) diff --git a/coffee/levels/nice.coffee b/coffee/levels/nice.coffee index af6772e..590234f 100644 --- a/coffee/levels/nice.coffee +++ b/coffee/levels/nice.coffee @@ -31,7 +31,7 @@ module.exports = KikiPos(p[0],p[1]-s,p[2]-s), KikiPos(p[0],p[1]-s,p[2]+s) ]) - s = world.getSize() + s = world.size world.addObjectLine(KikiWall, KikiPos(1,1,1), KikiPos(9,9,9)) world.addObjectLine(KikiWall, KikiPos(1,1,9), KikiPos(9,9,1)) world.addObjectLine(KikiWall, KikiPos(1,9,1), KikiPos(9,1,9)) diff --git a/coffee/levels/pool.coffee b/coffee/levels/pool.coffee index 5914368..828452a 100644 --- a/coffee/levels/pool.coffee +++ b/coffee/levels/pool.coffee @@ -16,7 +16,7 @@ module.exports = position: [0,0,-1] ] create: -> - s=world.getSize() + s=world.size d=1 # for (i,j,l) in [ (m,n,o) for m in range(s.x) for n in range(s.y) for o in range( s.z/2-1)] for i in [0...s.x] diff --git a/coffee/levels/rings.coffee b/coffee/levels/rings.coffee index 2296c66..f0c7de9 100644 --- a/coffee/levels/rings.coffee +++ b/coffee/levels/rings.coffee @@ -17,7 +17,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size for y in [-1, 1] x = 3 diff --git a/coffee/levels/slick.coffee b/coffee/levels/slick.coffee index a461b09..b27bd64 100644 --- a/coffee/levels/slick.coffee +++ b/coffee/levels/slick.coffee @@ -21,7 +21,7 @@ module.exports = position: [0,0,4] ] create: -> - s=world.getSize() + s=world.size for b in [1..3] # for (k,l) in [ (i,j) for i in range(b+1,s.x-b-1) for j in range(b+1,s.y-b-1) ] for k in [b+1..s.x-b] diff --git a/coffee/levels/spiral.coffee b/coffee/levels/spiral.coffee index 1721e3a..3194620 100644 --- a/coffee/levels/spiral.coffee +++ b/coffee/levels/spiral.coffee @@ -16,7 +16,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size for y in [ -7, -3, 1, 5] x = 1 diff --git a/coffee/levels/start.coffee b/coffee/levels/start.coffee index 5ec3051..3895834 100644 --- a/coffee/levels/start.coffee +++ b/coffee/levels/start.coffee @@ -25,7 +25,7 @@ module.exports = ] create: -> - world.addObjectAtPos(KikiWall(), world.decenter(0,0,-2)) - world.addObjectAtPos(KikiWall(), world.decenter(0,0,-4)) - world.addObjectAtPos(KikiWall(), world.decenter(0,0,1)) + world.addObjectAtPos('KikiWall', world.decenter(0,0,-2)) + world.addObjectAtPos('KikiWall', world.decenter(0,0,-4)) + world.addObjectAtPos('KikiWall', world.decenter(0,0,1)) \ No newline at end of file diff --git a/coffee/levels/stones.coffee b/coffee/levels/stones.coffee index 6529301..7c2803c 100644 --- a/coffee/levels/stones.coffee +++ b/coffee/levels/stones.coffee @@ -22,7 +22,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size num = 4 for i in [1..num] diff --git a/coffee/levels/switch.coffee b/coffee/levels/switch.coffee index 3f1d776..6f89b73 100644 --- a/coffee/levels/switch.coffee +++ b/coffee/levels/switch.coffee @@ -30,7 +30,7 @@ module.exports = ] create: -> - s = world.getSize() + s = world.size h = 0 # bomb and stones diff --git a/coffee/levels/towers.coffee b/coffee/levels/towers.coffee index 8ba5476..fa2def7 100644 --- a/coffee/levels/towers.coffee +++ b/coffee/levels/towers.coffee @@ -15,7 +15,7 @@ module.exports = position: [0,0,-3] ], create: -> - s = world.getSize() + s = world.size world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 0)) world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 1)) world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 2)) diff --git a/coffee/levels/walls.coffee b/coffee/levels/walls.coffee index 98181be..4c9acbd 100644 --- a/coffee/levels/walls.coffee +++ b/coffee/levels/walls.coffee @@ -23,15 +23,15 @@ module.exports = position: [0,0,0] ] create: -> - s=world.getSize() + s=world.size middlemax = (u,v,w) -> - s=world.getSize() + s=world.size d= 3.0/( (u-s.x/2.0)**2+ (v-s.y/2.0)**2 + (w-s.z/2.0)**2 + 1 ) return min(1.0 ,max(0.2,d)) middlemin = (u,v,w) -> - s=world.getSize() + s=world.size d= 2* ( (u-s.x/2.0)**2+ (v-s.y/2.0)**2 + (w-s.z/2.0)**2 )/25 return min(1.0 ,max(0.4,d)) diff --git a/coffee/lib/pos.coffee b/coffee/lib/pos.coffee index da3ebd8..b15447a 100644 --- a/coffee/lib/pos.coffee +++ b/coffee/lib/pos.coffee @@ -22,9 +22,11 @@ class Pos @y = parseInt y @z = parseInt z - vector: () -> new Vector(x, y, z) - minus: (p) -> new Pos @x-px, @y-py, @z-p.z - plus: (p) -> new Pos @x+px, @y+py, @z+p.z + vector: () -> new Vector x, y, z + minus: (p) -> new Pos @x-p.x, @y-p.y, @z-p.z + plus: (p) -> new Pos @x+p.x, @y+p.y, @z+p.z + mul: (f) -> new Pos @x*f, @y*f, @z*f + div: (d) -> new Pos @x/d, @y/d, @z/d eql: (p) -> @x==p.x and @y==p.y and @z==p.z add: (p) -> diff --git a/coffee/main.coffee b/coffee/main.coffee index b4ad327..f92e97d 100644 --- a/coffee/main.coffee +++ b/coffee/main.coffee @@ -24,66 +24,11 @@ class Kiki extends Stage @elem.style.bottom = '0' @elem.style.background = "#004" @view.appendChild @elem - - @renderer = new THREE.WebGLRenderer - antialias: true - logarithmicDepthBuffer: true - autoClear: true - - @renderer.setClearColor 0x008800 - @elem.appendChild @renderer.domElement - @renderer.setSize @view.offsetWidth, @view.offsetHeight + @world = KikiWorld.init @view - # 0000000 0000000 00 00 00000000 00000000 0000000 - # 000 000 000 000 000 000 000 000 000 000 - # 000 000000000 000000000 0000000 0000000 000000000 - # 000 000 000 000 0 000 000 000 000 000 000 - # 0000000 000 000 000 000 00000000 000 000 000 000 + @elem.appendChild @world.renderer.domElement - @fov = 60 - @near = 10 - @far = 1000 - @aspect = @view.offsetWidth / @view.offsetHeight - @dist = 20 - - @camera = new THREE.PerspectiveCamera @fov, @aspect, @near, @far - @camera.position.z = @dist - - # 0000000 0000000 00000000 000 000 00000000 - # 000 000 000 0000 000 000 - # 0000000 000 0000000 000 0 000 0000000 - # 000 000 000 000 0000 000 - # 0000000 0000000 00000000 000 000 00000000 - - @scene = new THREE.Scene() - @geom = new THREE.BoxGeometry 10, 10, 10 - - # 000 000 0000000 000 000 000000000 - # 000 000 000 000 000 000 - # 000 000 000 0000 000000000 000 - # 000 000 000 000 000 000 000 - # 0000000 000 0000000 000 000 000 - - @sun = new THREE.PointLight 0xffff00 - @sun.position.copy @camera.position - @scene.add @sun - - @ambient = new THREE.AmbientLight 0x444444 - @scene.add @ambient - - # @material = new THREE.MeshPhongMaterial - # color: 0xff0000 - # side: THREE.FrontSide - # shading: THREE.SmoothShading - # transparent: true - # opacity: 0.85 - # shininess: 0 -# - # @mesh = new THREE.Mesh @geom, @material - # @scene.add @mesh - - world = KikiWorld.init() log 'hello world' @animate() @@ -94,15 +39,7 @@ class Kiki extends Stage # 000 000 000 000 # 0000000 000 00000000 000 - animationStep: (step) => - - @quat = @camera.quaternion.clone() - @quat.multiply (new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(1,0,0), step.dsecs*0.2) - @quat.multiply (new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(0,1,0), step.dsecs*0.1) - @camera.position.set(0,0,@dist).applyQuaternion @quat - @camera.quaternion.copy @quat - @sun.position.copy @camera.position - @renderer.render @scene, @camera + animationStep: (step) => @world.step step reset: -> @elem.style.display = 'block' diff --git a/coffee/wall.coffee b/coffee/wall.coffee new file mode 100644 index 0000000..a7b2ed7 --- /dev/null +++ b/coffee/wall.coffee @@ -0,0 +1,70 @@ + +# 000 000 0000000 000 000 +# 000 0 000 000 000 000 000 +# 000000000 000000000 000 000 +# 000 000 000 000 000 000 +# 00 00 000 000 0000000 0000000 + +Item = require './item' + +class Wall extends Item + + constructor: -> + + @geom = new THREE.BoxGeometry 1,1,1 + @mat = new THREE.MeshBasicMaterial color: 0x00ff00 + @mesh = new THREE.Mesh @geom, @mat + world.scene.add @mesh + + s = 0.45 + d = 0.5 + + # glDisable(GL_LIGHTING); + # colors[KikiWall_base_color].glColor(); + # glDepthMask(false); + # kDisplaySolidCube(1.0); + # glDepthMask(true); + + # colors[KikiWall_plate_color].glColor(); + # glEnable(GL_LIGHTING); + # glBegin(GL_QUADS); +# + # glNormal3f (0.0, 0.0, 1.0); + # glVertex3f ( s, -s, d); + # glVertex3f ( s, s, d); + # glVertex3f (-s, s, d); + # glVertex3f (-s, -s, d); + + # glNormal3f (0.0, 0.0, -1.0); + # glVertex3f (-s, -s, -d); + # glVertex3f (-s, s, -d); + # glVertex3f ( s, s, -d); + # glVertex3f ( s, -s, -d); +# + # glNormal3f (0.0, 1.0, 0.0); + # glVertex3f (-s, d, -s); + # glVertex3f (-s, d, s); + # glVertex3f ( s, d, s); + # glVertex3f ( s, d, -s); + + # glNormal3f (0.0, -1.0, 0.0); + # glVertex3f ( s, -d, -s); + # glVertex3f ( s, -d, s); + # glVertex3f (-s, -d, s); + # glVertex3f (-s, -d, -s); + + # glNormal3f (1.0, 0.0, 0.0); + # glVertex3f (d, s, -s); + # glVertex3f (d, s, s); + # glVertex3f (d, -s, s); + # glVertex3f (d, -s, -s); + + # glNormal3f (-1.0, 0.0, 0.0); + # glVertex3f (-d, -s, -s); + # glVertex3f (-d, -s, s); + # glVertex3f (-d, s, s); + # glVertex3f (-d, s, -s); + + # glEnd(); + +module.exports = Wall \ No newline at end of file diff --git a/coffee/world.coffee b/coffee/world.coffee index 9fcb5c6..e91de80 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -25,7 +25,64 @@ class KikiWorld @levelList = [] @levelDict = [] - constructor: -> + constructor: (@view) -> + + @renderer = new THREE.WebGLRenderer + antialias: true + logarithmicDepthBuffer: true + autoClear: true + + @renderer.setClearColor 0x008800 + @renderer.setSize @view.offsetWidth, @view.offsetHeight + + # 0000000 0000000 00 00 00000000 00000000 0000000 + # 000 000 000 000 000 000 000 000 000 000 + # 000 000000000 000000000 0000000 0000000 000000000 + # 000 000 000 000 0 000 000 000 000 000 000 + # 0000000 000 000 000 000 00000000 000 000 000 000 + + @fov = 60 + @near = 10 + @far = 1000 + @aspect = @view.offsetWidth / @view.offsetHeight + @dist = 20 + + @camera = new THREE.PerspectiveCamera @fov, @aspect, @near, @far + @camera.position.z = @dist + + # 0000000 0000000 00000000 000 000 00000000 + # 000 000 000 0000 000 000 + # 0000000 000 0000000 000 0 000 0000000 + # 000 000 000 000 0000 000 + # 0000000 0000000 00000000 000 000 00000000 + + @scene = new THREE.Scene() + @geom = new THREE.BoxGeometry 10, 10, 10 + + # 000 000 0000000 000 000 000000000 + # 000 000 000 000 000 000 + # 000 000 000 0000 000000000 000 + # 000 000 000 000 000 000 000 + # 0000000 000 0000000 000 000 000 + + @sun = new THREE.PointLight 0xffff00 + @sun.position.copy @camera.position + @scene.add @sun + + @ambient = new THREE.AmbientLight 0x444444 + @scene.add @ambient + + # @material = new THREE.MeshPhongMaterial + # color: 0xff0000 + # side: THREE.FrontSide + # shading: THREE.SmoothShading + # transparent: true + # opacity: 0.85 + # shininess: 0 +# + # @mesh = new THREE.Mesh @geom, @material + # @scene.add @mesh + @preview = false @display_list = 0 @@ -62,7 +119,7 @@ class KikiWorld # initializeTextures () - @init: -> + @init: (view) -> return if world? global.rot0 = new KQuaternion() @@ -111,9 +168,10 @@ class KikiWorld for levelName in @levelList @levelDict[levelName] = require "./levels/#{levelName}" - log 'levelDict', @levelDict + # log 'levelDict', @levelDict - world = new KikiWorld() + world = new KikiWorld view + global.world = world world.create first @levelList world @@ -129,8 +187,8 @@ class KikiWorld if worldDict if _.isString worldDict - world.level_index = KikiWorld.levelList.indexOf worldDict - world.level_name = worldDict + @level_index = KikiWorld.levelList.indexOf worldDict + @level_name = worldDict @dict = KikiWorld.levelDict[worldDict] else @dict = worldDict @@ -138,33 +196,33 @@ class KikiWorld # ............................................................ appearance @setSize @dict["size"] - - if "scheme" in @dict - @applyColorScheme eval(@dict["scheme"]) - else - @applyColorScheme default_scheme + log "world size set", @size + # if "scheme" in @dict + # @applyColorScheme eval(@dict["scheme"]) + # else + # @applyColorScheme default_scheme - if "border" in @dict - border = @dict["border"] - else - border = 1 + # if "border" in @dict + # border = @dict["border"] + # else + # border = 1 - @setDisplayBorder border + # @setDisplayBorder border # ............................................................ intro text - if "intro" in @dict - if not @preview - intro_text = KikiScreenText() - intro_text.addText @dict["intro"] - intro_text.show() - @setName @dict["intro"] - else - @setName "noname" + # if "intro" in @dict + # if not @preview + # intro_text = KikiScreenText() + # intro_text.addText @dict["intro"] + # intro_text.show() + # @setName @dict["intro"] + # else + # @setName "noname" - if @preview - @getProjection().setViewport(0.0, 0.4, 1.0, 0.6) - else - @getProjection().setViewport(0.0, 0.0, 1.0, 1.0) + # if @preview + # @getProjection().setViewport(0.0, 0.4, 1.0, 0.6) + # else + # @getProjection().setViewport(0.0, 0.0, 1.0, 1.0) # ............................................................ escape # escape_event = Controller.getEventWithName ("escape") @@ -173,70 +231,72 @@ class KikiWorld # ............................................................ exits - if "exits" in @dict + if @dict.exits? and false + log "exits" exit_id = 0 - for entry in @dict["exits"] - exit_gate = KikiGate (entry["active"]) + for entry in @dict.exits + exit_gate = new KikiGate entry["active"] if "name" in entry name = entry["name"] else name = "exit "+str(exit_id) - exit_gate.setName(name) + exit_gate.setName name - exit_action = once ("exit " + str(exit_id)) - delay_action = once (lambda a = exit_action: Controller.timer_event.addAction (a)) - exit_gate.getEventWithName ("enter").addAction (delay_action) - if "position" in entry - pos = @decenter (entry["position"]) + exit_action = once "exit " + str(exit_id) + delay_action = once (a=exit_action) -> Controller.timer_event.addAction(a) + # exit_gate.getEventWithName("enter").addAction(delay_action) + if entry.position? + pos = @decenter entry.position else if "coordinates" in entry - pos = new Pos entry["coordinates"] + pos = new Pos entry.coordinates @addObjectAtPos exit_gate, pos exit_id += 1 # ............................................................ creation - if "create" in @dict - if _.isFunction @dict["create"] - @dict["create"]() - else - exec @dict["create"] in globals() + if @dict.create? + log "create" + if _.isFunction @dict.create + @dict.create() + # else + # exec @dict["create"] in globals() # ............................................................ player - player = Controller.player - - player_dict = @dict["player"] - - if "orientation" in player_dict - player.setOrientation (player_dict["orientation"]) - else - player.setOrientation (roty90) - - if "position" in player_dict - @addObjectAtPos player, @decenter(player_dict["position"]) - else if "coordinates" in player_dict - pos = player_dict["coordinates"] - @addObjectAtPos player, Pos(pos[0], pos[1], pos[2]) + # player = Controller.player +# + # player_dict = @dict["player"] +# + # if "orientation" in player_dict + # player.setOrientation (player_dict["orientation"]) + # else + # player.setOrientation (roty90) +# + # if "position" in player_dict + # @addObjectAtPos player, @decenter(player_dict["position"]) + # else if "coordinates" in player_dict + # pos = player_dict["coordinates"] + # @addObjectAtPos player, Pos(pos[0], pos[1], pos[2]) - if "nostatus" in player_dict - if player_dict["nostatus"] or @preview - Controller.player_status.hide() - else - Controller.player_status.show() - else - if @preview - Controller.player_status.hide() - else - Controller.player_status.show() - - @getProjection().setPosition(KVector()) + # if "nostatus" in player_dict + # if player_dict["nostatus"] or @preview + # Controller.player_status.hide() + # else + # Controller.player_status.show() + # else + # if @preview + # Controller.player_status.hide() + # else + # Controller.player_status.show() +# + # @getProjection().setPosition(KVector()) - Controller.player.getStatus().setMinMoves (highscore.levelParMoves (@level_name)) - Controller.player.getStatus().setMoves (0) + # Controller.player.getStatus().setMinMoves (highscore.levelParMoves (@level_name)) + # Controller.player.getStatus().setMoves (0) # ............................................................ init - @init() # tell the world that we are finished + # @init() # tell the world that we are finished restart: (self) -> # restores the player status and restarts the current level @@ -290,15 +350,11 @@ class KikiWorld else if object.getClassName() == "KikiGate" kikiObjectToGate(object).setActive(1) - decenter: () -> - s = @getSize() - if len(args) == 3 - [x, y, z] = args - else if len(args) == 1 - [x, y, z] = args[0] - - new Pos x+s.x/2, y+s.y/2, z+s.z/2 - + decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2 + + isValidPos: (pos) -> pos.x >= 0 and pos.x < @size.x and pos.y >= 0 and pos.y < @size.y and pos.z >= 0 and pos.z < @size.z + isInvalidPos: (pos) -> not @isValidPos pos + addObjectLine: (object, start, end) -> # adds a line of objects of type to the world. start and end should be 3-tuples or Pos objects if start instanceof Pos @@ -337,12 +393,11 @@ class KikiWorld setObjectRandom: (object) -> # adds number objects of type at random positions to the world - size = @getSize() object_set = 0 while not object_set # hack alert! - random_pos = Pos random.randrange(size.x), - random.randrange(size.y), - random.randrange(size.z) + random_pos = Pos random.randrange(@size.x), + random.randrange(@size.y), + random.randrange(@size.z) if not object.isSpaceEgoistic() or @isUnoccupiedPos(random_pos) @addObjectAtPos object, random_pos object_set = 1 @@ -428,23 +483,25 @@ class KikiWorld menu.addItem(Controller.getLocalizedString("about"), once(display_about)) menu.addItem(Controller.getLocalizedString("quit"), once(Controller.quit)) - setSize: (x, y, z) -> + setSize: (size) -> @deleteAllObjects() @deleteDisplayList() @cells = [] - @size.x = x - @size.y = y - @size.z = z + @size = new Pos size - @cells.resize x*y*z, 0 - - # .......................................... calcuate max distance (for position relative sound) - @max_distance = Math.Max(x, Math.Max(y, z)) # ............................. heuristic of a heuristic :-) + # calcuate max distance (for position relative sound) + @max_distance = Math.max(@size.x, Math.max(@size.y, @size.z)) # heuristic of a heuristic :-) getCellAtPos: (pos) -> return @cells[@posToIndex(pos)] if @isValidPos pos getBotAtPos: (pos) -> @getObjectOfTypeAtPos KikiBot, pos + posToIndex: (pos) -> pos.x * @size.z * @size.y + pos.y * @size.z + pos.z + indexToPos: (index) -> + lsize = @size.z * @size.y + lrest = index % lsize + new Pos index/lsize, lrest/@size.z, lrest%@size.z + getObjectsOfType: (clss) -> @objects.filter (o) -> o instanceof clss getObjectsOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getObjectsOfType clss getObjectOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getRealObjectOfType clss @@ -491,13 +548,22 @@ class KikiWorld # delete cell @cells[posToIndex(pos)] = null + newObject: (object) -> + log "newObject:", object + if _.isString object + if object.startsWith 'Kiki' + return new (require "./#{object.slice(4).toLowerCase()}")() + object + addObject: (object) -> + object = @newObject object if object instanceof KikiLight lights.push object # if lights.indexOf(object) < 0 else objects.push object # if objects.indexOf(object) < 0 addObjectAtPos: (object, pos) -> + object = @newObject object @setObjectAtPos object, pos @addObject object @@ -683,6 +749,20 @@ class KikiWorld @colors[1] = color # Controller.world.deleteDisplayList () - + + # 0000000 000000000 00000000 00000000 + # 000 000 000 000 000 + # 0000000 000 0000000 00000000 + # 000 000 000 000 + # 0000000 000 00000000 000 + + step: (step) -> + quat = @camera.quaternion.clone() + quat.multiply (new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(1,0,0), step.dsecs*0.2) + quat.multiply (new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(0,1,0), step.dsecs*0.1) + @camera.position.set(0,0,@dist).applyQuaternion quat + @camera.quaternion.copy quat + @sun.position.copy @camera.position + @renderer.render @scene, @camera module.exports = KikiWorld