-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNote.java
106 lines (90 loc) · 2.32 KB
/
Note.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import greenfoot.Actor;
import greenfoot.GreenfootImage;
/**
* This class creates a Note object.
*
* @author Team APCSA 2019
* @author Andrew Vittiglio
* @author Steve Rosario
* @version 2019-05-23
*/
@SuppressWarnings("WeakerAccess")
public class Note extends Actor
{
private static final int NOTE_WIDTH = Constants.GRAPHIC_TOTAL_LENGTH / Constants.NUM_COLS;
private final int startTime;
private final int hitTime;
private final int column;
private final long startTimeSystem;
// Init note textures when this class is accessed for the first time.
static
{
initNoteTextures();
}
/**
* Constructs a Note object with designated parameters.
*
* @param hitTime The in-game time that the note is hit.
* @param column The column number.
*/
public Note(int hitTime, int column)
{
this.startTime = hitTime - Constants.GAME_SPEED_MS;
this.hitTime = hitTime;
this.column = column;
this.startTimeSystem = System.currentTimeMillis();
setImage(Images.NOTES[column]);
}
/**
* Construct a Note actor with Note info.
*
* @param noteInfo Note information
*/
public Note(NoteInformation noteInfo)
{
this(noteInfo.getTime(), noteInfo.getColumn());
}
/**
* The note fall down
*/
public void act()
{
int elapseTime = (int) (System.currentTimeMillis() - startTimeSystem);
// Fall to the correct location.
setLocation(getX(), (int) Math.round((double) elapseTime / Constants.GAME_SPEED_MS * Constants.GRAPHIC_NOTE_LANDING));
}
/**
* Initialize position
*/
public void init()
{
// Initialize position
int x = Constants.GRAPHIC_COL_OFFSET + NOTE_WIDTH * column;
setLocation(x, 0);
}
/**
* Initialize note textures
*/
public static void initNoteTextures()
{
for (GreenfootImage note : Images.NOTES)
{
note.scale(NOTE_WIDTH, Constants.GRAPHIC_NOTE_HEIGHT);
}
}
// ###################
// Getters and Setters
// ###################
public int getHitTime()
{
return hitTime;
}
public int getStartTime()
{
return startTime;
}
public int getColumn()
{
return column;
}
}