-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinSpawner.pde
56 lines (36 loc) · 965 Bytes
/
CoinSpawner.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class CoinSpawner{
ArrayList<Coin> coins = new ArrayList<Coin>();
float timeUntilCheck = 0.5f;
float chanceToSpawn = 0.3f;
float elapsed = 0;
void update(float dt)
{
if (elapsed > timeUntilCheck)
{
elapsed = 0;
if (random(0f, 1f) > 1f - chanceToSpawn && coins.size() <= 5)
{
int x = int(random(100, width-100)); int y = int(random(100, height -100 ));
coins.add(new Coin(x, y, 20, 20 ));
//System.out.println("spawned");
}
}
elapsed += dt;
for( int i = 0; i< coins.size(); i++){
coins.get(i).update(dt);
}
}
void render(){
for( Coin c: coins){
if(c.active){
c.render();
}
}
for( int i = 0; i< coins.size(); i++){
if(!coins.get(i).active){
coins.remove(i);
i--;
}
}
}
}