blob: 5a1f7d959047009db436ed73359cd3e3fbe8627d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
var mover = new function(){
var base = this
base.room = null
base.init = function(){
base.bind()
base.update(scene.camera)
}
base.bind = function(){
app.on("move", base.update)
}
base.update = function(pos){
cam.y = pos.y
// if we were in a room
if (base.room) {
// check if we're still in the room
if (base.room.rect.contains(pos.x, pos.z)) {
cam.x = pos.x
cam.z = pos.z
return
}
// check if we've crossed one of the walls.. clamp position if so
var collision = base.room.collides(pos.x, pos.z)
if (collision) {
if (! (collision & LEFT || collision & RIGHT)) {
cam.x = pos.x
}
if (! (collision & FRONT || collision & BACK)) {
cam.z = pos.z
}
return
}
}
// otherwise we've either entered into a new room, or broken free
var intersects = clipper.rooms.filter(function(r){
return r.rect.contains(pos.x, pos.z)
})
$(".face.active").removeClass("active")
if (intersects.length) {
base.room = intersects[0]
base.room.$floor.addClass("active")
base.room.$ceiling.addClass("active")
base.room.$walls.addClass("active")
}
else {
base.room = null
}
cam.x = pos.x
cam.z = pos.z
}
}
|