Joe Rice
YaBB Newbies
Offline
Posts: 28
Re: need help debugging my game
Reply #1 - Feb 4th , 2010, 9:07am
Code: void keyPressed(){ if((runonce == true) && (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 = false; rungame = true; } if(key == TAB){ runonce = true; runonce2 = true; rungame = false; complete = false; level = ""; ball.bx = mouseX; ball.by = mouseY-17.5; mouseclick = false; } if(rungame ==true && key == BACKSPACE){ blocknum = 0; explode(); } } class Ball{ float bx; float by; float br; Ball(float x, float y, float r) { this.bx = x; this.by = y; this.br = 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, int i){ boolean result = false; PVector coord = new PVector(); if(rungame == true){ Block tempblock = (Block) blocks.get(i); coord.x = tempblock.xpos; coord.y = tempblock.ypos; float top = coord.y - 12.5; float bottom = coord.y + 12.5; float left = coord.x - 30; float right = coord.x + 30; //walls if((ball.bx-ball.br) <= 0 || ball.bx+ball.br >= width){ result = true; check = 1; } //ceiling else if(ball.by-ball.br <= 0){ result = true; check = 2; } //paddle else if(ball.bx > paddle.px-48 && ball.bx < paddle.px+48 && ball.by+ball.br >= paddle.py-10){ result = true; check = 7; } //left collision if(py > top && py < bottom && px+ball.br >= left){ result = true; check = 3; blocknum = i; } //right collision else if(py > top && py < bottom && px-ball.br <= right){ result = true; check = 4; blocknum = i; } //top collision else if(px > left && px < right && py+ball.br >= top){ result = true; check = 5; blocknum = i; } //bottom collision else if(px > left && px < right && py-ball.br <= bottom){ result = true; check = 6; blocknum = i; } } return result; } boolean checkcomplete(){ if(runonce == true){ return false; } else if(blocks.size() <= 0){ return true; } else{ return false; } } void explode(){ for(int i = 0; i < 25; i++){ Block tempblock = (Block) blocks.get(blocknum); particles.add(new Particle(tempblock.xpos,tempblock.ypos)); //particles.add(new Particle(mouseX,mouseY)); } blocks.remove(blocknum); } void levelexecute(int levelnum){ if(runonce2 == true){ 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 = false; } for(int i = 0; i < blocks.size(); i++){ Block tempblock = (Block) blocks.get(i); tempblock.display(); } } void levelselect(){ stroke(0,80,250); fill(0,80,250); textFont(font); textSize(40); textMode(SCREEN); text("Welcome to Ulitmate Block Breaker!!!", 125, height/2 -50); text("Type which level you want then hit enter(1-10): " + level, 25, height/2); } class Paddle{ float px; float py; int ph; int pw; Paddle(){ ph = 15; pw = 96; } void display(int xpos_,int ypos_){ px = xpos_; py = ypos_; px = constrain(mouseX, pw/2, width-pw/2); rectMode(CENTER); fill(255); rect(px, py, pw, ph); } } 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 = 500; } 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(constrain(px,5,width-5),py,10,10); } }