-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparksEffect.java
More file actions
executable file
·68 lines (53 loc) · 1.41 KB
/
Copy pathSparksEffect.java
File metadata and controls
executable file
·68 lines (53 loc) · 1.41 KB
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
67
68
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class SparksActor here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SparksEffect extends Actor
{
public static GreenfootImage images[] = new GreenfootImage[16];
int counter = 0;
public int speed = 0;
long startTime = 0;
public SparksEffect()
{
if(null == images[0])
{
for(int i = 0 ; i < 16 ; i++)
{
int j = i + 1;
images [i] = new GreenfootImage("fire-" + j + ".png");
}
}
setImage(images[0]);
}
/**
* Act - do whatever the SparksActor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
int index = counter;
long endTime = System.currentTimeMillis();
if((endTime - startTime) < 50)
{
return;
}
startTime = System.currentTimeMillis();
if(index > 15)
{
index = 15;
}
setImage(images[index]);
setRotation(getRotation() + Greenfoot.getRandomNumber(11)-5);
move(speed);
counter++;
if(counter > 16)
{
getWorld().removeObject(this);
}
}
}