We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm still new to processing :( having a big issue
I have add image into here, I'm trying to add the score counter when the image catch the ball will increase the score but not dropping off the window only increase the score...
import shiffman.box2d.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
short count, dim = 150;
int num = 0;
PFont counter;
final static short POS = 25, FPS = 50, BOLD = 2;
final static color // BG = #C04000,
FG = #10BA93, BORDER = -1;
PImage photo;
// A reference to our box2d world
Box2DProcessing box2d;
// A list we'll use to track fixed objects
ArrayList<Boundary> boundaries;
// A list for all of our rectangles
ArrayList<CustomShape> polygons;
ArrayList<Ball> balls;
int missed =0;
void setup() {
size(1000,600);
smooth();
counter = createFont("Arial", 50, true);
photo = loadImage("2-01.png");
// Initialize box2d physics and create the world
box2d = new Box2DProcessing(this);
box2d.createWorld();
// We are setting a custom gravity
box2d.setGravity(0, -10);
// Create ArrayLists
balls = new ArrayList<Ball>();
boundaries = new ArrayList<Boundary>();
polygons = new ArrayList<CustomShape>();
// Add a bunch of fixed boundaries
// b1
Boundary b1 = new Boundary(100f, 100f, 150f, 10f, radians(35));
boundaries.add(b1);
// b2
Boundary b2 = new Boundary(300f, 100f, 150f, 10f, radians(-35));
boundaries.add(b2);
//right side
Boundary rightSide = new Boundary(width-5,height/2,10,height,0);
rightSide.setRotation(-PI/11);
boundaries.add(rightSide);
// left sides
Boundary leftSide = new Boundary(5,height/2,10,height,0);
leftSide.setRotation(PI/11);
boundaries.add(leftSide);
}
void draw() {
background(255);
// We must always step through time!
box2d.step();
// Display all the boundaries
for (Boundary wall: boundaries) {
//wall.setRotation(PI/6);
wall.display();
}
// Display all the people
{
//for (Ball b: balls)
for (int i=0; i<balls.size(); i++)
{
//important
Ball b = balls.get(i);
b.display();
Vec2 pos = box2d.getBodyPixelCoord(b.body);
image(photo,mouseX,500);
if(b.done())
{
missed++;
balls.remove(i);
println("ball missed:"+missed);
createBall();
}
}
}
for (CustomShape cs: polygons) {
cs.display();
}
fill(FG);
ellipse(80, 80, 80, 80);
textFont(counter, 45); // Specify font to be used
fill(#5D5D5D); // Specify font color
text(nf(missed, 1), 60, 95); // Display Text and Location
}
void createBall()
{
Ball b = new Ball(random(0, width), 0);
balls.add(b);
}
void mousePressed() {
createBall();
}