Help about a code with Processing as a library (IJ IDE)

Hello everybody !
Let 's start by a quick présentation because this is my first post.
I am learning slowly Java and i have start by processing there is a month and a half.
I achieved a game with 2 balls, each jumping and hitting the other, in processing.
A friend of mine is coaching me and ask me to start Object way to think… so i have refactorise my code.
That where troubles begun…

I have try to import ArrayList and ListIterator… and finally i have load processing.core as a library in my project.

I have already read a lot about this. Here a skeleton of my code.

import processing.core.PApplet;

public class MainClass extends PApplet {

    public static PApplet p;
    public static Game game;

        public static void main (String... args) {
            PApplet.main("MainClass", args);
            game = new Game();

    public void settings(){
            p = this;
        smooth(); // Lissage des dessins

    public void draw(){
        //background(0,0,0);// On dessine un fond noir

        noStroke(); // on supprime le contour




public class Game {
    public static Player player01;
    public static Player player02;

    public Game(){
    void generatePlayer(){
        player01= new Player("Helron",255,100,200);
        player02= new Player("Nico",125,200,100);

import java.awt.*;

public class Player {
    String name;
    int nbColor;
    int score;
    int startXcoordonate;
    int startYcoordonate;
    Point startPosition;

//    String upButton;
//    String downButton;
//    String rightButton;
//    String leftButton;
//    String hitButton;
    public static Ball ball;

    Player (String name, int nbColor, int startXcoordonate, int startYcoordonate){ = name;
        this.nbColor = nbColor;
        this.startXcoordonate = startXcoordonate;
        this.startYcoordonate = startYcoordonate;
        score = 0;
        startPosition = new Point(startXcoordonate, startYcoordonate);


    void generateBall( Point startPosition){

        ball = new Ball(MainClass.p.color(nbColor), startPosition);
import java.awt.*;

public class Ball {

    int color;
    Point actualPosition;

    //Constructeur de la balle
    Ball (int color, Point actualPosition) {
        this.color    = color;
        this.actualPosition = actualPosition;


    //Dessin de la balle
    public void display() {
        MainClass.p.ellipse(actualPosition.x, actualPosition.y, 40, 40);

So here my problem… : i should have 4 balls… two of them are test, the other ones should be write and gray… and even if i comment game.player01.ball or game.player02.ball i still have a identical ball display.

Some how i am asking the draw 2 times the same thing… and i have no clue how to fix this.

Does somebody could help me please ?

1 Like

I need to change my way to access variables. The static mode is one of my probleme.

I’ll take the time to publish when it will work.

Hi @Helron – it looks like you were able to resolve your issue?

As you said, it isn’t clear why you used static inside player, here:

public static Ball ball;

A player’s ball is definitely not static – it has state.

My code is about to be too long to be post here…

At this point, my project import processing.core and my class game, player, ball are working.
on a new branch ( on my computer ) i am using swing to create a setup screen and a splash screen.
As i ve already said, i am a beginer and the more i use “regular java”, the more i understand that it s weird to import processing.core…but still funny.

Here the repo of the project :slight_smile:

and here a video made for the “baccalaureat” :slight_smile:

1 Like

I post a diagram of how this little game works. Perhaps it can help somebody to understand how use processing or to have ideas…

Everycolum represent a variable. If you follow a life line you can find what happen to each ones.

Every box is a function ( white) or a method ( white ) or a condition ( green ).

This diagram show you

  • a physical engine to simulate gravity
  • collision system using Pvector
  • a keyboard evenement management
  • a glowing visual effect
  • a simple change of ellypse color
  • how to use a layer with a 50 % opacity to clear progressively a scene, creating a nice and smooth visual effect.
    diagram PinkPurpleFight

Thanks for sharing this!

This is my last post in this topic because it s far from the original question. There is no more “baccalaureat” so i can share my work to help.

Here…sorry it s in French …The final report of this project. I am sure it s a good exemple for those who are learning. It contains the entire code, exept images. If you want to make it work. Just paste and copy. Delete Title section ( Setup, Draw…etc…)

1 Like

Thank you so much for sharing this!

If you would like to make your code available to others as an exampe to learn from, consider posting the files as a GitHub repository.

1 Like