forked from Toyoyou/homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoppableController.java
More file actions
40 lines (35 loc) · 1.22 KB
/
Copy pathStoppableController.java
File metadata and controls
40 lines (35 loc) · 1.22 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.*;
public class StoppableController extends WindowController {
private static final Location INSTR_LOCATION = new Location (10, 5);
private int width;
private int height;
private Stoppable face;
public void begin() {
width = canvas.getWidth();
height = canvas.getHeight();
// Display instructions
new Text( "Click to make a falling ball...",
INSTR_LOCATION, canvas );
}
public void onMouseClick( Location point ) {
// Make a new ball when the player clicks
if(point.getY()<height/2){
if(point.getX()<width/2){
face = new FallingFace(new FunnyFace(point,canvas),canvas);
}else{
face = new FallingFace(new StraightFace(point,canvas),canvas);
}
}else{
if(point.getX()<width/2){
face = new RisingFace(new FunnyFace(point,canvas),canvas);
}else{
face = new RisingFace(new StraightFace(point,canvas),canvas);
}
}
}
// Falling ball stops when mouse exits canvas
public void onMouseExit( Location point ) {
face.stopFalling();
}
}