Commit 9d0add5a authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

made some changes

parent 1cdc152f
No preview for this file type
function declareWinner(gp) {
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> origin/master
function declareWinner(gp)
{
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;
<<<<<<< HEAD
this.max_hor_vel = 400;
this.max_ver_vel = 400;
this.vangle = -angle * 4;
push();
backSound.stop();
backPlay++;
if(backPlay>=45)
{applauseSound.play();
=======
this.max_hor_vel = 400;
this.max_ver_vel = 400;
this.vangle = -angle * 4;
backPlay=0;
}
image(fireCrackers[floor(fCounter/3)],ll+20,300);
image(fireCrackers[floor(fCounter/3)],(rl+ll)/2,300);
image(fireCrackers[floor(fCounter/3)],rl-100,300);
fCounter++;
if(fCounter==fireCrackers.length*3)
fCounter=0;
fill(0,10,153);
=======
for(var i=0;i<(sPoint+1);i++)
{
boat[i+ (gp-1)*(sPoint+1)].drawBoat();
}
textSize(80);
if(sPoint==0){
text("Congratulations " + "Player " + gp + " won" ,ll,height/2);
}
else
text("Congratulations " + "Team " + gp + " won" ,ll,height/2);
image(fireCrackers[floor(fCounter/3)],ll+20,300);
image(fireCrackers[floor(fCounter/3)],(rl+ll)/2,300);
image(fireCrackers[floor(fCounter/3)],rl-100,300);
pop();
//noLoop();
win=true;
}
function createBoat(id,x,y,angle){
this.id=id,
this.x = x,
......@@ -60,33 +71,15 @@ function createBoat(id,x,y,angle){
this.vangle=-angle*4;
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
>>>>>>> origin/master
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);
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> origin/master
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};
<<<<<<< HEAD
=======
=======
polyBd.position.Set(x,y);
// polyBd.rotation=PI/2;
this.body = world.CreateBody(polyBd);
......@@ -94,53 +87,31 @@ function createBoat(id,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.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(this.score==3)
this.declareWinner();
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
>>>>>>> origin/master
this.rightStartPoint= {x:(40)*smallFactor1 ,y:0};
this.rightEndPoint= {x:(this.rightOarX)*smallFactor1 ,y:(this.rightOarY)*smallFactor1};
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> origin/master
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;
<<<<<<< HEAD
=======
=======
this.x = this.orix;
this.y = this.oriy;
this.angle=-this.oriA*4;
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
>>>>>>> origin/master
this.leftOarX=0;
this.leftOarY=0;
this.rightOarX=0;
......@@ -157,11 +128,11 @@ createBoat.prototype.reset=function()
this.max_ver_vel = 400;
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]);
}
......@@ -169,66 +140,20 @@ createBoat.prototype.reset=function()
polyBd.AddShape(this.polySd);
polyBd.position.Set(this.x,this.y);
<<<<<<< HEAD
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];
}
=======
<<<<<<< HEAD
this.body = world.CreateBody(polyBd);
this.body.SetCenterPosition(new b2Vec2(this.x,this.y),this.oriA);
=======
this.body = world.CreateBody(polyBd);
this.body.SetCenterPosition(new b2Vec2(this.x,this.y),this.oriA);
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
}
}
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
// find right oar
this.rightOarX = 80 * gp.axes[3] + 100;
this.rightOarY = 100 * gp.axes[2];
}
......@@ -236,133 +161,123 @@ createBoat.prototype.moveBoat= function(gp)
{
this.leftOarX = 80 * gp.axes[0] - 100;
this.leftOarY = 100 * gp.axes[1];
// find right oar
// find right oar
this.rightOarX = 80 * gp.axes[2] + 100;
this.rightOarY = 100 * gp.axes[3];
}
>>>>>>> origin/master
// 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)
{
(this.angle)+=temp;
}
if(this.prevLeftOarY >this.leftOarY)
{
(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.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};
<<<<<<< HEAD
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.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.setPoints( [ new SAT.Vector(this.leftStartPoint.x,this.leftStartPoint.y),new SAT.Vector(this.leftEndPoint.x,this.leftEndPoint.y)] );
this.polL.rotate(this.vangle);
>>>>>>> origin/master
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.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));
}
}
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();
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> origin/master
}
createBoat.prototype.add_velocity = function(vel)
{
<<<<<<< HEAD
=======
=======
......@@ -373,108 +288,78 @@ createBoat.prototype.add_velocity = function(vel)
createBoat.prototype.add_velocity = function(vel)
{
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
>>>>>>> origin/master
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 bodyAngle = body.GetRotation();
var desiredAngle=-(this.angle/4);
var nextAngle = bodyAngle + body.GetAngularVelocity() / 60.0;
var totalRotation = desiredAngle - nextAngle;
var nextAngle = bodyAngle + body.GetAngularVelocity() / 60.0;
var totalRotation = desiredAngle - nextAngle;
body.SetAngularVelocity(((v.Length())*(tan(totalRotation)))/15);
body.SetAngularVelocity(((v.Length())*(tan(totalRotation)))/15);
}
createBoat.prototype.drawBoat= function()
{
{
// push();
// push();
// translate(ll + (this.x)*smallFactor,(-viewYU+this.y)*smallFactor);
// rotate(-(this.angle)/4); //rotating the boat
<<<<<<< HEAD
push();
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();
=======
push();
<<<<<<< HEAD
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();
>>>>>>> origin/master
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();
<<<<<<< HEAD
=======
=======
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
// rect(-0,0,100, 100);
if(!sCheck)
{
image(bimg[this.id], (-95)*smallFactor1,-170*smallFactor1, bimg[this.id].width*smallFactor1, bimg[this.id].height*smallFactor1);
}
else
{
if(this.id<=1)
{
image(bimg[0], (-95)*smallFactor1,-170*smallFactor1, bimg[0].width*smallFactor1, bimg[0].height*smallFactor1);
}
else
image(bimg[1], (-95)*smallFactor1,-170*smallFactor1, bimg[1].width*smallFactor1, bimg[1].height*smallFactor1);
//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(255);
textSize(20);
noStroke();
text(this.id+1,(-25)*smallFactor1,-125*smallFactor1);
pop();