Commit 08645b40 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

V1

parent 5f61b41a
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Row</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.projects.webnature</nature>
</natures>
</projectDescription>
This diff is collapsed.
File added
function oars()
{
this.leftOarX=0,
this.leftOarY=0,
this.rightOarX=0,
this.rightOarY=0,
this.leftIn=false,
this.rightIn=false,
this.prevLeftOarY=0,
this.prevLeftOarX=0
}
function createBoat(x,y,id){
this.x = 0,
this.y = 0,
this.angle=0,
this.id=id,
this.velocity=0,
this.vx=0,
this.vy=0,
this.oar=[];
for(var i=0;i<2;i++)
this.oar[i]=new oars();
this.score=999;
this.max_hor_vel = 400;
this.max_ver_vel = 400;
this.vangle=0;
this.polySd = new b2PolyDef();
this.polySd.density = 0.8;
this.polySd.vertexCount = points.length;
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);
};
createBoat.prototype.moveBoat= function(gp)
{
for(var i=0;i<2;i++)
{
//find left oar
this.oar[i].leftOarX = 80 * gp[i+this.id*2].axes[1] - 100;
this.oar[i].leftOarY = 100 * gp[i+this.id*2].axes[0];
// find right oar
this.oar[i].rightOarX = 80 * gp[i+this.id*2].axes[3] + 100;
this.oar[i].rightOarY = 100 * gp[i+this.id*2].axes[2];
// calculate movement
if (this.oar[i].leftIn) {
dLeft = this.oar[i].prevLeftOarY - this.oar[i].leftOarY;
dUp = this.oar[i].prevLeftOarX - this.oar[i].leftOarX;
var v1=createVector(this.oar[i].prevLeftOarX,this.oar[i].prevLeftOarY);
var v2=createVector(this.oar[i].leftOarX,this.oar[i].leftOarY);
var temp=p5.Vector.angleBetween(v1,v2); // store the angle to be changed by boat
if(temp.toString()!="NaN")
{
if(this.oar[i].prevLeftOarY >this.oar[i].leftOarY)
{
(this.angle)+=temp;
}
else
{
(this.angle)-=temp;
}
}
this.velocity += dLeft / 50;
}
if (this.oar[i].rightIn) {
dRight = this.oar[i].prevRightOarY - this.oar[i].rightOarY;
dDown = this.oar[i].prevRightOarX - this.oar[i].rightOarX;
var v1=createVector(this.oar[i].prevRightOarX,this.oar[i].prevRightOarY);
var v2=createVector(this.oar[i].rightOarX,this.oar[i].rightOarY);
var temp=p5.Vector.angleBetween(v1,v2);
if(temp.toString()!="NaN")
{
if(this.oar[i].prevRightOarY >this.oar[i].rightOarY)
{
(this.angle)-=temp;
}
else
{
(this.angle)+=temp;
}
}
this.velocity += dRight / 50;
}
this.oar[i].prevLeftOarY = this.oar[i].leftOarY;
this.oar[i].prevRightOarY = this.oar[i].rightOarY;
this.oar[i].prevRightOarX = this.oar[i].rightOarX
this.oar[i].prevLeftOarX = this.oar[i].leftOarX
}
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.add_velocity(new b2Vec2(this.vx*25,this.vy*25));
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)
{
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(){
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;
body.SetAngularVelocity(((v.Length())*(tan(totalRotation)))/30);
}
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[this.id], (-170)*smallFactor,-200*smallFactor, bimg[this.id].width*smallFactor, bimg[this.id].height*smallFactor);
// 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();
for(var i=0;i<2;i++)
{
strokeWeight(5);
if (this.oar[i].leftOarX*smallFactor > -100*smallFactor) {
stroke(100);
this.oar[i].leftIn = false;
} else {
stroke(0);
this.oar[i].leftIn = true;
}
line((-75+10)*smallFactor, (-60+(i*210))*smallFactor, (this.oar[i].leftOarX+10)*smallFactor, (this.oar[i].leftOarY+(i*210))*smallFactor);
if (this.oar[i].rightOarX*smallFactor < 101*smallFactor) {
stroke(100);
this.oar[i].rightIn = false;
} else {
stroke(0);
this.oar[i].rightIn = true;
}
line((40-10)*smallFactor, (-60+(i*210))*smallFactor, (this.oar[i].rightOarX-10)*smallFactor, (this.oar[i].rightOarY+(i*210))*smallFactor);
}
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()
{
push();
fill(0,10,153);
textSize(80);
text("Congratulations " + (this.id + 1) + " won" ,ll,height/2);
pop();
noLoop();
}
boat0.png

