This commit is contained in:
monsterkodi 2016-08-09 02:39:12 +02:00
parent c5e105e9ee
commit 66253c51e1
43 changed files with 308 additions and 207 deletions

12
coffee/item.coffee Normal file
View File

@ -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

View File

@ -30,7 +30,7 @@ module.exports =
] ]
create: -> 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 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 world.addObjectAtPos KikiMotorCylinder(KikiFace.NY), KikiPos s.x/2-1, s.y-2, s.z/2

View File

@ -24,7 +24,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
d = 2 d = 2
world.addObjectAtPos(KikiMotorCylinder(KikiFace.PY), KikiPos(s.x/2, 1, s.z/2)) world.addObjectAtPos(KikiMotorCylinder(KikiFace.PY), KikiPos(s.x/2, 1, s.z/2))

View File

@ -20,7 +20,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
for i in [-2, 2] 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)]) world.addObjectPoly(KikiStone, [world.decenter(1, 1, i), world.decenter(1, -1, i), world.decenter(-1, -1, i), world.decenter(-1, 1, i)])

View File

@ -24,7 +24,7 @@ module.exports =
position: [0,-1,0] position: [0,-1,0]
], ],
create: -> create: ->
s = world.getSize() s = world.size
d = s.z/2 d = s.z/2
world.addObjectAtPos(KikiWall(), KikiPos(0, 0, d)) world.addObjectAtPos(KikiWall(), KikiPos(0, 0, d))

View File

@ -28,7 +28,7 @@ module.exports =
position: [-1,0,0] position: [-1,0,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
h = 0 h = 0
# bomb and stones # bomb and stones
for i in [1, 2] for i in [1, 2]

View File

@ -23,7 +23,7 @@ module.exports =
position: [0,-1,0] position: [0,-1,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
world.addObjectLine("KikiWireStone()", KikiPos(0, 0, 0), KikiPos(0, s.y-2, 0)) 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)) world.addObjectLine("KikiWireStone()", KikiPos(s.x-1, 0, 0), KikiPos(s.x-1, s.y-2, 0))

View File

@ -23,7 +23,7 @@ module.exports =
coordinates: [8,8,8] coordinates: [8,8,8]
] ]
create: -> create: ->
s=world.getSize() s=world.size
mx=s.x/2 mx=s.x/2
my=s.y/2 my=s.y/2
mz=s.z/2 mz=s.z/2

View File

@ -19,7 +19,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
for y in range(-s.y/2+1, s.y/2+1) 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) for x in range(-s.x/2+1, s.x/2+1, 2)

View File

@ -16,7 +16,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
] ]
create: -> 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,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] for i in [0...3]

View File

@ -23,7 +23,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
], ],
create: -> create: ->
s = world.getSize() s = world.size
d = 2 d = 2
world.addObjectLine(KikiWireStone, world.decenter(-d, s.y/2, 0), world.decenter(-d, 0, 0)) world.addObjectLine(KikiWireStone, world.decenter(-d, s.y/2, 0), world.decenter(-d, 0, 0))

View File

@ -26,7 +26,7 @@ module.exports =
] ]
create: -> 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(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)) world.addObjectAtPos(KikiMotorCylinder(KikiFace.NY), KikiPos(s.x/2-3, s.y-2, s.z/2))

View File

@ -20,7 +20,7 @@ module.exports =
], ],
create: -> 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, [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.addObjectLine(KikiWall, [s.x/2, s.y/2, 0], [s.x/2, s.y/2, s.z])

View File

@ -21,7 +21,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
] ]
create: -> create: ->
s=world.getSize() s=world.size
d=2 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,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] for i in [0...s.x]

View File

@ -27,7 +27,7 @@ module.exports =
] ]
create: -> create: ->
# #
s = world.getSize() s = world.size
exit_switch = KikiSwitch() exit_switch = KikiSwitch()
exit_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit"))) exit_switch.getEventWithName("switched").addAction(continuous(() -> world.toggle("exit")))

View File

@ -31,7 +31,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
#hop back on #hop back on
world.addObjectAtPos(KikiWall(), KikiPos(2, 12, 12)) world.addObjectAtPos(KikiWall(), KikiPos(2, 12, 12))

View File

@ -23,7 +23,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
for m in [[1,KikiWall], [2,KikiStone]] for m in [[1,KikiWall], [2,KikiStone]]
for k in [-1*m[0],1*m[0]] for k in [-1*m[0],1*m[0]]
for l in [-1*m[0],1*m[0]] for l in [-1*m[0],1*m[0]]

View File

@ -23,7 +23,7 @@ module.exports =
coordinates: [2,7,4] #absolute coord coordinates: [2,7,4] #absolute coord
] ]
create: -> create: ->
s = world.getSize() s = world.size
world.switch_countera = 0 world.switch_countera = 0
world.switch_counter = 0 world.switch_counter = 0

View File

@ -22,7 +22,7 @@ module.exports =
position: [0,4,0] position: [0,4,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
world.addObjectAtPos(KikiWireStone(), world.decenter(-1, 0, 0)) world.addObjectAtPos(KikiWireStone(), world.decenter(-1, 0, 0))
world.addObjectAtPos(KikiWireStone(), world.decenter( 1, 0, 0)) world.addObjectAtPos(KikiWireStone(), world.decenter( 1, 0, 0))

View File

@ -17,7 +17,7 @@ module.exports =
position: [0,4,0] position: [0,4,0]
] ]
create: -> create: ->
s = world.getSize() s = world.size
for y in range(-s.y/2+3, s.y/2, 2) 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 x in range(-s.x/2+1, s.x/2+1)
for z in range(-s.z/2+1, s.z/2+1) for z in range(-s.z/2+1, s.z/2+1)

View File

@ -20,7 +20,7 @@ module.exports =
] ]
create: -> 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))
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))

View File

@ -17,7 +17,7 @@ module.exports =
] ]
create: -> create: ->
# #
s = world.getSize() s = world.size
for y in [-1, 1] for y in [-1, 1]
for x in range(-s.x/2+3, s.x/2-1, 2) for x in range(-s.x/2+3, s.x/2-1, 2)

View File

@ -21,7 +21,7 @@ module.exports =
position: [0,0,0] position: [0,0,0]
], ],
create: -> create: ->
s = world.getSize() s = world.size
world.addObjectAtPos(KikiStone(), KikiPos(0,0,1)) world.addObjectAtPos(KikiStone(), KikiPos(0,0,1))
world.addObjectAtPos(KikiStone(), KikiPos(0,1,0)) world.addObjectAtPos(KikiStone(), KikiPos(0,1,0))

View File

@ -24,7 +24,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
switched = (swtch) -> switched = (swtch) ->
world.switch_counter += swtch.isActive() and 1 or -1 world.switch_counter += swtch.isActive() and 1 or -1

View File

@ -20,7 +20,7 @@ module.exports =
] ]
create: -> 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,1 - s.z/2))
world.addObjectAtPos(KikiWall(), world.decenter(0,0,3 - s.z/2)) world.addObjectAtPos(KikiWall(), world.decenter(0,0,3 - s.z/2))

View File

@ -15,7 +15,7 @@ module.exports =
coordinates: [1,2,8] coordinates: [1,2,8]
] ]
create: -> create: ->
s = world.getSize() s = world.size
world.addObjectAtPos(KikiMotorGear(KikiFace.X), KikiPos(0,2,4)) world.addObjectAtPos(KikiMotorGear(KikiFace.X), KikiPos(0,2,4))
world.addObjectAtPos(KikiWall(), KikiPos(0,2,3)) world.addObjectAtPos(KikiWall(), KikiPos(0,2,3))
world.addObjectAtPos(KikiWall(), KikiPos(0,2,5)) world.addObjectAtPos(KikiWall(), KikiPos(0,2,5))

View File

@ -15,15 +15,15 @@ module.exports =
] ]
create: -> create: ->
s=world.getSize() s=world.size
middlemax = (u,v,w) -> 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 ) 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)) return min(1.0 ,max(0.2,d))
middlemin = (u,v,w) -> 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 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)) return min(1.0 ,max(0.4,d))

View File

@ -22,7 +22,7 @@ module.exports =
] ]
create: -> 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))
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))

View File

@ -23,7 +23,7 @@ module.exports =
] ]
create: -> create: ->
# #
s = world.getSize() s = world.size
world.addObjectLine(KikiWall, [2, 2, 2], [s.x - 3, 2, 2]) 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]) world.addObjectLine(KikiWall, [s.x - 3, 2, 2], [s.x - 3, s.y - 3, 2])

View File

