Commit 0260c304 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Working 4 Player

parent cc035696
File mode changed from 100644 to 100755
No preview for this file type
function createBoat(x,y,angle){
this.x = 0,
this.y = 0,
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,
this.angle=-angle*4,
this.leftOarX=0,
this.leftOarY=0,
this.rightOarX=0,
......@@ -20,7 +21,7 @@ function createBoat(x,y,angle){
this.score=0;
this.max_hor_vel = 400;
this.max_ver_vel = 400;
this.vangle=0;
this.vangle=-angle*4;
this.polySd = new b2PolyDef();
......@@ -33,10 +34,11 @@ for (var i = 0; i <points.length; i++) {
var polyBd = new b2BodyDef();
polyBd.AddShape(this.polySd);
polyBd.position.Set(x,y);
// polyBd.rotation=PI/2;
this.body = world.CreateBody(polyBd);
// this.body.SetAngularVelocity(radians(-180));
this.body.SetCenterPosition(new b2Vec2(x,y),angle);
// this.body.SetAngularVelocity(radians(angle));
// this.add_velocityang();
......@@ -49,11 +51,13 @@ for (var i = 0; i <points.length; i++) {
};
createBoat.prototype.reset=function()
{
if(this.score==3)
this.declareWinner();
this.x = this.orix;
this.y = this.oriy;
this.angle=0;
this.angle=-this.oriA*4;
this.leftOarX=0;
this.leftOarY=0;
this.rightOarX=0;
......@@ -68,7 +72,7 @@ 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();
......@@ -83,7 +87,7 @@ for (var i = 0; i <points.length; i++) {
polyBd.position.Set(this.x,this.y);
this.body = world.CreateBody(polyBd);
this.body.SetCenterPosition(new b2Vec2(this.x,this.y),this.oriA);
......@@ -186,44 +190,11 @@ createBoat.prototype.moveBoat= function(gp)
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();
// }
}
......@@ -287,14 +258,28 @@ createBoat.prototype.drawBoat= function()
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();
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);
}
// 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();
......@@ -352,11 +337,15 @@ createBoat.prototype.moveView=function()
createBoat.prototype.declareWinner=function(gp)
{
scenario();
push();
fill(0,10,153);
textSize(80);
text("Congratulations " + (gp.index + 1) + " won" ,ll,height/2);
if(!sCheck){
text("Congratulations " + ("Player " +(this.id+ 1)) + " won" ,ll,height/2);
}
else
text("Congratulations " + ("Team " +((this.id/2)+1)) + " won" ,ll,height/2);
pop();
noLoop();
......
......@@ -78,18 +78,30 @@ this.body. m_linearDamping=0.95;
Soccer.prototype.check =function(){
if(this.body.GetOriginPosition().x<=38)
{
if(sCheck)
{
boat[2].score+=1;
}
else
boat[1].score+=1;
boat[0].reset();
boat[1].reset();
allowed=false;
GoalText(0,0,119);
for(var i=0;i<boat.length;i++)
boat[i].reset();
this.body.m_position.Set(this.x,this.y);
}
if(this.body.GetOriginPosition().x>=1002)
{
boat[0].score+=1;
boat[0].reset();
boat[1].reset();
allowed=false;
GoalText(0,109,0);
for(var i=0;i<boat.length;i++)
boat[i].reset();
this.body.m_position.Set(this.x,this.y);
......@@ -103,15 +115,17 @@ if(this.body.GetOriginPosition().x>=1002)
function finishLine()
function GoalText(a,b,c)
{
push();
fill(0,102,153);
textSize(100*smallFactor);
text("Finish" ,(ll+300*smallFactor),(-viewYU-2215)*smallFactor);
fill(a,b,c);
textSize(100);
text("Goal" ,(800),(height/2));
textSize(30);
text("Player 1, press X to continue" ,(750),(height/2+50));
pop();
line(ll,(-viewYU-2200)*smallFactor,rl,(-viewYU-2200)*smallFactor);
line(ll,(-viewYU-2300)*smallFactor,rl,(-viewYU-2300)*smallFactor);
}
......@@ -151,8 +165,6 @@ if(this.y>=hght)
}
}
waterStream.prototype.draw=function()
{
......
......@@ -40,7 +40,7 @@ var pCheck,sCheck,s1Check;
var img,bimg,wimg;
var boat0,boat1;
var V,P;
var allowed;
var world;
var groundBdy;
var frameC = 0;
......@@ -71,7 +71,7 @@ function setup() {
s1Check=true;
viewYU=0;
viewYD=9600;
allowed = true;
pCheck=false;
sCheck=false;
prevPress=false,currPress=false;
......@@ -85,9 +85,10 @@ setupWorld();
water.push(new waterStream());
}
bimg=[];
img = loadImage("rock.png");
bimg=loadImage("boat1.png");
bimg[0]=loadImage("boat0.png");
bimg[1]=loadImage("boat1.png");
wimg=loadImage("water.png");
points=[[-10*2*smallFactor1, -170*smallFactor1],[40*smallFactor1,-100*smallFactor1] ,[40*1.5*smallFactor1, (-150+30*4)*smallFactor1],[25*1.5*smallFactor1,(-155+80*3.5)*smallFactor1],[-50*1.5*smallFactor1,(-155+80*3.5)*smallFactor1],[-60*1.5*smallFactor1, (-150+30*4)*smallFactor1],[-75*smallFactor1,-100*smallFactor1]]
......@@ -137,8 +138,13 @@ function draw()
}
}
if(gp.buttons[0].pressed)
allowed=true;
if(allowed)
{
if(paused)
{
......@@ -148,10 +154,7 @@ function draw()
if(sCheck)
{
world.Step( 1/45,1);
boat[0].body.m_force.SetZero();
boat[0].body.m_torque = 0.0;
boat[1].body.m_force.SetZero();
boat[1].body.m_torque = 0.0;
background(150);
fill(50);
scenario();
......@@ -159,8 +162,12 @@ function draw()
boat[0].drawBoat();
boat[1].drawBoat();
boat[2].drawBoat();
boat[3].drawBoat();
boat[0].moveBoat(gamepads[0]);
boat[1].moveBoat(gamepads[1]);
boat[2].moveBoat(gamepads[2]);
boat[3].moveBoat(gamepads[3]);
// boat[0].moveView();
// boat[1].moveView();;
socbal.drawBall();
......@@ -169,17 +176,21 @@ function draw()
}
else{
world.Step( 1/45,1);
boat[0].body.m_force.SetZero();
boat[0].body.m_torque = 0.0;
background(150);
fill(50);
scenario();
boat[0].drawBoat();
boat[1].drawBoat();
boat[0].moveBoat(gamepads[0]);
boat[0].moveView();
boat[1].moveBoat(gamepads[1]);
// boat[0].moveView();
// boat[1].moveView();;
socbal.drawBall();
socbal.check();
// windowAdjustment();
......@@ -204,6 +215,7 @@ function draw()
}
}
}
}
function pauseMenu(gp)
......@@ -283,7 +295,7 @@ function scenario()
pop();
streamOfWater();
finishLine();
// rect(ll-30,height/2-115,30,230);
// rect(rl,height/2-115,30,230);
......@@ -306,9 +318,45 @@ rect(rl,0,30,2300);
function testing()
{ //push();
// fill(0);
if(!sCheck){
push();
textSize(40);
fill(0,153,0);
text("Player1 " + boat[0].score.toFixed(0) ,150, 260+30);
pop();
// fill(125,12);
push();
textSize(40);
fill(0,0,204);
text("Player2 " + boat[1].score.toFixed(0) ,1500, 260+30);
pop();
}
else
{
// fill(125,12.15);
push();
textSize(40);
fill(0,153,0);
text("Team1 " + boat[0].score.toFixed(0) ,150, 260+30);
pop();
// fill(125,12);
push();
textSize(40);
fill(0,0,204);
text("Team2 " + boat[2].score.toFixed(0) ,1500, 260+30);
pop();
}
text("Player1 " + boat[0].score.toFixed(0) ,150, 260+30);
text("Player2 " + boat[1].score.toFixed(0) ,1500, 260+30);
// text(controllers[0].axes[0],50,50);
// text(controllers[0].axes[1],50,80);
// strokeWeight(1);
......@@ -364,10 +412,10 @@ function startMenu(gp)
if(!sCheck)
{
boat=[];
boat.push(new createBoat(100,height/2));
// boat[0].x = 100;
// boat[0].y = 600 ;
boat=[];
boat.push(new createBoat(0,100,height/2,radians(90)));
boat.push(new createBoat(1,width/2-15,height/2,radians(-90)));
return true;
}
......@@ -375,8 +423,11 @@ function startMenu(gp)
{
boat=[];
boat.push(new createBoat(100,height/2,radians(90)));
boat.push(new createBoat(width/2,height/2,radians(-90)));
boat.push(new createBoat(0,100,height/2-200,radians(90)));
boat.push(new createBoat(1,100,height/2+200,radians(90)));
boat.push(new createBoat(2,width/2-10,height/2-200,radians(-90)));
boat.push(new createBoat(3,width/2-10,height/2+200,radians(-90)));
//setting initial position
// boat[0].x = 100;
// boat[0].y = -500 ;
......@@ -392,8 +443,8 @@ function startMenu(gp)
push();
fill(125,12,15);
textSize(40);
text("1 Player" ,ll+300,(height/2)-100);
text("2 Player" ,ll+300,(height/2)-50);
text("2 Player" ,ll+300,(height/2)-100);
text("4 Player" ,ll+300,(height/2)-50);
if(!sCheck)
......@@ -420,110 +471,6 @@ pop();
function windowAdjustment()
{
//zoom check // - - - - - - --------------------------------------//
if(boat[0].y<boat[1].y)
{
if(boat[0].y<=viewYU+50*smallFactor)
{
viewYD=boat[1].y+100/smallFactor;
viewYU=viewYD-hght;
}
if(boat[1].y>=viewYD-50*smallFactor)
{
viewYU=boat[0].y-100/smallFactor;
viewYD=viewYU+hght;
}
}
else
{
if(boat[1].y<=viewYU+50*smallFactor)
{
viewYD=boat[0].y+100/smallFactor;
viewYU=viewYD-hght;
}
if(boat[0].y>=viewYD-50*smallFactor)
{
viewYU=boat[1].y-100/smallFactor;
viewYD=viewYU+hght;
}
}
if((boat[0].y<=viewYU+80*smallFactor||boat[1].y<=viewYU+80*smallFactor||boat[0].y>=viewYD-80*smallFactor||boat[1].y>=viewYD-80*smallFactor) && (abs(boat[0].y-boat[1].y)>500/smallFactor))
{
viewYU-=3*(height)/4;
viewYD+=(height/4);
hght+=height;
smallFactor*=0.5;
ll/=(smallFactor);
// points=[[-10*2*smallFactor, -150*smallFactor], [40*1.5*smallFactor, (-150+30*4)*smallFactor],[40*1.5*smallFactor,(-150+80*3.5)*smallFactor],[-60*1.5*smallFactor,(-150+80*3.5)*smallFactor],[-60*1.5*smallFactor, (-150+30*4)*smallFactor]];
points=[[-10*2*smallFactor, -170*smallFactor],[40*smallFactor,-100*smallFactor] ,[40*1.5*smallFactor, (-150+30*4)*smallFactor],[25*1.5*smallFactor,(-155+80*3.5)*smallFactor],[-50*1.5*smallFactor,(-155+80*3.5)*smallFactor],[-60*1.5*smallFactor, (-150+30*4)*smallFactor],[-75*smallFactor,-100*smallFactor]];
for(var i=0;i<rocks.length;i++)
{
rocks[i].body.m_shapeList.m_radius=(65/2)*smallFactor;
}
}
if((smallFactor!=1)&&abs(boat[0].y-boat[1].y)<400/smallFactor)
{
viewYU+=3*(height)/4;
viewYD-=(height/4);
hght-=height;
ll*=(smallFactor);
smallFactor/=0.5;
// points=[[-10*2*smallFactor, -150*smallFactor], [40*1.5*smallFactor, (-150+30*4)*smallFactor],[40*1.5*smallFactor,(-150+80*3.5)*smallFactor],[-60*1.5*smallFactor,(-150+80*3.5)*smallFactor],[-60*1.5*smallFactor, (-150+30*4)*smallFactor]];
points=[[-10*2*smallFactor, -170*smallFactor],[40*smallFactor,-100*smallFactor] ,[40*1.5*smallFactor, (-150+30*4)*smallFactor],[25*1.5*smallFactor,(-155+80*3.5)*smallFactor],[-50*1.5*smallFactor,(-155+80*3.5)*smallFactor],[-60*1.5*smallFactor, (-150+30*4)*smallFactor],[-75*smallFactor,-100*smallFactor]];
for(var i=0;i<rocks.length;i++)
{
rocks[i].body.m_shapeList.m_radius=(65/2)*smallFactor;
}
}
}
function setupWorld()
{
......
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