Skip to content

Commit

Permalink
EVERYTHING WORKS LIFE IS GREAT
Browse files Browse the repository at this point in the history
  • Loading branch information
michelle committed Feb 18, 2012
1 parent 4b0a881 commit 2da36a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion admin/public/js/index.js
Expand Up @@ -6,7 +6,7 @@ var physics;

var addRect = function addRect (w, h, callback) {
var close = $('<div></div>').addClass('close').click(deleteRect);
$('<div></div>').data('o', 0).data('cb', callback).dblclick(rotate).addClass('rect').append(close).css({width: w/7, height: h/7, 'background-color': '#'+Math.floor(Math.random()*16777215).toString(16)}).draggable({snap:true, snapMode: 'outer', containment: 'parent'}).appendTo('#field');
$('<div></div>').data('o', 0).data('cb', callback).addClass('rect').append(close).css({width: w/7, height: h/7, 'background-color': '#'+Math.floor(Math.random()*16777215).toString(16)}).draggable({snap:true, snapMode: 'outer', containment: 'parent'}).appendTo('#field');
};

var send = function send () {
Expand Down
59 changes: 33 additions & 26 deletions physics.js
@@ -1,5 +1,5 @@
var Bridge = require('./bridge').Bridge;
var bridge = new Bridge({host:'136.152.37.120 '});
var bridge = new Bridge({host:'136.152.37.120'});
var ball = {x:120,y:120,radius:20};
var paddle1 = {x1:50,y1:50,x2:90,y2:60};
var paddle2 = {x1:50,y1:50,x2:90,y2:70};
Expand Down Expand Up @@ -58,15 +58,16 @@ physics = {
var m = physics.cornerFinder(r);
boxes = m.corners;
soft = m.softs;
console.log('softs: ', soft);

console.log(boxes);
leftAvg = (soft.left[1].y-soft.left[0].y)/2;
rightAvg = (soft.right[1].y-soft.right[0].y)/2;
paddle1.x1 = soft.left[0].x+50;
paddle1.x1 = soft.left[0].x+20;
paddle1.y1 = leftAvg-75;
paddle1.x2 = paddle1.x1+40;
paddle1.y2 = paddle1.y1+150;
paddle2.x1 = soft.right[0].x-90;
paddle2.x1 = soft.right[0].x - 60;
paddle2.y1 = rightAvg-75;
paddle2.x2 = paddle2.x1+40;
paddle2.y2 = paddle2.y1+150;
Expand Down Expand Up @@ -114,13 +115,13 @@ physics = {
var monitors = physics.translate(rawmonitors);

monitors.sort(physics.sortByX);

console.log(monitors);
// Top edge.
console.log('sorted monitors: ' + monitors[0].x);

// Left edge.
var leftT = { x: monitors[0].x, y: monitors[0].y };
var leftB = { x: monitors[0].x, y: monitors[0].y + monitors[0].height };

// Bottom edge.
// Right edge.
var rightT = { x: Number.MIN_VALUE, y: Number.MIN_VALUE };
var rightB = { x: Number.MIN_VALUE, y: Number.MAX_VALUE };

Expand All @@ -143,6 +144,7 @@ physics = {
if (tl.x == leftT.x) {
leftT.y = Math.min(tl.y, leftT.y);
leftB.y = Math.max(br.y, leftB.y);
console.log('changing left ', leftT, leftB);
}

// Check for right edge.
Expand All @@ -151,19 +153,21 @@ physics = {
rightB.y = br.y;
rightT.x = br.x;
rightB.x = br.x;
console.log('changing right ', rightT, rightB);
} else if (br.x == rightB.x) {
rightB.y = Math.max(br.y, rightB.y);
rightT.y = Math.min(tl.y, rightT.y);
console.log('changing right ', rightT, rightB);
}
}
console.log(monitors);
var sharad = {
corners: corners,
softs: {
left: [leftT, leftB],
right: [rightT, rightB]
}
};

return sharad;
},
update:function(){
Expand Down Expand Up @@ -198,18 +202,7 @@ physics = {
/*if (curBox == -1 && nextXBox != -1){
vel.x = -vel.x;
}*/
if (nextXBall.x>=soft.right[0].x){
score1++;
ball.x = startX;
ball.y = startY;
vel = {x:Math.abs(vel.x),y:Math.abs(vel.y)};
}
if (nextXBall.x<=soft.left[0].x){
score2++;
ball.x = startX;
ball.y = startY;
vel = {x:Math.abs(vel.x),y:Math.abs(vel.y)};
}

if ((nextXBall.x>=paddle1.x1&&nextXBall.x<=paddle1.x2&&nextXBall.y<=paddle1.y2&&nextXBall.y>=paddle1.y2)||(nextXBall.x<=paddle1.x2&&nextXBall.x>=paddle1.x1&&nextXBall.y<=paddle1.y2&&nextXBall.y>=paddle1.y1)){
vel.x = -vel.x;
vel.x *= 1.1;
Expand All @@ -220,27 +213,41 @@ physics = {
vel.x *= 1.1;
vel.y *= 1.1;
}


if (nextXBox == -1){
vel.x = -vel.x;
}

if (nextYBox == -1){
vel.y = -vel.y;
}

if (nextXBall.x>=soft.right[0].x){
score1++;
ball.x = startX;
ball.y = startY;
vel = {x:30,y:30};
}
if (nextXBall.x<=soft.left[0].x){
score2++;
ball.x = startX;
ball.y = startY;
vel = {x:Math.abs(vel.x),y:Math.abs(vel.y)};
}
ball.x += vel.x;
ball.y += vel.y;

shot3.draw({"ball":ball,"paddle":{'1':paddle1,'2':paddle2},"score":{'1':score1,'2':score2}});
},
movePaddle:function(player,amount){
console.log('move', arguments);
if (player == '1'){
paddle1.y1 += amount;
paddle1.y2 += amount;
paddle1.y1 += 2* amount;
paddle1.y2 += 2* amount;
} else if (player == '2'){
paddle2.y1 += amount;
paddle2.y2 += amount;
paddle2.y1 += 2* amount;
paddle2.y2 += 2* amount;
}
console.log(paddle1, paddle2);
}


Expand Down

0 comments on commit 2da36a8

Please sign in to comment.