ArrayList buffType; class ItemObject extends Entity { Vector3D dir; int randTmp; ItemObject(Vector3D l, float s, int t, Vector3D d) { super(l, s, t); randTmp = (int)random(0, 6); dir = d.copy(); dir.limit(0.3f); } void run() { update(); borders(); collision(); render(); } void update() { loc.add(dir); } void borders() { if (loc.x <= 0) dir = new Vector3D(random(0, 1.f), random(-1f, 1f)); else if (loc.x >= width) dir = new Vector3D(random(-1f, 0), random(-1f, 1f)); else if (loc.y <= 0) dir = new Vector3D(random(-1f, 1f), random(0, 1.f)); else if (loc.y >= height) dir = new Vector3D(random(-1f, 1f), random(-1f, 0)); } void callEffect() { if (randTmp == 0) gack.dmgShield = new ThunderBall(gack.loc, 33.f, 3, 4f, 2800.f); else if (randTmp == 1) bigSplash.add(new IceExplode(gack.loc, 90f, 5, 400f)); else if (randTmp == 2) gack.dmgShield = new ThornShield(gack.loc, 33.f, 3, 4f, 4000.f); else if (randTmp == 3) gack.rocketLaunch(); else if (randTmp == 4) dmgObject.add(new PsyLoad(gack.loc, gack.vel, 0f, 2, 10f)); else if (randTmp == 5) { dmgObject.add(new WindBlast(gack.loc, new Vector3D(2, 2), 2.5f, 2, 10f, (3 * PI) / 4)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(-2, 2), 2.5f, 2, 10f, (5 * PI) / 4)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(2, -2), 2.5f, 2, 10f, (PI) / 4)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(-2, -2), 2.5f, 2, 10f, (7 * PI) / 4)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(2, 0), 2.5f, 2, 10f, PI / 2)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(0, 2), 2.5f, 2, 10f, PI)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(0, -2), 2.5f, 2, 10f, 0)); dmgObject.add(new WindBlast(gack.loc, new Vector3D(-2, 0), 2.5f, 2, 10f, (3 * PI) / 2)); } } void collision() { float d = loc.distance(loc,gack.loc); if (d >= 0 && d <= r + gack.r && gack.life > 0) { callEffect(); for (int i = floatingItems.size() - 1; i >= 0; i--) if (this == floatingItems.get(i)) { floatingItems.remove(i); break; } } } void render() { fill(0); stroke(200); pushMatrix(); translate(loc.x,loc.y); imageMode(CENTER); PImage type = (PImage)energySprite.get(randTmp); image(type, 0, 0); popMatrix(); } };