Java – simulated rain
•
Java
I play a game in Java. I want to create a simulation of a raining cloud When it rains, the clouds should move to the right Mobile cloud is no problem This is the rain I'm trying to
What I'm thinking is to draw a rectangle with a timer, which should be the decline of the random X value in the cloud Then add the y value of every 100 milliseconds by 1 But I don't want to create 100 different rectangles, X variables and Y variables for each raindrop
What ideas can be realized? The suggestion is appreciated!
This is a 2D game I'm sorry.
Solution
I recommend storing the value as an ArrayList
class Raindrop { private int x; private int y; public void fall() { y--; } }
Then use a generic type ArrayList
ArrayList<Raindrop> drops = new ArrayList<Raindrop>();
To make every drop drop drop,
for (int i=0; i<drops.length(); i++) { drops.get(i).fall(); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码