Dynamite screen clear game

Im trying to simulate a player pushing down ignition for dynamite to explode and clear the screen of bad guys but I cant figure out how to detect the rect reaching a certain point of the screen to clear it

here’s my code

Bombs[] bomb = new Bombs[2];

ArrayList enemies = new ArrayList();

PImage source;

void setup() {
size(600, 600);
noStroke();
// init them: (xPos, yPos, width, height)
bomb[0] = new Bombs(10, 520, 30, 15);
bomb[1] = new Bombs(70, 520, 30, 15);
}

void draw() {
background(100);

for (Bombs b : bomb) {
b.run();
}
}

void mousePressed() {

//lock if clicked
for (Bombs b : bomb) {
{
if (b.isOver())
b.lock = true;
}
}
}

void mouseReleased() {

//unlock
for (Bombs b : bomb) {
{
b.lock = false;
}
}
}

class Bombs {

float x, y, w, h;
float initialY;

boolean kill = true;
boolean lock = false;

// grabs coordinates from methods
Bombs (float _x, float _y, float _w, float _h) {

x=_x;
y=_y;
w=_w;
h=_h;

}

void run() {

fill(0);
//shaft
rect(x, 520, 10, 100);

handle();

}

// is mouse ove knob?
boolean isOver()
{
return (x+w >= mouseX) && (mouseX >= x) && (y+h >= mouseY) && (mouseY >= y);
}

void handle() {
//handle
fill(255, 0, 0);
rect(x-10, y, w, h);

//get mouseInput and map it
float my = constrain(mouseY, 520, height - h - initialY );
if (lock) y = my;

if (kill) {
    if ( h > source.height -10) {
      enemies.clear();
      kill = false;
    }
  }

}
}

Hi @boomstick55

Can you provide the full version of your code? It is hard to understand and see the problem if we can’t test it :confused:

Best regards

//call classes
Player player = new Player();
Screens screen = new Screens();

// array to hold all sliders
Bombs[] bomb = new Bombs[2];

//calls arrays and classes
ArrayList enemies = new ArrayList();
ArrayList bullets = new ArrayList();

//calls images
PImage playerSprite, enemySprite, source;

int i;
int score = 0;
int difficultySelect = 0;
int gameScreen = 0;

void setup() {
size(600, 600);
smooth();
noStroke();
noCursor();
cursor (CROSS);
ellipseMode(CENTER);
imageMode(CENTER);
frameRate(60);

//load and sets images
source = loadImage(“maptest.png”);

playerSprite = loadImage(“player.png”);
playerSprite.resize(50, 50);
player.playerPos.set(300, 570);

enemySprite = loadImage(“zombie.png”);
enemySprite.resize(50, 50);

//creates dynamite
bomb[0] = new Bombs(10, 520, 30, 15);
bomb[1] = new Bombs(70, 520, 30, 15);
}

void draw() {
background(source);

// Changes screen states
if (gameScreen == 0) {
screen.startScreen();
} else if (gameScreen == 1) {
screen.easygameplayScreen();
} else if (gameScreen == 2) {
screen.mediumgameplayScreen();
} else if (gameScreen == 3) {
screen.hardgameplayScreen();
} else if (gameScreen == 4) {
screen.gameOverScreen();
}
}

//player movement
void keyPressed() {
final int k = keyCode;
if (k == LEFT || k == ‘A’)
player.playerSpd.x = -player.playerVel;
else if (k == RIGHT || k == ‘D’)
player.playerSpd.x = player.playerVel;
}

void keyReleased() {
final int k = keyCode;
if ( (k == LEFT || k == ‘A’) && player.playerSpd.x < 0
|| (k == RIGHT || k == ‘D’) && player.playerSpd.x > 0 )
player.playerSpd.x = 0;
}

public void mousePressed() {

// depending on the screen clicking changes the state
if (gameScreen==0) {
screen.startGame();
}
if (gameScreen==4) {
screen.restart();
}
//locks handle if clicked
for (Bombs b : bomb) {
{
if (b.isOver())
b.lock = true;
}
}
}

void mouseReleased() {

//unlock
for (Bombs b : bomb) {
{
b.lock = false;
}
}
}

// remove bullets
void handleBullets() {
for ( int b = bullets.size(); b != 0; )
if ( bullets.get(–b).run() )
bullets.remove(b);
print(bullets.size() + “\t”);
}


class Bombs {

float x, y, w, h;
float initialY;

boolean kill = true;
boolean lock = false;

// grabs coordinates from methods
Bombs (float _x, float _y, float _w, float _h) {

x=_x;
y=_y;
w=_w;
h=_h;

}

void run() {

pushMatrix();
fill(0);
//draws shaft
rect(x, 520, 10, 100);

handle();
popMatrix();

}

// sees if mouse is over the handle
boolean isOver()
{
return (x+w >= mouseX) && (mouseX >= x) && (y+h >= mouseY) && (mouseY >= y);
}

void handle() {
//handle
fill(255, 0, 0);
rect(x-10, y, w, h);

//get mouseInput and map it
float my = constrain(mouseY, 520, height - h - initialY );
if (lock) y = my;

if (kill) {
  if ( h > source.height -10) {
    enemies.clear();
    kill = false;
  }
}

}
}

class Bullet extends PVector {

PVector vel;

// grab get player location and velocity from player
Bullet(PVector loc, PVector vel) {
super(loc.x, loc.y);
this.vel = vel;
}

// bullet shape
void display() {
final byte bulletSize = 4;
fill(255, 0, 0);
rect(x+15, y-30, bulletSize, 10);
}

// bullet speed
boolean update() {
add(vel);
return x > width || x < 0 || y > height || y < 0;
}

// move animation
boolean run() {
display();
return update();
}
}


class Bullet extends PVector {

PVector vel;

// grab get player location and velocity from player
Bullet(PVector loc, PVector vel) {
super(loc.x, loc.y);
this.vel = vel;
}

// bullet shape
void display() {
final byte bulletSize = 4;
fill(255, 0, 0);
rect(x+15, y-30, bulletSize, 10);
}

// bullet speed
boolean update() {
add(vel);
return x > width || x < 0 || y > height || y < 0;
}

// move animation
boolean run() {
display();
return update();
}
}


class Enemy {

float x, y;

// enemy spawns
Enemy() {
x = random(30, 550);
y = -40;
}

void difficutlySelect() {
}

// enemy speed
void easyMove() {
y = y + random(1, 3);
}

void mediumMove() {
y = y + random(2, 4);
}

void hardMove() {
y = y + random(3, 4);
}

//enemy image
void display() {
image(enemySprite, x, y);
}
}


class Enemy {

float x, y;

// enemy spawns
Enemy() {
x = random(30, 550);
y = -40;
}

void difficutlySelect() {
}

// enemy speed
void easyMove() {
y = y + random(1, 3);
}

void mediumMove() {
y = y + random(2, 4);
}

void hardMove() {
y = y + random(3, 4);
}

//enemy image
void display() {
image(enemySprite, x, y);
}
}


class Player {

final PVector playerPos = new PVector();
final PVector playerSpd = new PVector();
final byte playerVel = 3;
final static byte bulletVel = 3;
float angle = 0;
float targetAngle = 0;
float easing = 0.05f;

// playe movement
void movePlayer() {
playerPos.add(playerSpd);
if (playerPos.x > width )
playerPos.x = width;
else if (playerPos.x < 0)
playerPos.x = 0;
else if (playerPos.x > 500)
playerPos.x = 500;
}

// player image
void displayPlayer() {

// sets angle
angle = atan2(playerPos.y - mouseY, playerPos.x - mouseX);

float dir = (angle - targetAngle) / TWO_PI;
dir -= round( dir );
dir *= TWO_PI;

targetAngle += dir * easing;

//push pop lets player rotate
pushMatrix();
translate( playerPos.x, playerPos.y );
rotate( targetAngle );
image(playerSprite, 0, 0);
popMatrix();

}

void rotatePlayer() {

translate(mouseX, mouseY);
rotate(radians(frameCount));

}

//every 20th frame to simulate a rate of fire
void shoot() {
final byte bulletGap = 20;
if (mousePressed && frameCount % bulletGap == 0)
player.addBullet();
}

// bulletSpd gets mouse position, gets the player position
// translates value so bullets can read information
void addBullet() {
final PVector bulletSpd = new PVector();
bulletSpd.set(mouseX, mouseY, 0);
bulletSpd.sub(playerPos);
bulletSpd.normalize();
bulletSpd.mult(7);
bullets.add( new Bullet(playerPos, bulletSpd) );
}
}