-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyHitScore.java
73 lines (64 loc) · 2 KB
/
KeyHitScore.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import greenfoot.Actor;
import greenfoot.GreenfootImage;
/**
* This class display the hit value after a hit. Eg. Great, Cool, Good, Bad, etc.
*
* @author Team APCSA 2019
* @author Andy Ge
* @since 2019-05-25 19:52
*/
@SuppressWarnings("WeakerAccess")
public class KeyHitScore extends Actor
{
/** Transparency (0 = fully transparent, 255 = not transparent) */
private int transparency = 255;
/** Timer */
private long time = System.currentTimeMillis();
/**
* Create object and initialize to no image
*/
public KeyHitScore()
{
setImage(new GreenfootImage(1, 1));
}
/**
* Initialize position. This method is called in KeypressHandler when
* the key score object is created.
*/
public void init()
{
// Initialize position
int keyLen = Constants.GRAPHIC_TOTAL_LENGTH / Constants.NUM_COLS;
int x = Constants.GRAPHIC_COL_OFFSET + Constants.GRAPHIC_TOTAL_LENGTH / 2 - keyLen / 2;
int y = (int) Math.round(Constants.GRAPHIC_NOTE_LANDING * (2.0 / 3.0));
setLocation(x, y);
}
/**
* Act: Dim it
*/
@Override
public void act()
{
// Execute every 10 ms
long current = System.currentTimeMillis();
if (current - time < 10) return;
time = current;
// Reduce the transparency by Constants.GRAPHIC_KEY_HIT_SCORE_SPEED ( > 0)
transparency -= 4;
if (transparency < 0) transparency = 0;
// Set the transparency of the image to the value in the transparency variable.
getImage().setTransparency(transparency);
}
/**
* This method is called when the player hit a note.
*
* @param hitScore Hit score (0 to 5)
*/
public void hit(int hitScore)
{
// Set the image to the corresponding hit image (Images.KEY_HIT_SCORE[hitScore])
setImage(Images.KEY_HIT_SCORE[hitScore]);
// Reset the transparency variable to not transparent
transparency = 255;
}
}