Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- size (800, 600);
- background = loadImage("Background.jpg");
- Ballimage=loadImage("ball.png");
- }
- PImage background;
- PImage Ballimage;
- float time;
- float interval;
- int last=0;
- class Bubble {
- float ballsize;
- PImage Ballimage;
- float randomx =random(width);
- float randomy=random(height);
- float timestart;
- }
- ArrayList<Bubble>bubbles= new ArrayList(10);
- ArrayList<Bubble>toRemove=new ArrayList();
- void draw() {
- background(0);
- image (background, 0, 0, width, height);
- time=time+1;
- for (Bubble bub : bubbles) {
- bub.ballsize=50-(50*sin(((0.5)*(bub.timestart-time))/7)+50);
- //above is just a function that controlss the size of the bubbles appearing on screen
- image(Ballimage, bub.randomx-bub.ballsize/2, bub.randomy-bub.ballsize/2, bub.ballsize, bub.ballsize);
- if (bub.ballsize<1) {
- toRemove.add (bub);
- }
- }
- bubbles.removeAll(toRemove);
- toRemove.clear();
- if (millis() - last > 1000) {
- last=millis();
- while (true) {
- Bubble bub = new Bubble();
- bub.timestart=time;
- boolean clash = false;
- if (bub.randomx<50 || bub.randomx>width-50||bub.randomy<50||bub.randomy>height-50) {
- clash=true;
- }
- for (Bubble b : bubbles) {
- if (100>dist(b.randomx, b.randomy, bub.randomx, bub.randomy)) {
- clash = true;
- }
- }
- if (!clash) {
- if (bubbles.size()<10) {
- bubbles.add(bub);
- return;
- }
- }
- }
- }
- }
- void mouseClicked() {
- Bubble b = null;
- float minDist = Float.MAX_VALUE;
- for (Bubble b2 : bubbles) {
- float d = dist(b2.randomx, b2.randomy, mouseX, mouseY);
- if (d < minDist) {
- minDist = d;
- b = b2;
- }
- }
- if (b == null) {
- return;
- }
- if (minDist<b.ballsize/2) {
- toRemove.add (b);
- } else {
- println(b.ballsize, mouseX, mouseY);
- }
- bubbles.removeAll(toRemove);
- toRemove.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement