Game from Japan

import fisica.*;
FWorld world;
FBox paddle;
FCircle ball;
int score=0;

void setup() {
  size(600, 600, P3D);
  noStroke();
  textAlign(CENTER);
  textSize(50);
  Fisica.init(this);
  world=new FWorld();
  world.setGravity(0, 0);
  world.setEdges(0, 0, width, height);
  world.remove(world.bottom);

  for (int i=0; i<8; i++) {
    for (int j=0; j<5; j++) {
      FBox box=new FBox( 60, 20);
      box.setFill(j*50, j, 150);
      box.setPosition(i*70+50, 30*j+30);
      box.setStatic(true);
      box.setFriction(0);
      box.setRestitution(1);
      box.setName("block");
      world.add(box);
    }
  }

  paddle=new FBox(70, 30);
  paddle.setStatic(true);
  paddle.setFriction(0);
  paddle.setRestitution(1);
  paddle.setFill(30,140,180);
  paddle.setName("paddle");
  world.add(paddle);

  ball=new FCircle(20);
  ball.addForce(10000,20000);
  ball.setDamping(0);
  ball.setPosition(width/2, height/2);
  ball.setName("ball");
  ball.setFriction(0);
  ball.setRestitution(1);
  world.add(ball);
}

void draw() {
  background(0);
  
  camera(width/2+width/2-mouseX,800+height/2-mouseY,500,width/2,height/2,0,0,1,0);
  
  paddle.setPosition(mouseX, 550);
  //world.draw();
  if(ball.getY()>=height){
    fill(255,0,0);
    pushMatrix();
    camera(width/2,height/2,500,width/2,height/2,0,0,1,0);
    text("GameOver",width/2,height/2);
    popMatrix();
  }
  
  pushMatrix();
  fill(0,200,0);
  camera(width/2,height/2,500,width/2,height/2,0,0,1,0);
  text("Score:"+score,500,100);
  popMatrix();
  world.step();
  
  ArrayList<FBody>bodies=world.getBodies();
  for(FBody b:bodies){
    if(b.getName()=="ball"){
      
      ArrayList<FContact>contacts=b.getContacts();
      for(FContact c:contacts){
        if(c.getBody1().getName()=="block"){
          world.remove(c.getBody1());
          score+=1;
        }
        if(c.getBody2().getName()=="block"){
          world.remove(c.getBody2());
          score+=1;
        }
      }
    }
    if (b instanceof FBox){
      draw3DBox((FBox)b);
    }
    if(b instanceof FCircle){
      draw3DCircle((FCircle)b);
    }
  }
}

void draw3DBox(FBox b){
  pushMatrix();
  fill(b.getFillColor());
  stroke(100);
  translate(b.getX(),b.getY());
  box(b.getWidth(),b.getHeight(),40);
  popMatrix();
}

void draw3DCircle(FCircle c){
  pushMatrix();
  fill(c.getFillColor());
  noStroke();
  translate(c.getX(),c.getY());
  sphere(c.getSize());
  popMatrix();
}
4 Likes