Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Ball
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.example.luimi.breakout;

import android.graphics.RectF;
import java.util.Random;

public class Ball {
RectF rect;
float xVelocity;
float yVelocity;
float ballWidth = 10;
float ballHeight = 10;

public Ball(int screenX, int screenY){

xVelocity = 200;
yVelocity = -400;

rect = new RectF();
}

public RectF getRect(){
return rect;
}

public void update(long fps){
rect.left = rect.left + (xVelocity / fps);
rect.top = rect.top + (yVelocity / fps);
rect.right = rect.left + ballWidth;
rect.bottom = rect.top - ballHeight;
}

public void reverseYVelocity(){
yVelocity = -yVelocity;
}

public void reverseXVelocity(){
xVelocity = - xVelocity;
}

public void setRandomXVelocity(){
Random generator = new Random();
int answer = generator.nextInt(2);

if(answer == 0){
reverseXVelocity();
}
}

public void clearObstacleY(float y){
rect.bottom = y;
rect.top = y - ballHeight;
}

public void clearObstacleX(float x){
rect.left = x;
rect.right = x + ballWidth;
}

public void reset(int x, int y){
rect.left = x / 2;
rect.top = y - 20;
rect.right = x / 2 + ballWidth;
rect.bottom = y - 20 - ballHeight;
}

}
34 changes: 34 additions & 0 deletions Brick
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.luimi.breakout;

import android.graphics.RectF;

public class Brick {

private RectF rect;

private boolean isVisible;

public Brick(int row, int column, int width, int height){

isVisible = true;

int padding = 1;

rect = new RectF(column * width + padding,
row * height + padding,
column * width + width - padding,
row * height + height - padding);
}

public RectF getRect(){
return this.rect;
}

public void setInvisible(){
isVisible = false;
}

public boolean getVisibility(){
return isVisible;
}
}
Loading