ArrayList towers = new ArrayList();
ArrayList circleMonsters = new ArrayList();
ArrayList circleBosses = new ArrayList();
int copyMonster = monsters;
int squarePlacement [][] = new int[cols][rows];
int mousefindXPos, mousefindYPos;
Button[] b = new Button[cols*rows];
boolean sameTowerPlacement = false;
boolean allMonstersSpawned = false;
path = loadImage("http://i294.photobucket.com/albums/mm118/OnePieceKT7/hkhk-1.jpg");
for (int h = 0; h < 192; h++) {
for (int v = 0; v < rows; v++) {
for (int w = 0; w < cols; w++) {
squarePlacement[w][v] = u;
int xLocation (int x, int y) {
int buttonChoice = squarePlacement[x][y];
xpos = b[buttonChoice].rectX;
int yLocation (int x, int y) {
int buttonChoice = squarePlacement[x][y];
ypos = b[buttonChoice].rectY;
mousefindXPos = int(map(mouseX, 0, 640, 0, 16));
mousefindYPos = int(map(mouseY, 0, 480, 0, 12));
text("START IT!", 540, 465);
text("Lives:" + " " + nf(lives, 2), 100, 465);
text("Level:" + " " + nf(level, 2), 220, 465);
text("Money:" + " " + nf(money, 2), 340, 465);
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 16; j++) {
b[buttonNumber].showButton((20+(j*40)), (20+(i*40)));
circleBosses.add(new Circles(bossHealth));
for (int j = 0; j < circleBosses.size(); j++) {
if (circleBosses.size() > 0) {
((Circles)circleBosses.get(j)).circleMovement();
if (circleBosses.size() == 0) {
circleMonsters.add(new Circles(circleHealth));
for (int j = 0; j < circleMonsters.size(); j++) {
if (circleMonsters.size() > 0)
((Circles)circleMonsters.get(j)).circleMovement();
if (circleMonsters.size() == 0) {
for (int i=0; i<towers.size(); i++) {
((Tower)towers.get(i)).showTower();
((Tower)towers.get(i)).shoot();
for (int z = 0; z < towers.size(); z++) {
for (int z = 0; z < circleMonsters.size(); z++) {
circleMonsters.remove(z);
for (int z = 0; z < circleBosses.size(); z++) {
if ((mouseX >= 480 && mouseX <= 600) && (mouseY >= 440 && mouseY <= 480)) {
if (mousefindYPos < 11 && !(mousefindYPos == 1 && mousefindXPos < 15) && !(mousefindXPos == 14 && (mousefindYPos >= 1 && mousefindYPos <= 3 || mousefindYPos >= 5 && mousefindYPos <= 7)) &&
!(mousefindYPos == 3 && mousefindXPos < 15 && mousefindXPos >= 1) && !(mousefindYPos == 5 && mousefindXPos < 15 && mousefindXPos >= 1) && !(mousefindYPos == 7 && mousefindXPos < 15) && !(mousefindXPos == 1 && mousefindYPos == 4)) {
for (int x = 0; x < towers.size(); x++) {
if ( xLocation(mousefindXPos, mousefindYPos) == ((Tower)towers.get(x)).getX() && yLocation(mousefindXPos, mousefindYPos) == ((Tower)towers.get(x)).getY()) {
if (((Tower)towers.get(x)).upgrade && money >= 500) {
towers.add(new Tower(((Tower)towers.get(x)).getX(), ((Tower)towers.get(x)).getY(), false));
sameTowerPlacement = true;
sameTowerPlacement = false;
if (money >= 250 && !sameTowerPlacement) {
towers.add(new Tower(xLocation(mousefindXPos, mousefindYPos), yLocation(mousefindXPos, mousefindYPos), true));
text("GAME OVER", 320, 200);
color rColor, bColor, highlighter, rRed, cColor;
boolean rectOver = false;
highlighter = color(175, 100);
rRed = color(#278AA8, 25);
void showButton (int x, int y) {
xPos = findXPos(mouseX, mouseY);
yPos = findYPos(mouseX, mouseY);
if (mousefindYPos < 11 && !(mousefindYPos == 1 && mousefindXPos < 15) && !(mousefindXPos == 14 && (mousefindYPos >= 1 && mousefindYPos <= 3 || mousefindYPos >= 5 && mousefindYPos <= 7)) &&
!(mousefindYPos == 3 && mousefindXPos < 15 && mousefindXPos >= 1) && !(mousefindYPos == 5 && mousefindXPos < 15 && mousefindXPos >= 1) && !(mousefindYPos == 7 && mousefindXPos < 15) && !(mousefindXPos == 1 && mousefindYPos == 4)) {
rect(rectX, rectY, rectSize, rectSize);
void update (int x, int y) {
if (overRect(rectX, rectY, rectSize, rectSize)) {
if (mousePressed && rectOver) {
int findXPos (int x, int y) {
if (mousePressed && rectOn) {
int findYPos (int x, int y) {
if (mousePressed && rectOn) {
boolean overRect (int x, int y, int width, int height)
if (mouseX > x-20 && mouseX <= x+20 && mouseY > y-20 && mouseY <= y+20) {
circle = loadImage("http://i294.photobucket.com/albums/mm118/OnePieceKT7/Boss.png");
circle = loadImage("http://i294.photobucket.com/albums/mm118/OnePieceKT7/Monster.png");
if (xpos < 580 && xLine) {
else if (xpos > 60 && xLine2) {
else if (ypos < 220 && ypos >= 140) {
else if (ypos < 300 && ypos >= 220) {
image(circle, 0, 0, 40, 25);
circleBosses.remove(this);
circleMonsters.remove(this);
circleBosses.remove(this);
circleMonsters.remove(this);
PVector loc = new PVector();
Bullet (float x, float y) {
turret = new PVector(loc.x, loc.y);
void run(float x, float y) {
center = new PVector(xDir, yDir);
PVector velocity = PVector.sub(center, turret);
loc.add(new PVector(velocity.x/2, velocity.y/2));
PVector location = new PVector();
Tower (float x, float y, boolean upgradable) {
bullets = new ArrayList();
towers = loadImage("http://i294.photobucket.com/albums/mm118/OnePieceKT7/upgraded.png");
towers = loadImage("http://i294.photobucket.com/albums/mm118/OnePieceKT7/vehicle-tower-defense-3.png");
for (int i=0; i < circleMonsters.size(); i++) {
if (dist(((Circles)circleMonsters.get(0)).xpos, ((Circles)circleMonsters.get(0)).ypos, location.x, location.y) < inReach) {
angle = atan2((((Circles)circleMonsters.get(0)).ypos)-location.y, (((Circles)circleMonsters.get(0)).xpos)-location.x);
aX = (r * cos(angle)) + location.x;
aY = (r * sin(angle)) + location.y;
image(towers, location.x, location.y);
translate(location.x, location.y+1);
if (circleBosses.size() > 0) {
if (dist(((Circles)circleBosses.get(0)).xpos, ((Circles)circleBosses.get(0)).ypos, location.x, location.y) < inReach) {
bullets.add(new Bullet(location.x, location.y));
for (int k=0; k<bullets.size(); k++) {
image(towers, location.x, location.y);
((Bullet)bullets.get(k)).run(aX, aY);
translate(location.x, location.y);
if (dist(((Circles)circleBosses.get(0)).xpos, ((Circles)circleBosses.get(0)).ypos, ((Bullet)bullets.get(k)).loc.x, ((Bullet)bullets.get(k)).loc.y) < 25) {
((Circles)circleBosses.get(0)).upgradeDamage();
((Circles)circleBosses.get(0)).damage();
else if (((Bullet)bullets.get(k)).loc.x > width || ((Bullet)bullets.get(k)).loc.x < 0 || ((Bullet)bullets.get(k)).loc.y > height || ((Bullet)bullets.get(k)).loc.y < 0) {
if (circleMonsters.size() > 0) {
if (dist(((Circles)circleMonsters.get(0)).xpos, ((Circles)circleMonsters.get(0)).ypos, location.x, location.y) < inReach) {
bullets.add(new Bullet(location.x, location.y));
for (int k=0; k<bullets.size(); k++) {
image(towers, location.x, location.y);
((Bullet)bullets.get(k)).run(aX, aY);
translate(location.x, location.y);
if (dist(((Circles)circleMonsters.get(0)).xpos, ((Circles)circleMonsters.get(0)).ypos, ((Bullet)bullets.get(k)).loc.x, ((Bullet)bullets.get(k)).loc.y) < 25) {
((Circles)circleMonsters.get(0)).damage();
else if (((Bullet)bullets.get(k)).loc.x > width || ((Bullet)bullets.get(k)).loc.x < 0 || ((Bullet)bullets.get(k)).loc.y > height || ((Bullet)bullets.get(k)).loc.y < 0) {