73.9 KB

File added
boat1.png

72.5 KB

boat111.png

76.8 KB

var haveEvents = 'GamepadEvent' in window;
var controllers = {};
console.log("start script");
function connecthandler(e) {
console.log("Start add gamepad");
addgamepad(e.gamepad);
console.log("Added gamepad");
}
function addgamepad(gamepad) {
console.log("Gamepad index = " + gamepad.index);
controllers[gamepad.index] = gamepad;
console.log(gamepad.axes);
console.log("Finished add gamepad");
console.log("Controllers = " + controllers[0]);
}
function disconnecthandler(e) {
removegamepad(e.gamepad);
}
function removegamepad(gamepad) {
delete controllers[gamepad.index];
console.log("Finished remove gamepad");
}
function scangamepads() {
console.log("start scan");
var gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
for (var i = 0; i < gamepads.length; i++) {
if (gamepads[i]) {
if (!(gamepads[i].index in controllers)) {
addgamepad(gamepads[i]);
} else {
controllers[gamepads[i].index] = gamepads[i];
}
}
}
console.log("finished scan");
}
console.log("end script 1");
if (haveEvents) {
window.addEventListener("gamepadconnected", connecthandler);
window.addEventListener("gamepaddisconnected", disconnecthandler);
} else {
scangamepads();
setInterval(scangamepads, 500);
}
console.log("end script");
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="lib/prototype-1.6.0.2.js"></script>
<!-- box2djs -->
<script src='js/box2d/common/b2Settings.js'></script>
<script src='js/box2d/common/math/b2Vec2.js'></script>
<script src='js/box2d/common/math/b2Mat22.js'></script>
<script src='js/box2d/common/math/b2Math.js'></script>
<script src='js/box2d/collision/b2AABB.js'></script>
<script src='js/box2d/collision/b2Bound.js'></script>
<script src='js/box2d/collision/b2BoundValues.js'></script>
<script src='js/box2d/collision/b2Pair.js'></script>
<script src='js/box2d/collision/b2PairCallback.js'></script>
<script src='js/box2d/collision/b2BufferedPair.js'></script>
<script src='js/box2d/collision/b2PairManager.js'></script>
<script src='js/box2d/collision/b2BroadPhase.js'></script>
<script src='js/box2d/collision/b2Collision.js'></script>
<script src='js/box2d/collision/Features.js'></script>
<script src='js/box2d/collision/b2ContactID.js'></script>
<script src='js/box2d/collision/b2ContactPoint.js'></script>
<script src='js/box2d/collision/b2Distance.js'></script>
<script src='js/box2d/collision/b2Manifold.js'></script>
<script src='js/box2d/collision/b2OBB.js'></script>
<script src='js/box2d/collision/b2Proxy.js'></script>
<script src='js/box2d/collision/ClipVertex.js'></script>
<script src='js/box2d/collision/shapes/b2Shape.js'></script>
<script src='js/box2d/collision/shapes/b2ShapeDef.js'></script>
<script src='js/box2d/collision/shapes/b2BoxDef.js'></script>
<script src='js/box2d/collision/shapes/b2CircleDef.js'></script>
<script src='js/box2d/collision/shapes/b2CircleShape.js'></script>
<script src='js/box2d/collision/shapes/b2MassData.js'></script>
<script src='js/box2d/collision/shapes/b2PolyDef.js'></script>
<script src='js/box2d/collision/shapes/b2PolyShape.js'></script>
<script src='js/box2d/dynamics/b2Body.js'></script>
<script src='js/box2d/dynamics/b2BodyDef.js'></script>
<script src='js/box2d/dynamics/b2CollisionFilter.js'></script>
<script src='js/box2d/dynamics/b2Island.js'></script>
<script src='js/box2d/dynamics/b2TimeStep.js'></script>
<script src='js/box2d/dynamics/contacts/b2ContactNode.js'></script>
<script src='js/box2d/dynamics/contacts/b2Contact.js'></script>
<script src='js/box2d/dynamics/contacts/b2ContactConstraint.js'></script>
<script src='js/box2d/dynamics/contacts/b2ContactConstraintPoint.js'></script>
<script src='js/box2d/dynamics/contacts/b2ContactRegister.js'></script>
<script src='js/box2d/dynamics/contacts/b2ContactSolver.js'></script>
<script src='js/box2d/dynamics/contacts/b2CircleContact.js'></script>
<script src='js/box2d/dynamics/contacts/b2Conservative.js'></script>
<script src='js/box2d/dynamics/contacts/b2NullContact.js'></script>
<script src='js/box2d/dynamics/contacts/b2PolyAndCircleContact.js'></script>
<script src='js/box2d/dynamics/contacts/b2PolyContact.js'></script>
<script src='js/box2d/dynamics/b2ContactManager.js'></script>
<script src='js/box2d/dynamics/b2World.js'></script>
<script src='js/box2d/dynamics/b2WorldListener.js'></script>
<script src='js/box2d/dynamics/joints/b2JointNode.js'></script>
<script src='js/box2d/dynamics/joints/b2Joint.js'></script>
<script src='js/box2d/dynamics/joints/b2JointDef.js'></script>
<script src='js/box2d/dynamics/joints/b2DistanceJoint.js'></script>
<script src='js/box2d/dynamics/joints/b2DistanceJointDef.js'></script>
<script src='js/box2d/dynamics/joints/b2Jacobian.js'></script>
<script src='js/box2d/dynamics/joints/b2GearJoint.js'></script>
<script src='js/box2d/dynamics/joints/b2GearJointDef.js'></script>
<script src='js/box2d/dynamics/joints/b2MouseJoint.js'></script>
<script src='js/box2d/dynamics/joints/b2MouseJointDef.js'></script>
<script src='js/box2d/dynamics/joints/b2PrismaticJoint.js'></script>
<script src='js/box2d/dynamics/joints/b2PrismaticJointDef.js'></script>
<script src='js/box2d/dynamics/joints/b2PulleyJoint.js'></script>
<script src='js/box2d/dynamics/joints/b2PulleyJointDef.js'></script>
<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 src = "gamepad.js"></script>
<script language="javascript" src="scenario.js"></script>
<script language="javascript" src="boat.js "></script>
<script language="javascript" src="p5.js"></script>
<!-- uncomment lines below to include extra p5 libraries -->
<!--<script language="javascript" src="../addons/p5.dom.js"></script>-->
<!--<script language="javascript" src="../addons/p5.sound.js"></script>-->
<script>
</script>
<script language="javascript" src="touch.js"></script>
<!-- <script language="javascript" src="scenario.js"></script>-->
<!-- this line removes any default padding and style. you might only need one of these values set. -->
<style>
body {
padding: 0;
margin: 0;
overflow: hidden
}
</style>
</head>
<body>
</body>
</html>
File added
/*
* Copyright (c) 2006-2007 Erin Catto http:
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked, and must not be
* misrepresented the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
var ClipVertex = Class.create();
ClipVertex.prototype =
{
v: new b2Vec2(),
id: new b2ContactID(),
initialize: function() {
// initialize instance variables for references
this.v = new b2Vec2();
this.id = new b2ContactID();
//
}};
/*
* Copyright (c) 2006-2007 Erin Catto http:
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked, and must not be
* misrepresented the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// We use contact ids to facilitate warm starting.
var Features = Class.create();
Features.prototype =
{
//
set_referenceFace: function(value){
this._referenceFace = value;
this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceFace & 0x000000ff)
},
get_referenceFace: function(){
return this._referenceFace;
},
_referenceFace: 0,
//
set_incidentEdge: function(value){
this._incidentEdge = value;
this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00)
},
get_incidentEdge: function(){
return this._incidentEdge;
},
_incidentEdge: 0,
//
set_incidentVertex: function(value){
this._incidentVertex = value;
this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000)
},
get_incidentVertex: function(){
return this._incidentVertex;
},
_incidentVertex: 0,
//
set_flip: function(value){
this._flip = value;
this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000)