forked from Toyoyou/homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFallingFace.java
More file actions
40 lines (33 loc) · 1.06 KB
/
Copy pathFallingFace.java
File metadata and controls
40 lines (33 loc) · 1.06 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
import objectdraw.*;
import java.awt.*;
// Class for an animated ball that falls down the canvas
public class FallingFace extends ActiveObject implements Stoppable{
// The size of the ball
private static final int SIZE = 10;
// The delay between successive moves of the ball
private static final int DELAY_TIME = 33;
// Number of pixels ball falls in a single move
private static final double Y_STEP = 4;
// The image of the ball
private ReMovable ballGraphic;
// Whether the ball is currently moving
private boolean moving;
// The canvas
private DrawingCanvas canvas;
public FallingFace( ReMovable face, DrawingCanvas aCanvas ) {
canvas = aCanvas;
ballGraphic = face;
moving = true;
start();
}
public void run() {
while ( moving && ballGraphic.getY() < canvas.getHeight() ) {
ballGraphic.move( 0, Y_STEP );
pause ( DELAY_TIME ) ;
}
ballGraphic.removeFromCanvas();
}
public void stopFalling() {
moving = false;
}
}