1. i had code to delete elements from an arraylist when the delete key is pressed, it was working and now it isn't, not sure what i did to change that.
2. my function checkcollision doesn't seems to work. i'm checking based on the distance of the mouse to the blocks on the screen, and below that i'm checking the distance of each point in each block and comparing it to the mouse's position.
thats all i can think of right now my code is below any and all help would be greatly appreciated.
Code:ArrayList blocks;
Paddle paddle = new Paddle();
PFont font;
String level = "";
int levelnum = 0;
int runonce = 0;
int runonce2 = 0;
int rungame = 0;
void setup(){
size(960,600);
font = loadFont("Helvetica-48.vlw");
}
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);
levelnum ++;
}
}
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 == '\n'){
runonce++;
rungame++;
}
if(key == TAB){
runonce = 0;
runonce2 = 0;
rungame = 0;
level = "";
}
if(key == DELETE){
int i = 0;
blocks.remove(i);
if(i < blocks.size()){
i++;
}
}
}
Code: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;
}
}
Code:class Block{
float posx;
float posy;
Block(float x, float y){
posx = x;
posy = y;
}
void display(){
strokeWeight(1);
stroke(0,80,250);
rectMode(CENTER);
fill(0,80,250,75);
rect(posx,posy, 60,25);
}
}
Code: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);
PVector coord = new PVector();
for(float x = tempblock.posy-12.5; x < tempblock.posy +12.5; x++){
for(float y = tempblock.posx - 30; y < tempblock.posx +30; y++){
coord.x = x;
coord.y = y;
blockgrid.add(coord);
}
}
for(int t = 0;t<blockgrid.size(); t++){
PVector tempvec = (PVector) blockgrid.get(t);
float temp = dist(px,py,tempvec.x,tempvec.y);
if( temp< 10){
check = true;
}
else{
check = false;
}
}
}
}
return check;
}
Code:boolean checkcomplete(){
if(runonce == 0){
return false;
}
else if(blocks.size() == 0){
return true;
}
else{
return false;
}
}
Code: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));
}
}
}
for(int i = 0; i < blocks.size(); i++){
Block tempblock = (Block) blocks.get(i);
tempblock.display();
}
}
Code:void levelselect(){
stroke(0,80,250);
fill(0,80,250);
textFont(font);
textSize(40);
textMode(SCREEN);
text("Welcome to Ulitmate Block Breaker!!!", 100, height/2 -50);
text("Which level do you want to start at?(1-10): " + level, 75, height/2);
}
Code: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);
}
}