Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.util.ArrayList;
- public class Balls {
- double x = 100;
- double y = 10;
- double dx = 10;
- double dy = 0;
- double dt = 0.2;
- double u = 0.9;
- double g = 15;
- public void move(int height, int width) {
- if (y == height - 30) {
- dx *= u;
- }
- if (y > height - 30) {
- y = height - 30;
- dy *= u;
- dy = -dy;
- } else {
- dy += dt * g;
- y += dy * dt + 0.5 * g * dt * dt;
- }
- if (x > width - 30) {
- x = width - 30;
- dx = -dx;
- } else if (x < 0) {
- x = 0;
- dx = -dx;
- } else {
- x += dx;
- }
- }
- public void draw(Graphics g) {
- g.fillOval((int) x, (int) y, 30, 30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement