item
This commit is contained in:
parent
c5e105e9ee
commit
66253c51e1
12
coffee/item.coffee
Normal file
12
coffee/item.coffee
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)])
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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")))
|
||||
|
|
|
@ -31,7 +31,7 @@ module.exports =
|
|||
]
|
||||
create: ->
|
||||
|
||||
s = world.getSize()
|
||||
s = world.size
|
||||
|
||||
#hop back on
|
||||
world.addObjectAtPos(KikiWall(), KikiPos(2, 12, 12))
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -24,7 +24,7 @@ module.exports =
|
|||
]
|
||||
create: ->
|
||||
|
||||
s = world.getSize()
|
||||
s = world.size
|
||||
|
||||
switched = (swtch) ->
|
||||
world.switch_counter += swtch.isActive() and 1 or -1
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports =
|
|||
]
|
||||
create: ->
|
||||
|
||||
s = world.getSize()
|
||||
s = world.size
|
||||
|
||||
for y in [-1, 1]
|
||||
x = 3
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -16,7 +16,7 @@ module.exports =
|
|||
]
|
||||
create: ->
|
||||
|
||||
s = world.getSize()
|
||||
s = world.size
|
||||
|
||||
for y in [ -7, -3, 1, 5]
|
||||
x = 1
|
||||
|
|
|
@ -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))
|
||||
|
|
@ -22,7 +22,7 @@ module.exports =
|
|||
]
|
||||
create: ->
|
||||
|
||||
s = world.getSize()
|
||||
s = world.size
|
||||
|
||||
num = 4
|
||||
for i in [1..num]
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports =
|
|||
]
|
||||
create: ->
|
||||
|
||||
s = world.getSize()
|
||||
s = world.size
|
||||
h = 0
|
||||
# bomb and stones
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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) ->
|
||||
|
|
|
@ -25,65 +25,10 @@ class Kiki extends Stage
|
|||
@elem.style.background = "#004"
|
||||
@view.appendChild @elem
|
||||
|
||||
@renderer = new THREE.WebGLRenderer
|
||||
antialias: true
|
||||
logarithmicDepthBuffer: true
|
||||
autoClear: true
|
||||
@world = KikiWorld.init @view
|
||||
|
||||
@renderer.setClearColor 0x008800
|
||||
@elem.appendChild @renderer.domElement
|
||||
@renderer.setSize @view.offsetWidth, @view.offsetHeight
|
||||
@elem.appendChild @world.renderer.domElement
|
||||
|
||||
|
||||
# 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'
|
||||
|
||||
@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'
|
||||
|
|
70
coffee/wall.coffee
Normal file
70
coffee/wall.coffee
Normal 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
|
|
@ -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"]
|
||||
log "world size set", @size
|
||||
# if "scheme" in @dict
|
||||
# @applyColorScheme eval(@dict["scheme"])
|
||||
# else
|
||||
# @applyColorScheme default_scheme
|
||||
|
||||
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 = 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
|
||||
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())
|
||||
|
||||
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,14 +350,10 @@ 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]
|
||||
decenter: (x,y,z) -> new Pos(x,y,z).plus @size.div 2
|
||||
|
||||
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) ->
|
||||
# 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) ->
|
||||
# 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
|
||||
|
||||
|
@ -684,5 +750,19 @@ class KikiWorld
|
|||
|
||||
# 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user