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

First

parent 00c973a1
<?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 createBoat(x,y,angle){
this.x = 0,
this.y = 0,
this.orix=x,
this.oriy=y,
this.oriA=angle;
this.angle=angle,
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=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);
// this.body.SetAngularVelocity(radians(-180));
};
createBoat.prototype.reset=function()
{
this.x = this.orix;
this.y = this.oriy;
this.angle=0;
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=0;
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++) {
this.polySd.vertices[i].Set(points[i][0], points[i][1]);
}
var polyBd = new b2BodyDef();
polyBd.AddShape(this.polySd);
polyBd.position.Set(this.x,this.y);
this.body = world.CreateBody(polyBd);
}
createBoat.prototype.moveBoat= function(gp)
{
//find left oar
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];
// calculate movement
if (this.leftIn) {
dLeft = this.prevLeftOarY - this.leftOarY;
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;
}
else
{
(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)
{
(this.angle)-=temp;
}
else
{
(this.angle)+=temp;
}
}
this.velocity += dRight / 50;
}
this.prevLeftOarY = this.leftOarY;
this.prevRightOarY = this.rightOarY;
this.prevRightOarX = this.rightOarX;
this.prevLeftOarX = this.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*50,this.vy*50));
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)))/15);
}
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, (-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();
pop();
push();
translate(ll+this.x*smallFactor,(-viewYU+this.y)*smallFactor);
rotate(this.vangle);
strokeWeight(5);
if (this.leftOarX*smallFactor > -100*smallFactor) {
stroke(100);
this.leftIn = false;
} else {
stroke(0);
this.leftIn = true;
}
line(-75*smallFactor1, 0, this.leftOarX*smallFactor1, this.leftOarY*smallFactor1);
if (this.rightOarX*smallFactor < 101*smallFactor) {
stroke(100);
this.rightIn = false;
} else {
stroke(0);
this.rightIn = true;
}
line(40*smallFactor1, 0, this.rightOarX*smallFactor1, this.rightOarY*smallFactor1);
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(gp)
{
push();
fill(0,10,153);
textSize(80);
text("Congratulations " + (gp.index + 1) + " won" ,ll,height/2);
pop();
noLoop();
}
boat1.png

70.9 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>
/*
* 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)