@ -31,7 +31,7 @@ module.exports =
KikiPos(p[0],p[1]-s,p[2]-s), KikiPos(p[0],p[1]-s,p[2]-s),
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,1), KikiPos(9,9,9))
world.addObjectLine(KikiWall, KikiPos(1,1,9), KikiPos(9,9,1)) world.addObjectLine(KikiWall, KikiPos(1,1,9), KikiPos(9,9,1))
world.addObjectLine(KikiWall, KikiPos(1,9,1), KikiPos(9,1,9)) world.addObjectLine(KikiWall, KikiPos(1,9,1), KikiPos(9,1,9))

View File

@ -16,7 +16,7 @@ module.exports =
position: [0,0,-1] position: [0,0,-1]
] ]
create: -> create: ->
s=world.getSize() s=world.size
d=1 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,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] for i in [0...s.x]

View File

@ -17,7 +17,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
for y in [-1, 1] for y in [-1, 1]
x = 3 x = 3

View File

@ -21,7 +21,7 @@ module.exports =
position: [0,0,4] position: [0,0,4]
] ]
create: -> create: ->
s=world.getSize() s=world.size
for b in [1..3] 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,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] for k in [b+1..s.x-b]

View File

@ -16,7 +16,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
for y in [ -7, -3, 1, 5] for y in [ -7, -3, 1, 5]
x = 1 x = 1

View File

@ -25,7 +25,7 @@ module.exports =
] ]
create: -> create: ->
world.addObjectAtPos(KikiWall(), world.decenter(0,0,-2)) world.addObjectAtPos('KikiWall', world.decenter(0,0,-2))
world.addObjectAtPos(KikiWall(), world.decenter(0,0,-4)) world.addObjectAtPos('KikiWall', world.decenter(0,0,-4))
world.addObjectAtPos(KikiWall(), world.decenter(0,0,1)) world.addObjectAtPos('KikiWall', world.decenter(0,0,1))

View File

@ -22,7 +22,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
num = 4 num = 4
for i in [1..num] for i in [1..num]

View File

@ -30,7 +30,7 @@ module.exports =
] ]
create: -> create: ->
s = world.getSize() s = world.size
h = 0 h = 0
# bomb and stones # bomb and stones

View File

@ -15,7 +15,7 @@ module.exports =
position: [0,0,-3] position: [0,0,-3]
], ],
create: -> 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))
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, 1))
world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 2)) world.addObjectAtPos(KikiStone(), KikiPos(s.x/2-1, s.y/2+1, 2))

View File

@ -23,15 +23,15 @@ module.exports =
position: [0,0,0] position: [0,0,0]
] ]
create: -> create: ->
s=world.getSize() s=world.size
middlemax = (u,v,w) -> 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 ) 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)) return min(1.0 ,max(0.2,d))
middlemin = (u,v,w) -> 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 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)) return min(1.0 ,max(0.4,d))

View File

@ -22,9 +22,11 @@ class Pos
@y = parseInt y @y = parseInt y
@z = parseInt z @z = parseInt z
vector: () -> new Vector(x, y, z) vector: () -> new Vector x, y, z
minus: (p) -> new Pos @x-px, @y-py, @z-p.z minus: (p) -> new Pos @x-p.x, @y-p.y, @z-p.z
plus: (p) -> new Pos @x+px, @y+py, @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 eql: (p) -> @x==p.x and @y==p.y and @z==p.z
add: (p) -> add: (p) ->

View File

@ -25,65 +25,10 @@ class Kiki extends Stage
@elem.style.background = "#004" @elem.style.background = "#004"
@view.appendChild @elem @view.appendChild @elem
@renderer = new THREE.WebGLRenderer @world = KikiWorld.init @view
antialias: true
logarithmicDepthBuffer: true
autoClear: true
@renderer.setClearColor 0x008800 @elem.appendChild @world.renderer.domElement
@elem.appendChild @renderer.domElement
@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
world = KikiWorld.init()
log 'hello world' log 'hello world'
@animate() @animate()
@ -94,15 +39,7 @@ class Kiki extends Stage
# 000 000 000 000 # 000 000 000 000
# 0000000 000 00000000 000 # 0000000 000 00000000 000
animationStep: (step) => animationStep: (step) => @world.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
reset: -> reset: ->
@elem.style.display = 'block' @elem.style.display = 'block'

70
coffee/wall.coffee Normal file
View File

