-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinShower.pde
38 lines (36 loc) · 900 Bytes
/
CoinShower.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Use stack interface from java standard library
import java.util.Stack;
/*
Helper Class managing the falling coins
by Flocksserver http://flocksserver.de
*/
class CoinShower {
Stack<Coin> waitingStack = new Stack();
//Each second one coin
int interval = 1000;
int savedTime = millis();
/*
Add coin from stack to coinarray to display.
If no coin on stack anymore, create new coin
*/
void start(ArrayList<Coin> ingameCoins) {
if (isTimeForNextOne()) {
if (waitingStack.empty()) {
waitingStack.push(new Coin());
}
Coin coin = waitingStack.pop();
ingameCoins.add(coin);
}
}
/*
Check intervall seconds between last coin drop and now
*/
boolean isTimeForNextOne( ) {
int currentTime = millis();
if (savedTime + interval < currentTime) {
savedTime = currentTime;
return true;
}
return false;
}
}