Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.net.URL;
- import java.util.Random;
- /**
- * Created by kalin on 06.06.16.
- */
- public class Platform {
- private int dx;
- private int x;
- private int y;
- private int whdth;
- private int height;
- private URL url;
- private Image plat;
- private float frame = 0;
- public Platform(int x, int y) {
- this.x = x;
- this.y = y;
- whdth = 201;
- height = 51;
- dx = -1;
- plat = Pictures.platform;
- }
- public void update (StartingPoints sp, Ball b){
- int tester = (int)(frame + .2);
- if (tester < 3){
- frame += .2;
- }else {
- frame = 0;
- }
- x +=dx;
- checkForCollision(b);
- //move right to left
- if (x < 0 - whdth){
- Random r = new Random();
- //random position
- y = sp.getHeight() - 40 - r.nextInt(400);
- x = sp.getWidth() + r.nextInt(300);
- }
- }
- private void checkForCollision(Ball b) {
- int ballX = b.getX();
- int ballY = b.getY();
- int radius = b.getRadius();
- if (ballY + radius > y && ballY + radius < y + height){
- if (ballX > x && ballX < x + whdth) {
- double newDY = b.getGameDy();
- b.setY(y-radius);
- b.setDy(newDY);
- }
- }
- }
- public void paint(Graphics g){
- g.setColor(Color.BLUE);
- g.fillRect(x,y,whdth,height);
- g.drawImage(plat,x, y, x + whdth, y + height, 0 , 55 * (int)frame, 201, 55 * (int)frame + 55 ,Pictures.sp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment