Skip to content

Instantly share code, notes, and snippets.

@boyanov83
Created September 16, 2014 16:46
Show Gist options
  • Save boyanov83/4cb42dc639b92c2013f6 to your computer and use it in GitHub Desktop.
Save boyanov83/4cb42dc639b92c2013f6 to your computer and use it in GitHub Desktop.
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Random;
public class Rain extends GameObjects {
private int yPos; // xPos, width, height; <- useless
Random rnd = new Random();
ArrayList<Object> rain = new ArrayList<Object>(); // rain(y, x, y, x)
Object[] colors = {Color.black, Color.yellow, Color.blue, Color.red, Color.orange};
@Override
void draw(Graphics g) {
g.clearRect(0, 0, 500, 500);
if (rain.size() < 20) {
rain.add(20); // this is Y
rain.add(rnd.nextInt(500)); // this is X
}
for (int j = 0; j < rain.size(); j += 2) {
g.setColor((Color)colors[rnd.nextInt(5)]);
g.fillOval((int) rain.get(j + 1), (int) rain.get(j), 15, 15);
rain.set(j, (int) rain.get(j) + 10);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
}
@Override
void update() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment