Skip to content

Instantly share code, notes, and snippets.

@boyanov83
Created September 17, 2014 14:35
Show Gist options
  • Save boyanov83/9a927518d318461fa13e to your computer and use it in GitHub Desktop.
Save boyanov83/9a927518d318461fa13e to your computer and use it in GitHub Desktop.
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import javax.imageio.ImageIO;
public class Rain extends GameObjects {
private int yPos; // xPos, width, height; <- useless
Random rnd = new Random();
int rockY = 10;
int rockX = rnd.nextInt(450);
ArrayList<Object> rain = new ArrayList<Object>(); // rain(y, x, color, y, x, color)
//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) {
try {
rain.add(10);
rain.add(rnd.nextInt(450));
rain.add(ImageIO.read(new File("rock.png")));
} catch (IOException e) {
System.out.println("PROBLEM WITH ROCK.PNG");
}
}
for (int i = 0; i < rain.size(); i+=3)
{
g.drawImage((Image)rain.get(i+2), (int)rain.get(i+1), (int)rain.get(i), null);
rain.set(i, ((int)rain.get(i))+1);
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
void update() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment