-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrail.java
More file actions
54 lines (45 loc) · 1.29 KB
/
Trail.java
File metadata and controls
54 lines (45 loc) · 1.29 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
package com.tutorial.main;
import java.awt.*;
/**
* Created by narhwal on 6/12/2016.
*/
public class Trail extends GameObject {
private float alpha = 1;
private Handler handler;
private Color color;
private int width, height;
private float life;
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;
}
@Override
public Rectangle getBounds() {
return null;
}
@Override
public void tick() {
if (alpha > life) {
alpha -= life - 0.001f;
} else handler.removeObject(this);
}
@Override
public void render(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(makeTransparent(alpha));
g.setColor(color);
//g.fillRect(x, y, height, width);
double test = alpha * 15;
int size = (int) test;
g.fillOval(x, y, size, size);
g2d.setComposite(makeTransparent(1));
}
private AlphaComposite makeTransparent(float alpha) {
int type = AlphaComposite.SRC_OVER;
return (AlphaComposite.getInstance(type, alpha));
}
}