i'm trying to implement the previous code into another project and is doesn't seem to be working i'll highlight where i'm getting problems. any help would be amazing
Code:
ArrayList blocks;
Paddle paddle = new Paddle();
PFont font;
String level = "";
int levelnum = 0;
int runonce = 0;
int runonce2 = 0;
int runonce3 = 0;
int rungame = 0;
int complete = 0;
ArrayList particles;
void setup(){
size(960,600);
smooth();
font = loadFont("Helvetica-48.vlw");
particles = new ArrayList();
}
void draw(){
background(0);
if(runonce == 0){
levelselect();
}
if(rungame != 0){
levelexecute(levelnum);
}
paddle.display(mouseX,constrain(mouseY, 500, height-paddle.paddle_height/2-25));
if(checkcollision(mouseX, mouseY) == true){
println("Success!");
}
if(checkcomplete() == true){
delay(1000);
runonce2 = 0;
if(levelnum < 10){
levelnum ++;
}
else{
complete++;
}
}
if(complete != 0){
levelnum = -2;
blocks.clear();
stroke(0,80,250);
fill(0,80,250);
textFont(font);
textSize(40);
textMode(SCREEN);
text("Congratulations! You Win!", 250, height/2);
}
if(particles.isEmpty() == false){ //if i comment this out i get an out of bounds exception but not in the stand alone program
for (int i = 0; i >= particles.size(); i++ ) {
Particle p = (Particle) particles.get(i);
p.burst();
p.gravity();
p.display();
if (p.finished()) {
particles.remove(i);
}
}
}
}
void mouseClicked(){
Block tempblock = (Block) blocks.get(0);
for(int i = 0; i < 25; i++){
particles.add(new Particle(mouseX,mouseY));
}
}
void keyPressed(){
if((runonce == 0) && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' ||
key == '7' || key == '8' || key == '9' || key == '0')){
level = level+key;
levelnum = int(level);
}
if(key == ENTER){
runonce++;
rungame++;
}
if(key == TAB){
runonce = 0;
runonce2 = 0;
rungame = 0;
level = "";
}
if(rungame != 0 && key == BACKSPACE){
blocks.remove(0);
explode();
//blocks.clear();
}
}
class Ball{
float ball_x;
float ball_y;
float ball_r;
Ball(float x, float y, float r) {
this.ball_x = x;
this.ball_y = y;
this.ball_r = r;
}
}
class Block{
float xpos;
float ypos;
Block(float x, float y){
xpos = x;
ypos = y;
}
void display(){
strokeWeight(1);
stroke(0,80,250);
rectMode(CENTER);
fill(0,80,250,75);
rect(xpos,ypos, 60,25);
}
}
boolean checkcollision(float px, float py){
boolean check = false;
ArrayList blockgrid = new ArrayList();
if(runonce != 0){
for(int i = 0; i < blocks.size(); i++){
Block tempblock = (Block) blocks.get(i);
float temp = dist(px,py,tempblock.xpos,tempblock.ypos);
if( temp< 10){
check = true;
}
else{
check = false;
}
}
}
return check;
}
boolean checkcomplete(){
if(runonce == 0){
return false;
}
else if(blocks.size() <= 0){
return true;
}
else{
return false;
}
}
void explode(){
Block tempblock = (Block) blocks.get(0);
for(int i = 0; i < 25; i++){
particles.add(new Particle(tempblock.xpos,tempblock.ypos));
}
if(particles.isEmpty() == false){
for (int i = 0; i >= particles.size(); i++ ) {
Particle p = (Particle) particles.get(i);
p.burst();
p.gravity();
p.display();
if (p.finished()) {
particles.remove(i);
}
}
}
}
void levelexecute(int levelnum){
if(runonce2 == 0){
blocks = new ArrayList();
for(int x = 1;x < 15;x++){
for(int t = 1; t <= levelnum+2; t++){
blocks.add(new Block(x*60+30, t*25+30));
}
}
runonce2++;
}
for(int i = 0; i < blocks.size(); i++){
Block tempblock = (Block) blocks.get(i);
tempblock.display();
}
}
void levelexecute(int levelnum){
if(runonce2 == 0){
blocks = new ArrayList();
for(int x = 1;x < 15;x++){
for(int t = 1; t <= levelnum+2; t++){
blocks.add(new Block(x*60+30, t*25+30));
}
}
runonce2++;
}
for(int i = 0; i < blocks.size(); i++){
Block tempblock = (Block) blocks.get(i);
tempblock.display();
}
}
void levelexecute(int levelnum){
if(runonce2 == 0){
blocks = new ArrayList();
for(int x = 1;x < 15;x++){
for(int t = 1; t <= levelnum+2; t++){
blocks.add(new Block(x*60+30, t*25+30));
}
}
runonce2++;
}
for(int i = 0; i < blocks.size(); i++){
Block tempblock = (Block) blocks.get(i);
tempblock.display();
}
}
class Paddle{
float paddle_xpos;
float paddle_ypos;
int paddle_height;
int paddle_width;
Paddle(){
paddle_height = 15;
paddle_width = 96;
}
void display(int xpos_,int ypos_){
int xpos = xpos_;
int ypos = ypos_;
xpos = constrain(mouseX, paddle_width/2, width-paddle_width/2);
rectMode(CENTER);
fill(255);
rect(xpos, ypos,paddle_width, paddle_height);
}
}
class Particle{
float px, py, xspeed, yspeed, life;
Particle(float x_, float y_){
px = x_;
py = y_;
xspeed = random(-2,2);
yspeed = random(-4,0);
life = 255;
}
void burst(){
px += xspeed;
py += yspeed;
}
void gravity(){
yspeed += .05;
}
boolean finished(){
life -= 2.0;
if (life < 0) return true;
else return false;
}
void stop() {
xspeed = 0;
yspeed = 0;
}
void display(){
strokeWeight(1);
stroke(0,80,250);
ellipseMode(CENTER);
fill(0,80,250,75);
ellipse(px,py,10,10);
}
}