he question is to get my shapes to change over time according to some criteria of my own design therefore i tried to make the shape change size as it hits certain coordinates but it would turn into line and keep moving as lines below is my move method to make my shapes move, rebound, and move horizontally and vertically.
public void move() {
// Rebound X
if (x <= 0 || x >= 400 - width) {
moveX = moveX * -1;
}
// Rebound Y
if (y <= 0 || y >= 400 - height) {
moveY = moveY * -1;
}
// Wide shapes move up and down, narrow shapes move sideways
if (width > 15) {
y += moveY;
} else {
x += moveX;
}
// Change shape size
if (y <= 100 || y >= 300 - height) {
moveX = -moveX;
height += height * 1 / 2;
}
//if {
// height -= height * 1/2;
// moveX = -moveX;
//}
//if (x < 20) {
// width -= width * 1/2;
// moveY = -moveY;
//} else {
// width += width * 1/2;
// moveY = -moveY;
//}
This is my shape class that all shapes extend:
package shapes;
import java.awt.*;
import java.util.Random;
public abstract class Shape {
protected int x;
protected int y;
protected int width;
protected int height;
protected Color color;
protected int moveX = 1;
protected int moveY = 1;
public Shape() {
Random r = new Random();
width = r.nextInt(30) + 10;
height = width;
x = r.nextInt(400 - width);
y = r.nextInt(400 - height);
color = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
}
// Returns random value within range (low < n <= high).
public int randomRange(int low, int high) {
Random generator = new Random();
return generator.nextInt(high - low + 1) + low;
}
public abstract void display(Graphics page);
public abstract void move();
}