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

**URL:** <https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319>\
**Category:** Coding Questions\
**Created:** [April 1, 2020, 10:48pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319 "2020-04-01T22:48:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helron](https://avatars.discourse-cdn.com/v4/letter/h/cab0a1/32.png) [@Helron](https://discourse.processing.org/u/Helron)\
**Post date:** [April 1, 2020, 10:48pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/1 "2020-04-01T22:48:36Z")

</div>

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.

```auto
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
        size(800,400);

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

        noStroke(); // on supprime le contour

        ellipse(400,200,40,40);
        ellipse(300,50,40,40);

        game.player01.ball.display();
        game.player02.ball.display();
        }

}

```

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

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

}

```

```auto
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){
        this.name = name;
        this.nbColor = nbColor;
        this.startXcoordonate = startXcoordonate;
        this.startYcoordonate = startYcoordonate;
        score = 0;
        startPosition = new Point(startXcoordonate, startYcoordonate);
        generateBall(startPosition);

    }

    void generateBall( Point startPosition){

        ball = new Ball(MainClass.p.color(nbColor), startPosition);
    }
}

```

```auto
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.fill(MainClass.p.color(color));
        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 ?

---

<div class="post-metadata">

**Author:** ![Helron](https://avatars.discourse-cdn.com/v4/letter/h/cab0a1/32.png) [@Helron](https://discourse.processing.org/u/Helron)\
**Post date:** [April 2, 2020, 4:42pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/2 "2020-04-02T16:42:20Z")

</div>

Hello,  
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.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 5, 2020, 5:17pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/3 "2020-04-05T17:17:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Helron](https://avatars.discourse-cdn.com/v4/letter/h/cab0a1/32.png) [@Helron](https://discourse.processing.org/u/Helron)\
**Post date:** [April 5, 2020, 8:39pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/4 "2020-04-05T20:39:47Z")

</div>

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 🙂

> **[Helron1977/Helron1977-PinkPurple](https://github.com/Helron1977/Helron1977-PinkPurple)**
>
> PinkPurple game. Contribute to Helron1977/Helron1977-PinkPurple development by creating an account on GitHub.

and here a video made for the “baccalaureat” 🙂  
https://explee.com/embed/video/nk79879

---

<div class="post-metadata">

**Author:** ![Helron](https://avatars.discourse-cdn.com/v4/letter/h/cab0a1/32.png) [@Helron](https://discourse.processing.org/u/Helron)\
**Post date:** [April 16, 2020, 8:36pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/5 "2020-04-16T20:36:53Z")

</div>

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](https://drive.google.com/open?id=1jFgfL8MZr-x2uiqR9FITAj2wnu1wZMdE)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 16, 2020, 10:47pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/6 "2020-04-16T22:47:52Z")

</div>

Thanks for sharing this!

---

<div class="post-metadata">

**Author:** ![Helron](https://avatars.discourse-cdn.com/v4/letter/h/cab0a1/32.png) [@Helron](https://discourse.processing.org/u/Helron)\
**Post date:** [April 18, 2020, 2:36pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/7 "2020-04-18T14:36:31Z")

</div>

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…)

> **[Google Drive](https://drive.google.com/file/d/1p89CtXVjwtrsRJVgU0Q62AXBiyU8zELf/view?usp=drive_open)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 18, 2020, 2:41pm UTC](https://discourse.processing.org/t/help-about-a-code-with-processing-as-a-library-ij-ide/19319/8 "2020-04-18T14:41:15Z")

</div>

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.
