-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrail.java
More file actions
61 lines (49 loc) · 1.18 KB
/
Trail.java
File metadata and controls
61 lines (49 loc) · 1.18 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
package com.tutorial.main;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class Trail extends GameObject
{
private float life;
private float alpha = 1;
private Handler handler;
private Color color;
private int width, height;
//.001 < life < 0.1
public Trail(int x, int y, ID id, Color color, int width, int height, float life, Handler handler)
{
super(x, y, id);
this.handler = handler;
this.color = color;
this.width = width;
this.height = height;
this.life = life;
}
public void tick()
{
if(alpha > life)
{
alpha -= (life - .0001f);
}
else handler.removeObject(this);
}
public void render(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(makeTransparent(alpha));
g.setColor(color);
g.fillRect((int)x, (int)y, width, height);
g2d.setComposite(makeTransparent(1));
}
private AlphaComposite makeTransparent(float alpha)
{
int type = AlphaComposite.SRC_OVER;
return(AlphaComposite.getInstance(type, alpha));
}
public Rectangle getBounds()
{
return null;
}
}