-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParticleGenerator.java
47 lines (44 loc) · 1.07 KB
/
ParticleGenerator.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Write a description of class ParticleGenerator here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ParticleGenerator extends Actor
{
/**
* Act - do whatever the ParticleGenerator wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int dir = 0;
public ParticleGenerator(int dir)
{
this.dir = dir;
}
public void act()
{
// Add your action code here.
if(dir == 0)
{
setLocation(getX(),getY()+10);
}
else if(dir ==1)
{
setLocation(getX(),getY()-10);
}
if(getY()>getWorld().getHeight())
{
destroy();
}
}
public void destroy()
{
Actor par = getWorld().getObjects(ParticleGenerator.class).get(0);
if(par!=null)
{
getWorld().removeObject(par);
}
}
}