Commit 6a36325a authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

control mapping and other stuff

parent e06d4591
File mode changed from 100644 to 100755
No preview for this file type
function oars(x,y,n)
function oars(x,y,n)
{
this.leftOarX=0,
this.leftOarY=0,
......@@ -8,8 +8,9 @@
this.rightIn=false,
this.prevLeftOarY=0,
this.prevLeftOarX=0
this.velocity=0;
this.velocityL=0;
this.velocityR=0;
this.prevleftStartPoint = {x:0 , y:0};
this.prevleftEndPoint = {x:0 , y:0};
......@@ -141,10 +142,10 @@ this.body.CreateFixture(this.fixtureDef);
if(i==0)
{
this.oar[i].leftStartPoint={x:(((-75+20))*smallFactor),y:((-90+(i*120))*smallFactor)} ;
this.oar[i].leftEndPoint={x:((this.oar[i].leftOarX-10)*smallFactor) ,y:((this.oar[i].leftOarY-70+(i*110))*smallFactor)};
this.oar[i].leftEndPoint={x:((this.oar[i].leftOarX-10+10)*smallFactor) ,y:((this.oar[i].leftOarY-70+(i*110))*smallFactor)};
this.oar[i].rightStartPoint={x:((40-20)*smallFactor),y:((-90+(i*120))*smallFactor)} ;
this.oar[i].rightEndPoint={x:((this.oar[i].rightOarX-10)*smallFactor) ,y:((this.oar[i].rightOarY-50+(i*110))*smallFactor)};
this.oar[i].rightEndPoint={x:((this.oar[i].rightOarX-10)*smallFactor) ,y:((this.oar[i].rightOarY-70+(i*110))*smallFactor)};
}
else if(i==3){
this.oar[i].leftStartPoint={x:(((-75+50))*smallFactor),y:((-90+(i*120))*smallFactor)} ;
......@@ -159,7 +160,7 @@ this.body.CreateFixture(this.fixtureDef);
this.oar[i].leftEndPoint={x:((this.oar[i].leftOarX-10)*smallFactor) ,y:((this.oar[i].leftOarY-70+(i*110))*smallFactor)};
this.oar[i].rightStartPoint={x:((40-20)*smallFactor),y:((-90+(i*120))*smallFactor)} ;
this.oar[i].rightEndPoint={x:((this.oar[i].rightOarX-10)*smallFactor) ,y:((this.oar[i].rightOarY-50+(i*110))*smallFactor)};
this.oar[i].rightEndPoint={x:((this.oar[i].rightOarX-10)*smallFactor) ,y:((this.oar[i].rightOarY-70+(i*110))*smallFactor)};
}
......@@ -183,7 +184,7 @@ this.body.CreateFixture(this.fixtureDef);
if(SAT.testPolygonPolygon(this.oar[i].polL,this.oar[i+1].polL,responseL))
{
oarColliding.play();
text("yes",50,50);
//text("yes",50,50);
// text(boat[i].oar[i].leftEndPoint.x,50,350);
// text(boat[i].oar[i].prevleftEndPoint.x,50,450);
this.oar[i].leftEndPoint.x = this.oar[i].prevleftEndPoint.x-2;
......@@ -194,6 +195,10 @@ this.body.CreateFixture(this.fixtureDef);
this.oar[i+1].polL.setPoints( [ new SAT.Vector(this.oar[i+1].leftStartPoint.x,this.oar[i+1].leftStartPoint.y),new SAT.Vector(this.oar[i+1].leftEndPoint.x,this.oar[i+1].leftEndPoint.y)] );
this.oar[i+1].polL.rotate(this.vangle);
responseL.clear();
this.oar[i].velocityL=0;
this.oar[i+1].velocityL=0;
}
else
{
......@@ -205,7 +210,7 @@ this.body.CreateFixture(this.fixtureDef);
if(SAT.testPolygonPolygon(this.oar[i].polR,this.oar[i+1].polR,responseR))
{
oarColliding.play();
text("ye1s",50,50);
// text("ye1s",50,50);
this.oar[i].rightEndPoint.x = this.oar[i].prevrightEndPoint.x-2;
this.oar[i].rightEndPoint.y = this.oar[i].prevrightEndPoint.y-2;
this.oar[i].isCollidingR=true;
......@@ -214,7 +219,8 @@ this.body.CreateFixture(this.fixtureDef);
this.oar[i+1].polR.setPoints([ new SAT.Vector(this.oar[i+1].leftStartPoint.x,this.oar[i+1].leftStartPoint.y),new SAT.Vector(this.oar[i+1].leftEndPoint.x,this.oar[1+i ].leftEndPoint.y)] );
this.oar[i+1].polR.rotate(this.vangle);
responseR.clear();
this.oar[i].velocityR=0;
this.oar[i+1].velocityR=0;
}
else
{
......@@ -245,7 +251,11 @@ this.body.CreateFixture(this.fixtureDef);
(this.angle)-=temp/4;
}
}
this.velocity += dLeft /(25*(sPoint+1));
this.oar[i].velocityL += dLeft /(50*(boat[0].oar.length));
if( this.oar[i].velocityL >0.75)
this.oar[i].velocityL=0.75;
if( this.oar[i].velocityL<-0.75)
this.oar[i].velocityL=-0.75;
}
}
......@@ -279,16 +289,27 @@ this.body.CreateFixture(this.fixtureDef);
}
if(sPoint ==0 || sPoint==1)
this.velocity += dRight /25;
else
this.velocity += dRight /(25*(sPoint+1));
this.oar[i].velocityR += dRight /(50*(boat[0].oar.length));
if( this.oar[i].velocityR >0.75)
this.oar[i].velocityR=0.75;
if( this.oar[i].velocityR<-0.75)
this.oar[i].velocityR=-0.75;
}
}
this.oar[i].velocityL*=damping;
this.oar[i].velocityR*=damping;
this.oar[i].velocity=this.oar[i].velocityL+this.oar[i].velocityR;
// this.velocity=0;
// for(var p=0;p<this.oar.length;p++)
this.velocity+=this.oar[i].velocity;
//updating previous points
this.velocity*=damping;
this.oar[i].prevLeftOarY = this.oar[i].leftOarY;
this.oar[i].prevRightOarY = this.oar[i].rightOarY;
this.oar[i].prevRightOarX = this.oar[i].rightOarX;
......@@ -314,14 +335,14 @@ this.body.CreateFixture(this.fixtureDef);
this.x=this.body.GetPosition().x;
this.y=this.body.GetPosition().y;
this.vangle=this.body.GetAngle();
this.velocity *= damping;
//Calculating the components of velocity in x and y direction
this.vy = ((this.velocity*(cos((this.vangle)))));
this.vx = this.velocity*sin((-this.vangle));
//adding velocity to body of box2d object
this.add_velocity(new b2Vec2(this.vx,this.vy));
this.add_velocity(new b2Vec2(this.vx*(10/boat[0].oar.length),this.vy*(10/boat[0].oar.length)));
this.add_velocityang();
......@@ -353,20 +374,10 @@ this.body.CreateFixture(this.fixtureDef);
if(this.y <= -5000)
this.declareWinner(gp);
// 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();
}
}
......@@ -374,23 +385,23 @@ this.body.CreateFixture(this.fixtureDef);
createBoat.prototype.add_velocity = function(vel)
{
var b = this.body;
var v = b.GetLinearVelocity();
// var v = b.GetLinearVelocity();
v.Add(vel);
if(Math.abs(v.y) > this.max_ver_vel)
{
v.y = this.max_ver_vel * v.y/Math.abs(v.y);
}
// v.Add(vel);
// 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);
}
// if(Math.abs(v.x) > this.max_hor_vel)
// {
// v.x = this.max_hor_vel * v.x/Math.abs(v.x);
// }
b.SetLinearVelocity(v);
b.SetLinearVelocity(vel);
// b.ApplyForce(vel,b.GetPosition);
}
......@@ -510,13 +521,27 @@ this.body.CreateFixture(this.fixtureDef);
createBoat.prototype.declareWinner=function()
{
scenario();
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);
this.drawBoat();
//this.body.SetOriginPosition
fCounter++;
if(fCounter==fireCrackers.length*3)
fCounter=0;
push();
fill(0,10,153);
var s;
textSize(80);
text("Congratulations " + (this.id + 1) + " won" ,ll,height/2);
var colr = this.id==0?"Red":"Green";
s = colr=="Red"? color(255,0,0):color(0,255,0);
fill(s);
rectMode(CENTER);
text("Congratulations " + colr + " won" ,width/4,height/2);
pop();
noLoop();
win=true;
}
......@@ -562,9 +587,7 @@ this.body.CreateFixture(this.fixtureDef);
......
fw01/0.gif

188 Bytes

fw01/1.gif

1.02 KB

fw01/10.gif

2.27 KB

fw01/11.gif

2.28 KB

fw01/12.gif

2.21 KB

fw01/13.gif

2.15 KB

fw01/14.gif

2.07 KB

fw01/15.gif

1.88 KB

fw01/16.gif

1.71 KB

fw01/17.gif

1.54 KB

fw01/18.gif

1.26 KB

fw01/19.gif

965 Bytes

fw01/20.gif

965 Bytes

fw01/3.gif

1.29 KB

fw01/4.gif

1.53 KB

fw01/5.gif

1.91 KB

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment