-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrailBall.java
More file actions
50 lines (44 loc) · 1.25 KB
/
TrailBall.java
File metadata and controls
50 lines (44 loc) · 1.25 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
import greenfoot.*;
/**
* A TrailBall is a thing that bounces of walls and paddles (or at least i should).
*
* @author Patrik Valentiny (PM)
* @version 1
*/
public class TrailBall extends Actor
{
private static final int BALL_SIZE = 25;
private static final int START_LIFE = 17; // determines how many balls will create the "motion blur"
private int life = START_LIFE;
private GreenfootImage ballImage = new GreenfootImage(BALL_SIZE,BALL_SIZE);
public TrailBall()
{
createImage();
}
/**
* Creates and sets an image of a black ball to this actor.
*/
private void createImage()
{
ballImage.setColor(Color.WHITE);
ballImage.fillOval(0, 0, BALL_SIZE, BALL_SIZE);
setImage(ballImage);
}
/**
* Act - do whatever the TrailBall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (life == 0){
((PingWorld)getWorld()).removeObject(this);
} else {
life--;
fader();
}
}
private void fader(){
int value = (255 / START_LIFE) * (life);
ballImage.setTransparency(value);
}
}