summaryrefslogtreecommitdiff
path: root/assets/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts')
-rw-r--r--assets/javascripts/app.js10
-rw-r--r--assets/javascripts/mx/extensions/mx.movements.js14
-rw-r--r--assets/javascripts/rectangles/_env.js41
-rw-r--r--assets/javascripts/rectangles/engine/builder.js10
-rw-r--r--assets/javascripts/rectangles/engine/clipper.js2
-rw-r--r--assets/javascripts/rectangles/engine/mover.js31
-rw-r--r--assets/javascripts/rectangles/map/draw.js2
-rw-r--r--assets/javascripts/rectangles/util/keys.js9
8 files changed, 86 insertions, 33 deletions
diff --git a/assets/javascripts/app.js b/assets/javascripts/app.js
index b6c484c..b142a02 100644
--- a/assets/javascripts/app.js
+++ b/assets/javascripts/app.js
@@ -42,6 +42,8 @@ app.init = function () {
cam = scene.camera
cam.y = viewHeight
+
+ app.tube = new Tube ()
if (MX.Map) map = app.map = new MX.Map()
@@ -70,6 +72,14 @@ app.init = function () {
loader.ready()
}
+app.on = function(){
+ app.tube.on.apply(app.tube, arguments)
+}
+
+app.off = function(){
+ app.tube.off.apply(app.tube, arguments)
+}
+
app.position = function(obj){
return {
x: obj.x,
diff --git a/assets/javascripts/mx/extensions/mx.movements.js b/assets/javascripts/mx/extensions/mx.movements.js
index 2f76e8c..6837637 100644
--- a/assets/javascripts/mx/extensions/mx.movements.js
+++ b/assets/javascripts/mx/extensions/mx.movements.js
@@ -17,11 +17,11 @@ MX.Movements = function (cam, viewHeight) {
locked = false,
gravity = false
- var v = 20,
+ var v = 15,
vr = Math.PI * 0.015
- jumpV = 30,
+ jumpV = 23,
vx = vy = vz = 0,
- creepFactor = 0.1
+ creepFactor = 0.3
var DEFAULT_SCALE = scale = 1.0
@@ -77,9 +77,7 @@ MX.Movements = function (cam, viewHeight) {
case 32: // space
if (gravity) {
jumping = true
-
vy = abs(vy) + jumpV * scale
-
if (e.shiftKey) {
vy *= -1
}
@@ -240,6 +238,9 @@ MX.Movements = function (cam, viewHeight) {
cam.y += vy
cam.z += vz
+ if (vx || vz) {
+ app.tube("move", cam)
+ }
}
if (gravity) {
@@ -260,5 +261,8 @@ MX.Movements = function (cam, viewHeight) {
unlock: function(){ locked = false },
scale: function(n){ if (n) scale = n; return scale },
resetScale: function(n){ scale = DEFAULT_SCALE },
+ gravity: function(g){ gravity = g },
+ velocity: function(n){ v = clamp(n, 1, 50) },
+ jumpVelocity: function(n){ jumpV = clamp(n, 1, 50) },
}
}
diff --git a/assets/javascripts/rectangles/_env.js b/assets/javascripts/rectangles/_env.js
index 818cb55..be3d931 100644
--- a/assets/javascripts/rectangles/_env.js
+++ b/assets/javascripts/rectangles/_env.js
@@ -2,50 +2,43 @@
var environment = new function(){}
environment.init = function(){
window.scene && scene.camera.move({
- "x": 500,
+ "x": 1000,
"y": 1500,
- "z": 200,
- "rotationX": PI/2,
- "rotationY": PI
+ "z": 250,
+ "rotationX": 0, // PI/2,
+ "rotationY": PI/2, // PI
})
// map.center.a = scene.camera.x
// map.center.b = scene.camera.z
- map.center.a = 100
- map.center.b = 100
+ map.center.a = 0
+ map.center.b = 0
clipper.rooms.push( new room ({
- rect: new rect(-100,-100, 100,100),
- height: 400,
+ rect: new rect(0,0, 500,500),
+ height: 500,
}))
clipper.rooms.push( new room ({
- rect: new rect(100,100, 200,300),
- height: 400,
+ rect: new rect(600,0, 1100,500),
+ height: 500,
}))
clipper.rooms.push( new room ({
- rect: new rect(200,300, 300,500),
- height: 400,
- }))
- clipper.rooms.push( new room ({
- rect: new rect(300,100, 600,300),
- height: 400,
- }))
- clipper.rooms.push( new room ({
- rect: new rect(400,200, 700,400),
- height: 400,
+ rect: new rect(450,150, 650,350),
+ height: 300,
}))
+ app.movements.gravity(true)
- builder.init()
-
if (window.location.href.match(/stone/)) {
- builder.tube.on("clip", function(){
+ app.on("clip", function(){
$(".face").css({
"background-image": "url(http://i.asdf.us/im/4a/_1398144847_frankhats.gif)"
})
})
$("#map").hide()
}
-
+
+ builder.init()
+ mover.init()
clipper.init()
window.scene && scene.update()
environment.update()
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js
index 2b8734a..8e1508a 100644
--- a/assets/javascripts/rectangles/engine/builder.js
+++ b/assets/javascripts/rectangles/engine/builder.js
@@ -1,6 +1,5 @@
var builder = new function(){
var base = this
- base.tube = new Tube ()
var els = []
@@ -9,7 +8,7 @@ var builder = new function(){
}
base.bind = function(){
- base.tube.on("clip", rebuild)
+ app.on("clip", rebuild)
}
function rebuild(){
@@ -20,6 +19,10 @@ var builder = new function(){
}
function build (){
clipper.rooms = sort_rooms_by_id(clipper.rooms)
+ clipper.rooms.forEach(function(r){
+ r.walls = []
+ r.floors = []
+ })
clipper.regions.forEach(function(r){
walls(r).forEach(function(el){
els.push(el)
@@ -203,6 +206,9 @@ var builder = new function(){
el.z = r.y.a + depth/2
el.rotationX = PI/2
el.el.style.backgroundColor = "#f00"
+
+ rm.floors.push(el)
+
return el
}
function ceiling(rm, r){
diff --git a/assets/javascripts/rectangles/engine/clipper.js b/assets/javascripts/rectangles/engine/clipper.js
index 79e44e5..bcd0586 100644
--- a/assets/javascripts/rectangles/engine/clipper.js
+++ b/assets/javascripts/rectangles/engine/clipper.js
@@ -18,7 +18,7 @@ var clipper = new function(){
base.update = function(){
clipper.solve_rects()
- builder.tube("clip")
+ app.tube("clip")
}
base.add_room = function(r){
diff --git a/assets/javascripts/rectangles/engine/mover.js b/assets/javascripts/rectangles/engine/mover.js
new file mode 100644
index 0000000..ebe4447
--- /dev/null
+++ b/assets/javascripts/rectangles/engine/mover.js
@@ -0,0 +1,31 @@
+var mover = new function(){
+
+ var base = this
+ var last_room = null
+
+ base.init = function(){
+ last_room = clipper.rooms[0]
+ base.bind()
+ }
+
+ base.bind = function(){
+ app.on("move", base.update)
+ }
+
+ base.update = function(pos){
+ if (last_room && last_room.rect.contains(pos.x, pos.z)) return;
+
+ var intersects = []
+ clipper.rooms.forEach(function(r){
+ if (r.rect.contains(pos.x, pos.z)) {
+ intersects.push(r)
+ }
+ })
+
+ if (intersects.length) {
+ $(".face.active").removeClass("active")
+ last_room = intersects[0]
+ }
+ }
+
+}
diff --git a/assets/javascripts/rectangles/map/draw.js b/assets/javascripts/rectangles/map/draw.js
index 57faa10..560cf38 100644
--- a/assets/javascripts/rectangles/map/draw.js
+++ b/assets/javascripts/rectangles/map/draw.js
@@ -151,7 +151,7 @@ map.draw = new function(){
ctx.save()
ctx.translate(x,z)
- var radius = 3 / map.zoom
+ var radius = 2 / map.zoom
ctx.beginPath();
ctx.arc(0, 0, radius, 0, 2*Math.PI, false);
diff --git a/assets/javascripts/rectangles/util/keys.js b/assets/javascripts/rectangles/util/keys.js
index 7c437a1..03abe50 100644
--- a/assets/javascripts/rectangles/util/keys.js
+++ b/assets/javascripts/rectangles/util/keys.js
@@ -1,7 +1,16 @@
var keys = (function(){
+
var base = new function(){}
base.tube = new Tube ()
+ base.on = function(){
+ base.tube.on.apply(base.tube, arguments)
+ }
+
+ base.off = function(){
+ base.tube.off.apply(base.tube, arguments)
+ }
+
$(window).keydown(function(e){
var key = KEY_NAMES[e.keyCode];
switch (key) {