public void checkBrickCollision(){
for(Brick brick : bricks) {
if (ball.intersects(brick)) {
double angle = Math.random() * 360;
ball.setDirection(angle);
bricks.remove(bricks.indexOf(brick));
}
}
}
package com.codegym.task.task24.task2413;
import java.util.List;
public class Arkanoid {
public static void main(String[] args){
}
private int width;
private int height;
private Ball ball;
private Paddle paddle;
private List<Brick> bricks;
static Arkanoid game;
private boolean isGameOver;
public Arkanoid(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public Ball getBall() {
return ball;
}
public void setBall(Ball ball) {
this.ball = ball;
}
public Paddle getPaddle() {
return paddle;
}
public void setPaddle(Paddle paddle) {
this.paddle = paddle;
}
public List<Brick> getBricks() {
return bricks;
}
public void setBricks(List<Brick> bricks) {
this.bricks = bricks;
}
public void run(){
}
public void move(){
paddle.move();
ball.move();
}
public void draw(Canvas canvas){
ball.draw(canvas);
for(Brick brick : bricks)
brick.draw(canvas);
paddle.draw(canvas);
}
public void checkBrickCollision(){
for(Brick brick : bricks) {
if (ball.intersects(brick)) {
double angle = Math.random() * 360;
ball.setDirection(angle);
bricks.remove(bricks.indexOf(brick));
}
}
}
public void checkPaddleCollision(){
if (ball.intersects(paddle)){
double angle = 90 + 20 * (Math.random() - 0.5);
ball.setDirection(angle);
}
}
public void checkGameOver(){
if(ball.y >= game.height){
isGameOver = true;
}
}
}