-
Notifications
You must be signed in to change notification settings - Fork 0
/
VolcanoFlare.java
executable file
·66 lines (54 loc) · 1.65 KB
/
VolcanoFlare.java
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
57
58
59
60
61
62
63
64
65
66
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class VolcanoFlare here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class VolcanoFlare extends Actor
{
static GreenfootImage[] images;
static
{
images = new GreenfootImage[6];
images[0] = new GreenfootImage("flare-1.png");
images[1] = new GreenfootImage("flare-2.png");
images[2] = new GreenfootImage("flare-3.png");
images[3] = new GreenfootImage("flare-4.png");
images[4] = new GreenfootImage("flare-5.png");
images[5] = new GreenfootImage("flare-6.png");
}
int index = 0;
int step = 0;
long startTime = System.currentTimeMillis();
long totaldiff = 0;
int smallpause = 20 + Greenfoot.getRandomNumber(50);
int bigpause = 1000 + Greenfoot.getRandomNumber(2000);
public void act()
{
long endTime = System.currentTimeMillis();
if((endTime - startTime) > smallpause)
{
index = (index + 1) % 3;
totaldiff += (endTime - startTime);
startTime = endTime;
}
else
{
return;
}
if(totaldiff > bigpause)
{
smallpause = 20 + Greenfoot.getRandomNumber(50);
step = (step + 1) % 3;
totaldiff = 0;
bigpause = 1000 + Greenfoot.getRandomNumber(2000);
if(step < 1)
{
FireBall fb = new FireBall();
getWorld().addObject(fb,getX(),getY());
}
}
setImage(images[step + index]);
}
}