-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyHitAnimation.java
76 lines (66 loc) · 1.72 KB
/
KeyHitAnimation.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
74
75
76
import greenfoot.Actor;
import greenfoot.GreenfootImage;
/**
* This class displays a hit animation on the note hitting line after
* the player hits a note.
*
* @author Team APCSA 2019
* @author Andrew Vittiglio
* @since 2019-05-24 14:15
*/
public class KeyHitAnimation extends Actor
{
/** What column it is in */
private final int column;
/** Current index of the animated image */
private int index;
/** Timer */
private long time = System.currentTimeMillis();
/**
* Construct a key hit animation object
*
* @param column Column number
*/
public KeyHitAnimation(int column)
{
this.column = column;
this.index = 0;
setImage((GreenfootImage) null);
}
/**
* Initialize the key. This method is called in KeypressHandler when
* the key object is created.
*/
public void init()
{
// Scale image
int keyLen = Constants.GRAPHIC_TOTAL_LENGTH / Constants.NUM_COLS;
// getImage().scale(keyLen, Constants.GRAPHIC_NOTE_LANDING);
// Initialize position
int x = Constants.GRAPHIC_COL_OFFSET + keyLen * column;
int y = Constants.GRAPHIC_NOTE_LANDING;
setLocation(x, y);
}
/**
* Act: Updates the frame
*/
public void act()
{
// Execute every 20 ms
long current = System.currentTimeMillis();
if (current - time < 20) return;
time = current;
if (index < Images.KEY_HIT_ANIMATION_FRAMES.length)
{
setImage(Images.KEY_HIT_ANIMATION_FRAMES[index]);
index++;
}
}
/**
* Reset the index.
*/
public void resetIndex()
{
index = 0;
}
}