Commit 471f6d17 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Indenting

parent cc035696
File mode changed from 100644 to 100755
No preview for this file type
File added
File added
File added
function declareWinner(gp) {
function createBoat(x,y,angle){
this.x = 0,
this.y = 0,
this.orix=x,
this.oriy=y,
this.oriA=angle;
this.angle=angle,
this.leftOarX=0,
this.leftOarY=0,
this.rightOarX=0,
this.rightOarY=0,
this.leftIn=false,
this.rightIn=false,
this.velocity=0,
this.vx=0,
this.vy=0,
this.prevLeftOarY=0,
this.prevLeftOarX=0,
this.score=0;
scenario();
push();
fill(0, 10, 153);
textSize(80);
if (sPoint == 0) {
text("Congratulations " + "Player " + gp + " won", ll, height / 2);
} else
text("Congratulations " + "Team " + gp + " won", ll, height / 2);
pop();
noLoop();
}
function createBoat(id, x, y, angle) {
this.id = id, this.x = x, this.y = y, this.orix = x, this.oriy = y, this.oriA =
angle;
this.angle = -angle * 4, this.leftOarX = 0, this.leftOarY = 0, this.rightOarX =
0, this.rightOarY = 0, this.leftIn = false, this.rightIn = false, this.velocity =
0, this.vx = 0, this.vy = 0, this.prevLeftOarY = 0, this.prevLeftOarX =
0, this.score = 0;
this.max_hor_vel = 400;
this.max_ver_vel = 400;
this.vangle=0;
this.vangle = -angle * 4;
this.polySd = new b2PolyDef();
this.polySd.density = 0.8;
this.polySd.vertexCount = points.length;
for (var i = 0; i <points.length; i++) {
for (var i = 0; i < points.length; i++) {
this.polySd.vertices[i].Set(points[i][0], points[i][1]);
}
var polyBd = new b2BodyDef();
polyBd.AddShape(this.polySd);
polyBd.position.Set(x,y);
this.body = world.CreateBody(polyBd);
// this.body.SetAngularVelocity(radians(-180));
};
createBoat.prototype.reset=function()
{
polyBd.position.Set(x, y);
// polyBd.rotation=PI/2;
this.body = world.CreateBody(polyBd);
this.body.SetCenterPosition(new b2Vec2(x, y), angle);
// this.body.SetAngularVelocity(radians(angle));
// this.add_velocityang();
this.leftStartPoint= {x: (-75)*smallFactor1 ,y:0};
this.leftEndPoint= {x:(this.leftOarX)*smallFactor1 ,y:(this.leftOarY)*smallFactor1};
this.rightStartPoint= {x:(40)*smallFactor1 ,y:0};
this.rightEndPoint= {x:(this.rightOarX)*smallFactor1 ,y:(this.rightOarY)*smallFactor1};
this.x = this.orix;
this.y = this.oriy;
this.angle=0;
this.polL = new SAT
.Polygon(new SAT.Vector(ll+x,y), [ new SAT.Vector(this.leftStartPoint.x,this.leftStartPoint.y),new SAT.Vector(this.leftEndPoint.x,this.leftEndPoint.y)]);
this.polR = new SAT
.Polygon(new SAT.Vector(ll+x,y), [ new SAT.Vector(this.rightStartPoint.x,this.rightStartPoint.y),new SAT.Vector(this.rightEndPoint.x,this.rightEndPoint.y)]);
}
;
createBoat.prototype.reset=function()
{
if(team1==3)
declareWinner(1);
else if(team2==3)
declareWinner(2);
this.x = this.orix;
this.y = this.oriy;
this.angle=-this.oriA*4;
this.leftOarX=0;
this.leftOarY=0;
this.rightOarX=0;
......@@ -68,13 +76,13 @@ createBoat.prototype.reset=function()
// this.score=0;
this.max_hor_vel = 400;
this.max_ver_vel = 400;
this.vangle=0;
this.vangle=-this.oriA*4;
world.DestroyBody(this.body);
this.polySd = new b2PolyDef();
this.polySd.density = 0.8;
this.polySd.vertexCount = points.length;
for (var i = 0; i <points.length; i++) {
for (var i = 0; i <points.length; i++) {
this.polySd.vertices[i].Set(points[i][0], points[i][1]);
}
......@@ -82,227 +90,207 @@ for (var i = 0; i <points.length; i++) {
polyBd.AddShape(this.polySd);
polyBd.position.Set(this.x,this.y);
this.body = world.CreateBody(polyBd);
this.body = world.CreateBody(polyBd);
this.body.SetCenterPosition(new b2Vec2(this.x,this.y),this.oriA);
}
createBoat.prototype.moveBoat= function(gp)
{
//find left oar
if(gp.axes.length !=4)
{
this.leftOarX = 80 * gp.axes[1] - 100;
this.leftOarY = 100 * gp.axes[0];
// find right oar
this.rightOarX = 80 * gp.axes[3] + 100;
this.rightOarY = 100 * gp.axes[2];
}
else
{
this.leftOarX = 80 * gp.axes[0] - 100;
this.leftOarY = 100 * gp.axes[1];
// find right oar
this.rightOarX = 80 * gp.axes[2] + 100;
this.rightOarY = 100 * gp.axes[3];
}
}
createBoat.prototype.moveBoat= function(gp)
{
//find left oar
this.leftOarX = 80 * gp.axes[1] - 100;
this.leftOarY = 100 * gp.axes[0];
// find right oar
this.rightOarX = 80 * gp.axes[3] + 100;
this.rightOarY = 100 * gp.axes[2];
// calculate movement
if (this.leftIn) {
dLeft = this.prevLeftOarY - this.leftOarY;
dUp = this.prevLeftOarX - this.leftOarX;
dUp = this.prevLeftOarX - this.leftOarX;
var v1=createVector(this.prevLeftOarX,this.prevLeftOarY);
var v2=createVector(this.leftOarX,this.leftOarY);
var temp=p5.Vector.angleBetween(v1,v2); // store the angle to be changed by boat
if(temp.toString()!="NaN")
{
if(this.prevLeftOarY >this.leftOarY)
{
if(this.prevLeftOarY >this.leftOarY)
{
(this.angle)+=temp;
}
(this.angle)+=temp;
}
else
{
(this.angle)-=temp;
}
{
(this.angle)-=temp;
}
}
this.velocity += dLeft / 50;
}
if (this.rightIn) {
dRight = this.prevRightOarY - this.rightOarY;
dDown = this.prevRightOarX - this.rightOarX;
var v1=createVector(this.prevRightOarX,this.prevRightOarY);
var v2=createVector(this.rightOarX,this.rightOarY);
var temp=p5.Vector.angleBetween(v1,v2);
if(temp.toString()!="NaN")
{
if(this.prevRightOarY >this.rightOarY)
if(this.prevRightOarY >this.rightOarY)
{
(this.angle)-=temp;
}
else
else
{
(this.angle)+=temp;
}
}
this.velocity += dRight / 50;
this.velocity += dRight / 50;
}
this.prevLeftOarY = this.leftOarY;
this.prevRightOarY = this.rightOarY;
this.prevRightOarX = this.rightOarX;
this.prevLeftOarX = this.leftOarX;
this.prevLeftOarX = this.leftOarX;
this.leftStartPoint= {x: -75*smallFactor1 ,y:0};
this.leftEndPoint= {x:this.leftOarX*smallFactor1 ,y:this.leftOarY*smallFactor1};
this.rightStartPoint= {x:40*smallFactor1 ,y:0};
this.rightEndPoint= {x:this.rightOarX*smallFactor1 ,y:this.rightOarY*smallFactor1};
this.polL.pos.x=this.x+ll;
this.polL.pos.y=this.y;
this.polL.setPoints( [ new SAT.Vector(this.leftStartPoint.x,this.leftStartPoint.y),new SAT.Vector(this.leftEndPoint.x,this.leftEndPoint.y)] );
this.polL.rotate(this.vangle);
this.polR.pos.x=this.x+ll;
this.polR.pos.y=this.y;
this.polR.setPoints( [ new SAT.Vector(this.rightStartPoint.x,this.rightStartPoint.y),new SAT.Vector(this.rightEndPoint.x,this.rightEndPoint.y)] );
this.polR.rotate(this.vangle);
var response = new SAT.Response();
if(socbal!=null)
{
if( SAT.testPolygonCircle(this.polL , socbal.SatCircle,response) )
{
socbal.body.SetLinearVelocity(new b2Vec2(50*response.overlapV.x,50*response.overlapV.y));
}
if( SAT.testPolygonCircle(this.polR , socbal.SatCircle,response) )
{
socbal.body.SetLinearVelocity(new b2Vec2(50*response.overlapV.x,50*response.overlapV.y));
}
}
this.velocity *= damping;
//moving=velocityY;
this.vy = ((this.velocity*(cos((this.angle)/4))));
//y+=sSpeed;
//adjusting x coordinate if boat is rotated
this.vx = this.velocity*sin((this.angle)/4);
this.vx = this.velocity*sin((this.angle)/4);
this.add_velocity(new b2Vec2(this.vx*50,this.vy*50));
this.add_velocityang();
this.x=this.body.GetOriginPosition().x;
this.y=this.body.GetOriginPosition().y;
this.vangle=this.body.GetRotation();
//---------------------------------------------------
//changing my view if boat reaches the top of screen
if(!sCheck)
{
if(this.body.GetOriginPosition().y<=viewYU+50)
{
viewYD=viewYU+50;
viewYU=viewYD-height;
}
if(this.body.GetOriginPosition().y>=viewYD-50)
{
viewYU=viewYD-50;
viewYD=viewYU+height;
}
}
//------------------------------------------------------
if(this.y <= -2250)
this.declareWinner(gp);
// if(this.score<=0)
// {
// push();
// fill(0,12,244);
// textSize(100*smallFactor);
// text("Try Again",width/2,(-viewYU+this.y)*smallFactor);
// pop();
// noLoop();
// }
}
createBoat.prototype.add_velocity = function(vel)
{
createBoat.prototype.add_velocity = function(vel)
{
var b = this.body;
var v = b.GetLinearVelocity();
v.Add(vel);
//check for max horizontal and vertical velocities and then set
if(Math.abs(v.y) > this.max_ver_vel)
{
v.y = this.max_ver_vel * v.y/Math.abs(v.y);
}
if(Math.abs(v.x) > this.max_hor_vel)
{
v.x = this.max_hor_vel * v.x/Math.abs(v.x);
}
//set the new velocity
b.SetLinearVelocity(v);
}
}
createBoat.prototype.add_velocityang= function(){
createBoat.prototype.add_velocityang= function() {
var body = this.body;
var body = this.body;
var v =body.GetLinearVelocity();
var bodyAngle = body.GetRotation();
var desiredAngle=-(this.angle/4);
var nextAngle = bodyAngle + body.GetAngularVelocity() / 60.0;
var totalRotation = desiredAngle - nextAngle;
var bodyAngle = body.GetRotation();
body.SetAngularVelocity(((v.Length())*(tan(totalRotation)))/15);
var desiredAngle=-(this.angle/4);
var nextAngle = bodyAngle + body.GetAngularVelocity() / 60.0;
var totalRotation = desiredAngle - nextAngle;
}
body.SetAngularVelocity(((v.Length())*(tan(totalRotation)))/15);
}
createBoat.prototype.drawBoat= function()
{
{
// push();
// translate(ll + (this.x)*smallFactor,(-viewYU+this.y)*smallFactor);
// rotate(-(this.angle)/4); //rotating the boat
push();
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
// rect(-0,0,100, 100);
image(bimg, (-95)*smallFactor1,-170*smallFactor1, bimg.width*smallFactor1, bimg.height*smallFactor1);
beginShape();
for (var i = 0; i <points.length; i++) {
vertex(points[i][0], points[i][1]);
}
vertex(points[0][0], points[0][1]);
endShape();
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
// rect(-0,0,100, 100);
//if(sPoint<(boat.length)/2)
// {
image(bimg[floor((this.id)/((boat.length)/2))], (-95)*smallFactor1,-170*smallFactor1, bimg[0].width*smallFactor1, bimg[0].height*smallFactor1);
push();
fill(125,12,15);
textSize(20);
noStroke();
text(this.id+1,(-25)*smallFactor1,-125*smallFactor1);
pop();
// beginShape();
// for (var i = 0; i <points.length; i++) {
// vertex(points[i][0], points[i][1]);
// }
// vertex(points[0][0], points[0][1]);
// endShape();
pop();
push();
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
strokeWeight(5);
if (this.leftOarX*smallFactor > -100*smallFactor) {
stroke(100);
......@@ -311,7 +299,7 @@ translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
stroke(0);
this.leftIn = true;
}
line(-75*smallFactor1, 0, this.leftOarX*smallFactor1, this.leftOarY*smallFactor1);
line(this.leftStartPoint.x,this.leftStartPoint.y , this.leftEndPoint.x,this.leftEndPoint.y );
if (this.rightOarX*smallFactor < 101*smallFactor) {
stroke(100);
this.rightIn = false;
......@@ -319,52 +307,9 @@ translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
stroke(0);
this.rightIn = true;
}
line(40*smallFactor1, 0, this.rightOarX*smallFactor1, this.rightOarY*smallFactor1);
line(this.rightStartPoint.x,this.rightStartPoint.y , this.rightEndPoint.x,this.rightEndPoint.y );
pop();
this.body.SetLinearVelocity(new b2Vec2(0,0));
}
createBoat.prototype.collision= function()
{
this.velocity+=0.1;
this.score--;
}
createBoat.prototype.moveView=function()
{
viewYU+=(this.velocity*(cos((this.angle)/4)))/3;
viewYD+=(this.velocity*(cos((this.angle)/4)))/3;
}
createBoat.prototype.declareWinner=function(gp)
{
push();
fill(0,10,153);
textSize(80);
text("Congratulations " + (gp.index + 1) + " won" ,ll,height/2);
pop();
noLoop();
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -72,6 +72,8 @@
<script src='js/box2d/dynamics/joints/b2RevoluteJoint.js'></script>
<script src='js/box2d/dynamics/joints/b2RevoluteJointDef.js'></script>
<script language="javascript" src="SAT.js"></script>
<script language="javascript" src="howler.js"></script>
<script src = "gamepad.js"></script>
<script language="javascript" src="scenario.js"></script>
<script language="javascript" src="boat.js "></script>
......
function createRock(x,y) {
this.y=typeof(y)!=="undefined"?y:random(-2000,200);
this.x=typeof(x)!=="undefined"?x:(this.y>390&&this.y<590)?(random(120,880)):random(20,880);
this.polySd = new b2CircleDef();
this.polySd.density = 100.0;
this.polySd.radius = 65/2;
var polyBd = new b2BodyDef();
polyBd.AddShape(this.polySd);
polyBd.position.Set(this.x,this.y);
this.body = world.CreateBody(polyBd);
var jointDef = new b2RevoluteJointDef();
jointDef.body1 = this.body;
jointDef.body2 = groundBdy;
jointDef.anchorPoint = this.body.GetOriginPosition();
world.CreateJoint(jointDef);
}
createRock.prototype.drawRock =function(){
push();
imageMode(CENTER);
// ellipse( ll + (this.body.GetOriginPosition().x)*smallFactor , (-viewYU+this.body.GetOriginPosition().y)*smallFactor,65*smallFactor,65*smallFactor);
image(img, ll + (this.body.GetOriginPosition().x)*smallFactor , (-viewYU+this.body.GetOriginPosition().y)*smallFactor,img.height*smallFactor,img.width*smallFactor);
pop();
}
function Soccer(x, y) {
this.y = height / 2;