Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.shreesoft.so;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- public class Ball {
- int x = 0;
- int xs = -1;
- int ys = -1;
- int y = 0;
- static final int DIAMETER = 30;
- JalPan jpn;
- Ball(JalPan jpn) {
- this.jpn = jpn;
- }
- public void move() {
- if (x + xs < 0) {
- xs = 1;
- } else if (y + ys < 0) {
- ys = 1;
- } else if (x + xs > jpn.getWidth() - 30) {
- xs = -1;
- } else if (y + ys > jpn.getHeight() - 30) {
- ys = -1;
- }
- x = x + xs;
- y = y + ys;
- if (collision()) {
- ys = -1;
- y = jpn.plate.getTop() - DIAMETER;
- }
- if (y + ys > 490) {
- ((JalPan) jpn).gameOver();
- }
- }
- public void paint(Graphics g) {
- g.setColor(Color.RED);
- g.fillRoundRect(x, y, DIAMETER, DIAMETER, DIAMETER, DIAMETER);
- }
- public Rectangle getBounds() {
- return new Rectangle(x, y, DIAMETER, DIAMETER);
- }
- public boolean collision() {
- return jpn.plate.getBounds().intersects(getBounds());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement