Commit 55d536ef authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Last changes

parents 047725e2 0260c304
function declareWinner(gp) {
<<<<<<< HEAD
scenario();
push();
fill(0, 10, 153);
......@@ -24,6 +25,33 @@ function createBoat(id, x, y, angle) {
this.max_ver_vel = 400;
this.vangle = -angle * 4;
=======
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=-angle*4;
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
this.polySd = new b2PolyDef();
this.polySd.density = 0.8;
this.polySd.vertexCount = points.length;
......@@ -33,6 +61,7 @@ function createBoat(id, x, y, angle) {
var polyBd = new b2BodyDef();
polyBd.AddShape(this.polySd);
<<<<<<< HEAD
polyBd.position.Set(x, y);
// polyBd.rotation=PI/2;
this.body = world.CreateBody(polyBd);
......@@ -42,10 +71,33 @@ function createBoat(id, x, y, angle) {
this.leftStartPoint= {x: (-75)*smallFactor1 ,y:0};
this.leftEndPoint= {x:(this.leftOarX)*smallFactor1 ,y:(this.leftOarY)*smallFactor1};
=======
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();
};
createBoat.prototype.reset=function()
{
if(this.score==3)
this.declareWinner();
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
this.rightStartPoint= {x:(40)*smallFactor1 ,y:0};
this.rightEndPoint= {x:(this.rightOarX)*smallFactor1 ,y:(this.rightOarY)*smallFactor1};
<<<<<<< HEAD
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
......@@ -62,6 +114,11 @@ createBoat.prototype.reset=function()
this.x = this.orix;
this.y = this.oriy;
this.angle=-this.oriA*4;
=======
this.x = this.orix;
this.y = this.oriy;
this.angle=-this.oriA*4;
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
this.leftOarX=0;
this.leftOarY=0;
this.rightOarX=0;
......@@ -90,8 +147,27 @@ 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);
=======
this.body = world.CreateBody(polyBd);
this.body.SetCenterPosition(new b2Vec2(this.x,this.y),this.oriA);
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
}
createBoat.prototype.moveBoat= function(gp)
......@@ -216,10 +292,23 @@ createBoat.prototype.moveBoat= function(gp)
this.y=this.body.GetOriginPosition().y;
this.vangle=this.body.GetRotation();
<<<<<<< HEAD
}
createBoat.prototype.add_velocity = function(vel)
{
=======
}
createBoat.prototype.add_velocity = function(vel)
{
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
var b = this.body;
var v = b.GetLinearVelocity();
......@@ -264,6 +353,7 @@ createBoat.prototype.drawBoat= function()
// rotate(-(this.angle)/4); //rotating the boat
push();
<<<<<<< HEAD
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
// rect(-0,0,100, 100);
......@@ -286,6 +376,34 @@ createBoat.prototype.drawBoat= function()
// 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(!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();
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
pop();
push();
......@@ -310,6 +428,57 @@ createBoat.prototype.drawBoat= function()
line(this.rightStartPoint.x,this.rightStartPoint.y , this.rightEndPoint.x,this.rightEndPoint.y );
pop();
this.body.SetLinearVelocity(new b2Vec2(0,0));
<<<<<<< HEAD
=======
}
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)
{
scenario();
push();
fill(0,10,153);
textSize(80);
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();
}
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
}
......@@ -37,6 +37,7 @@ Soccer.prototype.check =function() {
// ellipse(ll,100,50,50);
if(this.body.GetOriginPosition().x<=ll-ll+38)
{
<<<<<<< HEAD
team2+=1;
applauseSound.play();
......@@ -85,6 +86,57 @@ Soccer.prototype.check =function() {
}
=======
if(sCheck)
{
boat[2].score+=1;
}
else
boat[1].score+=1;
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;
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);
}
}
function GoalText(a,b,c)
{
push();
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();
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
}
function GoalText(a, b, c) {
......@@ -121,12 +173,16 @@ waterStream.prototype.move=function()
if(this.y>=hght)
{
<<<<<<< HEAD
this.x=random(20,860);
this.y= -300;
}
}
=======
}
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
waterStream.prototype.draw=function()
{
......
......@@ -34,12 +34,21 @@ var paused;
var nearToWin;
var smallFactor;
//streamWater
<<<<<<< HEAD
var i, j; //stream water
var finishline = false;
var pCheck, sCheck, s1Check;
var img, bimg, wimg;
var boat0, boat1;
var V, P;
=======
var i,j; //stream water
var finishline=false;
var pCheck,sCheck,s1Check;
var img,bimg,wimg;
var boat0,boat1;
var V,P;
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
var allowed;
var world;
var groundBdy;
......@@ -78,6 +87,7 @@ function setup() {
applauseSound = new Howl( {urls:['appl.wav']});
backSound= new Howl( {urls:['back.wav'] ,loop:true}).play();
damping = 0.9;
<<<<<<< HEAD
stream = 0;
sSpeed = 0.8;
s1Check = true;
......@@ -102,6 +112,32 @@ function setup() {
bimg[0] = loadImage("boat0.png");
bimg[1] = loadImage("boat1.png");
wimg = loadImage("water.png");
=======
stream=0;
sSpeed=0.8;
s1Check=true;
viewYU=0;
viewYD=9600;
allowed = true;
pCheck=false;
sCheck=false;
prevPress=false,currPress=false;
setupWorld();
smallFactor1=0.7;
simg=loadImage("soc.png");
socbal = new Soccer();
water=[];
for (var i = 0; i < 25; i++) {
water.push(new waterStream());
}
bimg=[];
img = loadImage("rock.png");
bimg[0]=loadImage("boat0.png");
bimg[1]=loadImage("boat1.png");
wimg=loadImage("water.png");
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
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]]
}
......@@ -132,6 +168,7 @@ function draw() {
prevPress = false;
}
}
<<<<<<< HEAD
if (gp.buttons[0].pressed)
allowed = true;
......@@ -162,8 +199,90 @@ function draw() {
pauseMenu(gp);
}
=======
if(gp.buttons[0].pressed)
allowed=true;
if(allowed)
{
if(paused)
{
if(sCheck)
{
world.Step( 1/45,1);
background(150);
fill(50);
scenario();
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();
socbal.check();
// windowAdjustment();
}
else{
world.Step( 1/45,1);
background(150);
fill(50);
scenario();
boat[0].drawBoat();
boat[1].drawBoat();
boat[0].moveBoat(gamepads[0]);
boat[1].moveBoat(gamepads[1]);
// boat[0].moveView();
// boat[1].moveView();;
socbal.drawBall();
socbal.check();
// windowAdjustment();
}
testing();
frameC++;
elapsed = millis() - startTime;
text("FPS: " + fps,100,100);
if (elapsed > 1000) {
fps = frameC;
startTime = millis();
frameC = 0;
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
}
}
<<<<<<< HEAD
=======
else
{
pauseMenu(gp);
}
}
}
}
function pauseMenu(gp)
{
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
}
......@@ -261,7 +380,13 @@ function scenario() {
rect(ll - 30, 0, 30, 2300);
rect(rl, 0, 30, 2300);
<<<<<<< HEAD
}
=======
// rect(ll-30,height/2-115,30,230);
// rect(rl,height/2-115,30,230);
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
function testing() {
if (sPoint == 0) {
......@@ -295,7 +420,75 @@ function testing() {
}
<<<<<<< HEAD
function startMenu(gp) {
=======
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(controllers[0].axes[0],50,50);
// text(controllers[0].axes[1],50,80);
// strokeWeight(1);
// text(boat.x.toFixed(2) + ", " + boat.y.toFixed(2), 50, 170);
// text("ViewYU " + viewYU.toFixed(0), 50, 200);
// text("ViewYD " +viewYD.toFixed(0), 50, 230);
// text(degrees((boat.angle)/4).toFixed(2), 50, 260);
// text("boat 0 + " +boat[0].x.toFixed(3) + " " +boat[0].y.toFixed(3) ,50, 260);
// text("boat 1 + " + boat[1].x.toFixed(3) + " " +boat[1].y.toFixed(3) ,50, 290);
// text("your boat 0 strenth " + boat[0].score, 50, 320);
// text("your boat 1 strenth " + boat[1].score, 50, 350);
// text(rocks[0].pol.points[0].x+ " "+ rocks[0].pol.points[0].y,50,380);
// text("moving " + moving.toFixed(3), 50, 320);
// text ("sin" + sin((boat.angle)/4),50,350);
// text ("cos" + cos((boat.angle)/4),50,380);
// text (k,50,440);
// pop();
}
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
var
gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads : []);
......@@ -316,8 +509,63 @@ function startMenu(gp) {
sPoint = 3;
prevPress = false;
<<<<<<< HEAD
}
}
=======
sCheck=false;
}
//UP key Released
if(gp.buttons[0].pressed)
{
if(!sCheck)
{
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;
}
else
{
boat=[];
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 ;
// boat[1].x = 400;
// boat[1].y = height/2 ;
return true;
}
}
else{
push();
fill(125,12,15);
textSize(40);
text("2 Player" ,ll+300,(height/2)-100);
text("4 Player" ,ll+300,(height/2)-50);
if(!sCheck)
triangle(ll+270,(height/2)-110,ll+270,(height/2)-120,ll+290,(height/2)-110);
else
triangle(ll+270,(height/2)-60,ll+270,(height/2)-70,ll+290,(height/2)-60);
pop();
>>>>>>> 0260c3044e26947aa7c6c037cefe74f85233ad5f
if (gp.axes[6] == -1) {