Created
September 16, 2014 17:47
-
-
Save boyanov83/a06f3429572bc06b6abe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))+5); | |
} | |
try { | |
Thread.sleep(40); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
//try { | |
// BufferedImage rock = ImageIO.read(new File("rock.png")); | |
// g.drawImage((Image)rock, rockX, rockY, null); | |
// rockY += 2;} | |
// super.paintComponent(g); | |
/*if (rain.size() < 6) { | |
rain.add(20); // this is Y | |
rain.add(rnd.nextInt(500)); // this is X | |
//rain.add(new Color(rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat())); | |
} | |
for (int j = 0; j < rain.size(); j += 2) { | |
//g.setColor((Color)rain.get(j+2)); | |
//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