-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStraightMover.java
More file actions
31 lines (25 loc) · 830 Bytes
/
Copy pathStraightMover.java
File metadata and controls
31 lines (25 loc) · 830 Bytes
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
import java.awt.Graphics;
public class StraightMover implements Mover{
private int x;
private int y;
private int xDirection;
private int yDirection;
private Sprite sprite;
/** Create a Bouncer that positions sprite at (startX, startY). */
public StraightMover(int startX, int startY, Sprite sprite) {
x = startX;
y = startY;
this.sprite = sprite;
}
/** Starts moving the object in the direction (xIncrement, yIncrement). */
public void setMovementVector(int xIncrement, int yIncrement) {
xDirection = xIncrement;
yDirection = yIncrement;
}
public void draw(Graphics graphics) {
sprite.draw(graphics, x, y);
// Move the center of the object each time we draw it
x += xDirection;
y += yDirection;
}
}