@ -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

View File

@ -25,7 +25,64 @@ class KikiWorld
@levelList = [] @levelList = []
@levelDict = [] @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 @preview = false
@display_list = 0 @display_list = 0
@ -62,7 +119,7 @@ class KikiWorld
# initializeTextures () # initializeTextures ()
@init: -> @init: (view) ->
return if world? return if world?
global.rot0 = new KQuaternion() global.rot0 = new KQuaternion()
@ -111,9 +168,10 @@ class KikiWorld
for levelName in @levelList for levelName in @levelList
@levelDict[levelName] = require "./levels/#{levelName}" @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.create first @levelList
world world
@ -129,8 +187,8 @@ class KikiWorld
if worldDict if worldDict
if _.isString worldDict if _.isString worldDict
world.level_index = KikiWorld.levelList.indexOf worldDict @level_index = KikiWorld.levelList.indexOf worldDict
world.level_name = worldDict @level_name = worldDict
@dict = KikiWorld.levelDict[worldDict] @dict = KikiWorld.levelDict[worldDict]
else else
@dict = worldDict @dict = worldDict
@ -138,33 +196,33 @@ class KikiWorld
# ............................................................ appearance # ............................................................ appearance
@setSize @dict["size"] @setSize @dict["size"]
log "world size set", @size
# if "scheme" in @dict
# @applyColorScheme eval(@dict["scheme"])
# else
# @applyColorScheme default_scheme
if "scheme" in @dict # if "border" in @dict
@applyColorScheme eval(@dict["scheme"]) # border = @dict["border"]
else # else
@applyColorScheme default_scheme # border = 1
if "border" in @dict # @setDisplayBorder border
border = @dict["border"]
else
border = 1
@setDisplayBorder border
# ............................................................ intro text # ............................................................ intro text
if "intro" in @dict # if "intro" in @dict
if not @preview # if not @preview
intro_text = KikiScreenText() # intro_text = KikiScreenText()
intro_text.addText @dict["intro"] # intro_text.addText @dict["intro"]
intro_text.show() # intro_text.show()
@setName @dict["intro"] # @setName @dict["intro"]
else # else
@setName "noname" # @setName "noname"
if @preview # if @preview
@getProjection().setViewport(0.0, 0.4, 1.0, 0.6) # @getProjection().setViewport(0.0, 0.4, 1.0, 0.6)
else # else
@getProjection().setViewport(0.0, 0.0, 1.0, 1.0) # @getProjection().setViewport(0.0, 0.0, 1.0, 1.0)
# ............................................................ escape # ............................................................ escape
# escape_event = Controller.getEventWithName ("escape") # escape_event = Controller.getEventWithName ("escape")
@ -173,70 +231,72 @@ class KikiWorld
# ............................................................ exits # ............................................................ exits
if "exits" in @dict if @dict.exits? and false
log "exits"
exit_id = 0 exit_id = 0
for entry in @dict["exits"] for entry in @dict.exits
exit_gate = KikiGate (entry["active"]) exit_gate = new KikiGate entry["active"]
if "name" in entry if "name" in entry
name = entry["name"] name = entry["name"]
else else
name = "exit "+str(exit_id) name = "exit "+str(exit_id)
exit_gate.setName(name) exit_gate.setName name
exit_action = once ("exit " + str(exit_id)) exit_action = once "exit " + str(exit_id)
delay_action = once (lambda a = exit_action: Controller.timer_event.addAction (a)) delay_action = once (a=exit_action) -> Controller.timer_event.addAction(a)
exit_gate.getEventWithName ("enter").addAction (delay_action) # exit_gate.getEventWithName("enter").addAction(delay_action)
if "position" in entry if entry.position?
pos = @decenter (entry["position"]) pos = @decenter entry.position
else if "coordinates" in entry else if "coordinates" in entry
pos = new Pos entry["coordinates"] pos = new Pos entry.coordinates
@addObjectAtPos exit_gate, pos @addObjectAtPos exit_gate, pos
exit_id += 1 exit_id += 1
# ............................................................ creation # ............................................................ creation
if "create" in @dict if @dict.create?
if _.isFunction @dict["create"] log "create"
@dict["create"]() if _.isFunction @dict.create
else @dict.create()
exec @dict["create"] in globals() # else
# exec @dict["create"] in globals()
# ............................................................ player # ............................................................ player
player = Controller.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_dict = @dict["player"] # 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 "orientation" in player_dict # Controller.player.getStatus().setMinMoves (highscore.levelParMoves (@level_name))
player.setOrientation (player_dict["orientation"]) # Controller.player.getStatus().setMoves (0)
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())
Controller.player.getStatus().setMinMoves (highscore.levelParMoves (@level_name))
Controller.player.getStatus().setMoves (0)
# ............................................................ init # ............................................................ init
@init() # tell the world that we are finished # @init() # tell the world that we are finished
restart: (self) -> restart: (self) ->
# restores the player status and restarts the current level # restores the player status and restarts the current level
@ -290,14 +350,10 @@ class KikiWorld
else if object.getClassName() == "KikiGate" else if object.getClassName() == "KikiGate"
kikiObjectToGate(object).setActive(1) kikiObjectToGate(object).setActive(1)
decenter: () -> decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2
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 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) -> addObjectLine: (object, start, end) ->
# adds a line of objects of type to the world. start and end should be 3-tuples or Pos objects # adds a line of objects of type to the world. start and end should be 3-tuples or Pos objects
@ -337,12 +393,11 @@ class KikiWorld
setObjectRandom: (object) -> setObjectRandom: (object) ->
# adds number objects of type at random positions to the world # adds number objects of type at random positions to the world
size = @getSize()
object_set = 0 object_set = 0
while not object_set # hack alert! while not object_set # hack alert!
random_pos = Pos random.randrange(size.x), random_pos = Pos random.randrange(@size.x),
random.randrange(size.y), random.randrange(@size.y),
random.randrange(size.z) random.randrange(@size.z)
if not object.isSpaceEgoistic() or @isUnoccupiedPos(random_pos) if not object.isSpaceEgoistic() or @isUnoccupiedPos(random_pos)
@addObjectAtPos object, random_pos @addObjectAtPos object, random_pos
object_set = 1 object_set = 1
@ -428,23 +483,25 @@ class KikiWorld
menu.addItem(Controller.getLocalizedString("about"), once(display_about)) menu.addItem(Controller.getLocalizedString("about"), once(display_about))
menu.addItem(Controller.getLocalizedString("quit"), once(Controller.quit)) menu.addItem(Controller.getLocalizedString("quit"), once(Controller.quit))
setSize: (x, y, z) -> setSize: (size) ->
@deleteAllObjects() @deleteAllObjects()
@deleteDisplayList() @deleteDisplayList()
@cells = [] @cells = []
@size.x = x @size = new Pos size
@size.y = y
@size.z = z
@cells.resize x*y*z, 0 # calcuate max distance (for position relative sound)
@max_distance = Math.max(@size.x, Math.max(@size.y, @size.z)) # heuristic of a heuristic :-)
# .......................................... calcuate max distance (for position relative sound)
@max_distance = Math.Max(x, Math.Max(y, z)) # ............................. heuristic of a heuristic :-)
getCellAtPos: (pos) -> return @cells[@posToIndex(pos)] if @isValidPos pos getCellAtPos: (pos) -> return @cells[@posToIndex(pos)] if @isValidPos pos
getBotAtPos: (pos) -> @getObjectOfTypeAtPos KikiBot, 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 getObjectsOfType: (clss) -> @objects.filter (o) -> o instanceof clss
getObjectsOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getObjectsOfType clss getObjectsOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getObjectsOfType clss
getObjectOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getRealObjectOfType clss getObjectOfTypeAtPos: (clss, pos) -> @getCellAtPos(pos)?.getRealObjectOfType clss
@ -491,13 +548,22 @@ class KikiWorld
# delete cell # delete cell
@cells[posToIndex(pos)] = null @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) -> addObject: (object) ->
object = @newObject object
if object instanceof KikiLight if object instanceof KikiLight
lights.push object # if lights.indexOf(object) < 0 lights.push object # if lights.indexOf(object) < 0
else else
objects.push object # if objects.indexOf(object) < 0 objects.push object # if objects.indexOf(object) < 0
addObjectAtPos: (object, pos) -> addObjectAtPos: (object, pos) ->
object = @newObject object
@setObjectAtPos object, pos @setObjectAtPos object, pos
@addObject object @addObject object
@ -684,5 +750,19 @@ class KikiWorld
# Controller.world.deleteDisplayList () # 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 module.exports = KikiWorld