View Javadoc

1   package de.jos.game.actions;
2   
3   import java.awt.AlphaComposite;
4   import java.awt.Composite;
5   import java.awt.Graphics2D;
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   import com.golden.gamedev.GameObject;
10  
11  import de.jos.game.objects.Bullet;
12  import de.jos.game.objects.Bullet.State;
13  
14  public class ActionFadeBullets extends AbstractAction implements SpecialActionEvent {
15  
16    private List<Bullet> bulletList = new ArrayList<Bullet>();
17    private boolean finished = false;
18  
19    private State state = null;
20  
21    public ActionFadeBullets(State initialState) {
22      state = initialState;
23    }
24  
25    public void init() {
26      super.init();
27  
28      for (Bullet tmpBullet : getBulletList()) {
29        tmpBullet.setActionState(state);
30        if (state == Bullet.State.DISSOLVING) {
31          tmpBullet.setTransparency(Bullet.TRANSPARENCY_INIT);
32        } else if (state == Bullet.State.FADEIN) {
33          tmpBullet.setTransparency(0.0f);
34        }
35  
36        // reset possible animation
37        tmpBullet.resetHoverAnimation();
38      }
39    }
40  
41    public boolean isFinished() {
42      return finished;
43    }
44  
45    public void update(long elapsedTime, GameObject gameObject) {
46      for (Bullet tmpBullet : getBulletList()) {
47        tmpBullet.update(elapsedTime);
48        if (tmpBullet.isFinished()) {
49          finished = true;
50        }
51      }
52    }
53  
54    public void render(Graphics2D graphics, GameObject gameObject) {
55      Composite old = graphics.getComposite();
56  
57      for (Bullet tmpBullet : getBulletList()) {
58        Composite cursorComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, tmpBullet.getTransparency());
59        graphics.setComposite(cursorComposite);
60        tmpBullet.render(graphics);
61      }
62  
63      graphics.setComposite(old);
64    }
65  
66    public Integer getLayer() {
67      return LayerConstants.LAYER_1;
68    }
69  
70    public List<Bullet> getBulletList() {
71      return bulletList;
72    }
73  
74    public String getName() {
75      return this.getClass().getName();
76    }
77  
78  }