class Bonus extends Moving { boolean outScreen = false; ArrayList bonuse = new ArrayList(); ArrayList bonusb = new ArrayList(); Bonuse bonuses; Bonusb bonusbs; PVector bonusplus = new PVector (-1, 0); Bonus(PVector pos) { super(pos); // call the constructor of the moving class radius = 20; } void update() { pos.add(bonusplus); // extra score if (player.score % 800 == 0 && bonuse.size()<1) { bonuse.add(new Bonuse(new PVector(800, random(100, 400)))); }// make a new object // arguments passed to the constructor set the initial values for (int i = 0; i < bonuse.size(); i++) { Bonuse e = bonuse.get(i); e.update(); if (e.outScreen == true) { bonuse.remove(i); //remove the object which out of screen } if (e.collision(player)) { //check collision player.getbonuse(); bonusemusic.play(0); bonuse.remove(i); } } // extra HP for (int i = 0; i < bonusb.size(); i++) { Bonusb b = bonusb.get(i); b.update(); if (b.outScreen == true) { bonusb.remove(i); } if (b.collision(player)) { player.getbonusb(); bonusbmusic.play(0); bonusb.remove(i); } } bonusbs = new Bonusb(new PVector(800, random(100, 400))); if (player.score % 1000 == 0 && bonusb.size()<1) { bonusb.add(bonusbs); } } }