padding:0.5em; background-color:rgba(0,0,0, 0.1); color:#787878;
border-radius:1em; -moz-border-radius:1em; -webkit-border-radius:1em; }
-#controls { position:fixed; top:1em; left:1em; width:250px; }
- #controls > div { position:relative; }
- #controls label { position:relative; width:30%; display:inline-block; }
- #controls input { position:absolute; width:40%; top:0; right:0; text-align:center;
+#config { position:fixed; top:1em; left:1em; width:250px; }
+ #config > div { position:relative; line-height:1.5em; }
+ #config label { position:relative; width:69%; display:inline-block; }
+ #config input { position:absolute; width:30%; top:0; right:0; text-align:center;
border:0; background-color:rgba(0,0,0, 0.1) ! important; color:#5c5c5c; }
+ #config input[type=checkbox] { top:0.33em; }
#viewport { position:relative; top:1em; width:500px; height:500px; margin:0 auto; overflow:hidden; }
#info { position:fixed; bottom:10px; right:1em; }
var w = this.width, h = this.height;
this.walls = {
- top : new Wall(0,0, w,1),
- bottom : new Wall(0,h, w,1),
- left : new Wall(0,0, 1,h),
- right : new Wall(w,0, 1,h)
+ top : new math.Line(0,0, w,0),
+ bottom : new math.Line(0,h, w,h),
+ left : new math.Line(0,0, 0,h),
+ right : new math.Line(w,0, w,h)
};
- Y(this.walls).forEach(this.addBlocker, this);
+ // this.walls = {
+ // top : new Wall(0,0, w,1),
+ // bottom : new Wall(0,h, w,1),
+ // left : new Wall(0,0, 1,h),
+ // right : new Wall(w,0, 1,h)
+ // };
+ // Y(this.walls).forEach(this.addBlocker, this);
},
addBlocker : function addBlocker(obj){
var wall, blocker, what
, clamp = math.clamp
, bb = obj.boundingBox
- , maxW = this.width, maxH = this.height
- , w = bb.width, h = bb.height
- , x1 = to.x, y1 = to.y
- , x2 = x1+w, y2 = y1+h
+ , minW = 2, minH = 2
+ , maxW = this.width-2, maxH = this.height-2
+ , w = bb.width, h = bb.height
+ , x1 = to.x, y1 = to.y
+ , x2 = x1+w, y2 = y1+h
;
+ // Check for collision with the walls to prevent teleporting units
+ if (x1 < minW || x2 > maxW || y1 < minH || y2 > maxH){
+ blocker = this.game.level;
+ what = 'LevelWall on the ';
+
+ if (x1 < minW) {
+ what = 'left';
+ wall = this.walls.left;
+ to = trj.pointAtX(minW);
+
+ } else if (x2 > maxW) {
+ what = 'right';
+ wall = this.walls.right;
+ to = trj.pointAtX(maxW-w);
+
+ } else if (y1 < minH) {
+ what = 'top';
+ wall = this.walls.top;
+ to = trj.pointAtY(minH);
+
+ } else if (y2 > maxH) {
+ what = 'bottom';
+ wall = this.walls.bottom;
+ to = trj.pointAtY(maxH-h);
+ }
+
+ what += ' at '+wall;
+ return { 'ok':!wall, 'to':to, 'wall':wall, 'blocker':blocker, 'what':what };
+ }
+
// Check for pathmap collisions
var blockers = this.get(x1,y1, x2,y2).remove(obj);
if (blockers.size() > 1){
}
}
- to.setXY(
- clamp(to.x, 2,maxW-2),
- clamp(to.y, 2,maxH-2) );
+ // to.setXY(
+ // clamp(to.x, 2,maxW-2),
+ // clamp(to.y, 2,maxH-2) );
what += ' at '+wall;
return { 'ok':!wall, 'to':to, 'wall':wall, 'blocker':blocker, 'what':what };
-
+ _overlayBG : $('<img src="img/pathmap-bg.png" />')[0],
overlay : function overlay(gridEl){
var w = this.width *SCALE
, h = this.height *SCALE
// Clear the canvas
ctx.beginPath();
- // ctx.fillStyle = 'rgba(0,0,0,0)';
- // ctx.lineWidth = 0;
ctx.clearRect(this.x,this.y, w,h);
ctx.closePath();
+ // ctx.fillStyle = ctx.createPattern(this._overlayBG, 'repeat');
ctx.fillStyle = 'rgba(255,255,255,0.1)';
ctx.lineWidth = 1;
ctx.strokeStyle = 'rgba(255,255,255,0.2)';
acc[r.id] = r;
ctx.beginPath();
- // ctx.fillStyle = 'rgba(255,255,255,0.1)';
- // ctx.lineWidth = 1;
- // ctx.strokeStyle = 'rgba(255,255,255,0.2)';
+ // ctx.globalAlpha = 0.1;
ctx.rect(r.x1,r.y1, r.width,r.height);
ctx.fill();
+ // ctx.globalAlpha = 1;
ctx.stroke();
ctx.closePath();