yono38 / leapmotion-fruitninja Goto Github PK
View Code? Open in Web Editor NEWA simple fruitninja clone built in Processing to interface with the Leap Motion Controller
A simple fruitninja clone built in Processing to interface with the Leap Motion Controller
I believe this needs to be updated for the Leap Motion SDK 0.7.7 because I can't find the files needed from the SDK. The only files I could find in the SDK were LeapPython.so, libLeap.so, and libLeapJava.so. As a result, when I run Fruit_Ninja.pde, I don't see anything displayed on-screen, and the cursor is changed to a crosshair until I close the program.
import pbox2d.;
import org.jbox2d.collision.shapes.;
import org.jbox2d.common.;
import org.jbox2d.dynamics.;
ArrayList fingerPositions = new ArrayList();
PBox2D e; // this is our world
ArrayList theFruits;
ArrayList theSplashes;
int level = 0;
SampleListener listener;
Controller controller;
PImage backgroundImage;
int swipeR, swipeG, swipeB;
void setup()
{
size(displayWidth, displayHeight, OPENGL);
theFruits = new ArrayList();
theSplashes = new ArrayList();
// this sets up the box2d physics engine to deal with us
e = new PBox2D(this);
e.createWorld();
e.setGravity(0, -20);
// Create a sample listener and assign it to a controller to receive events
listener = listener = new SampleListener();
controller = new Controller(listener);
backgroundImage = loadImage("Background.png");
swipeR = int(random(200, 255));
swipeG = int(random(200, 255));
swipeB = int(random(200, 255));
}
void draw()
{
swipeR += random(-5, 5);
swipeG += random(-5, 5);
swipeB += random(-5, 5);
swipeR = constrain(swipeR, 200, 255);
swipeG = constrain(swipeG, 200, 255);
swipeB = constrain(swipeB, 200, 255);
background(0);
tint(255);
image(backgroundImage, 0, 0, width, height);
fill(255);
stroke(swipeR, swipeG, swipeB);
strokeJoin(ROUND);
strokeCap(ROUND);
if ((listener.lastPos != null && listener.connected) || !listener.connected) {
// remove the last position if fingerPositions has more than 20 positions
if (fingerPositions.size() > 20) fingerPositions.remove(fingerPositions.size() - 1);
Vector lastPos;
if (listener.connected) {
// add the new position at index 0
lastPos = listener.lastPos;
}
else {
lastPos = new Vector(mouseX / (float)(width) * 400 - 200, (height - mouseY) / (float)(height) * 600, 0);
}
fingerPositions.add(0, lastPos);
for (int i = 0; i < fingerPositions.size() - 1; i++) {
Vector fingerPos1 = fingerPositions.get(i);
Vector fingerPos2 = fingerPositions.get(i+1);
float normalizedX1 = (float)(fingerPos1.getX() + 200) / 400 * width;
float normalizedY1 = height - (float)(fingerPos1.getY()) / 600 * height;
float normalizedX2 = (float)(fingerPos2.getX() + 200) / 400 * width;
float normalizedY2 = height - (float)(fingerPos2.getY()) / 600 * height;
//ellipse(normalizedX, normalizedY, fingerPositions.size() - i, fingerPositions.size() - i);
strokeWeight(fingerPositions.size() - i);
line(normalizedX1, normalizedY1, normalizedX2, normalizedY2);
}
}
e.step(); // advances the physics engine one frame
ArrayList splashesToRemove = new ArrayList();
for (Splash splash: theSplashes)
{
splash.display();
// remove splashes if their counter > 255
if (splash.counter > 255) splashesToRemove.add(splash);
}
for (Splash splash: splashesToRemove) theSplashes.remove(splash);
for (Fruit fruit: theFruits)
{
fruit.display();
}
// remove the fruits that are off the screen
ArrayList fruitsToRemove = new ArrayList();
for (Fruit fruit: theFruits) {
Vec2 position = e.coordWorldToPixels(fruit.body.getPosition());
if (position.y > height*2 && fruit.body.getLinearVelocity().y < 0) {
fruitsToRemove.add(fruit);
}
}
for (Fruit fruitToRemove: fruitsToRemove) {
fruitToRemove.killBody();
theFruits.remove(fruitToRemove);
}
fruitsToRemove.clear();
// check if the swipe intersects any of the fruits.. if so, remove them and add splash
for (Fruit fruit: theFruits) {
if ((listener.hasHands || (!listener.connected)) && fingerPositions.size() > 0) {
Vector fingerPos = fingerPositions.get(0);
Vec2 fruitPosition = e.coordWorldToPixels(fruit.body.getPosition()); // center of fruit
float fingerPosX = (float)(fingerPos.getX() + 200) / 400 * width;
float fingerPosY = height - (float)(fingerPos.getY()) / 600 * height;
float spriteSize = fruit.fruitSprite.width; // width and height are same
if (fingerPosX > fruitPosition.x - spriteSize/2.0 && fingerPosX < fruitPosition.x + spriteSize/2.0 && fingerPosY > fruitPosition.y - spriteSize/2.0 && fingerPosY < fruitPosition.y + spriteSize/2.0) {
// swiped!
println("SWIPED!");
fruitsToRemove.add(fruit);
}
}
}
for (Fruit fruitToRemove: fruitsToRemove) {
Vec2 fruitPosition = e.coordWorldToPixels(fruitToRemove.body.getPosition());
// add splash
Splash splash = new Splash(fruitToRemove.fruitName(), fruitPosition);
theSplashes.add(splash);
fruitToRemove.killBody();
theFruits.remove(fruitToRemove);
}
// new level
if (theFruits.size() == 0) {
// increment the level... add fruits
level++;
int numFruits = (int)random(1, 6);
for (int i = 0; i < numFruits; i++) {
int randomX = int(random(0, width));
int impulseX = int(random(0, width));
if (randomX > width/2) impulseX *= -1;
Fruit p = new Fruit(randomX, height + 20);
theFruits.add(p);
p.body.applyAngularImpulse(0.5);
p.body.applyLinearImpulse(new Vec2(impulseX, random(height * 2, height * 3)), e.getBodyPixelCoord(p.body));
}
}
}
currently running processing 2.0b7, just wondering what you developed this in. i'm having some issues running it.
Hey all
After many tries, I can't get this app to launch. It runs and then promptly crashes, giving me the error:
Native code library failed to load.
java.lang.UnsatisfiedLinkError: no LeapJava in java.library.path
I've tried and retried adding the file, but nothing seems to work.
Any ideas?
"Cannot find a class or type named "HandArray""
Where is it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.