class Cannon implements Entity { final int framesBetweenSpawns = 3; float x, y, radius, strength; int lastSpawnTime = -framesBetweenSpawns; boolean flip; /* Bumper(float x, float y, float radius, float strength) { this.x = x; this.y = y; this.radius = radius; this.strength = strength; }*/ Cannon(float x, float y, float strength) { this.x = x; this.y = y; this.radius = cannonAnimation.w*2; this.strength = strength; this.flip = false; } Cannon(float x, float y, float strength, boolean flip) { this(x,y,strength); this.flip = flip; } void doPhysics0() { } void doPhysics1() { boolean spawnBomb = false; for (int i = 0; i < theBouncies.size(); ++ i) { Bouncy h = (Bouncy)theBouncies.get(i); float d = dist(h.x, h.y, x, y); if (d < radius + h.collisionRadius) { playSound(bumperhit); float []push = elasticCollision(h.x - x, h.y - y, h.vX, h.vY, strength); h.push(push[0], push[1]); spawnBomb = true; } } if (spawnBomb && t-lastSpawnTime > framesBetweenSpawns) { lastSpawnTime = t; int xoff = 30; if (flip) xoff = -30; Bomb b = new Bomb((int)x+xoff,(int)y-30); b.vX = 5; b.vY = -5; if (flip) b.vX = -5; b.addToLevel(); } } void draw() { /* stroke(0, 0, 0); if (t - lastBumpTime < bumpNFramesVisible) fill(255, 200, 200); else fill(200, 200, 200); ellipse(x, y, radius * 2, radius * 2); */ cannonAnimation.displayCentered(x,y,t,true,4,flip); } void addToLevel() { theEntities.add(this); } void levelStart() { x += leftBorder; } }