-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScroller.java
More file actions
65 lines (53 loc) · 1.51 KB
/
Copy pathScroller.java
File metadata and controls
65 lines (53 loc) · 1.51 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* A class that contains all of the objects that have to move according to the player
* for a camera following effect.
*
* @author Zachary Zhao
* @version 0.0.2
*/
public class Scroller extends SuperSmoothMover
{
private boolean inRange;
protected Player player;
private MyWorld w;
private boolean isNew;
protected static double camX = 0; // the "camera's" position
protected static double camY = 0;
public Scroller() {
isNew = true;
}
@Override
protected void addedToWorld(World w) {
if(isNew) {
w = (MyWorld)getWorld();
player = getWorld().getObjects(Player.class).get(0);
realX = getX();
realY = getY();
isNew = false;
}
}
public void act()
{
updateLocation();
}
public void centreOn(SuperSmoothMover target) { // this is essentially static, only being called ONCE per act (not instance) on the player.
if(target != null) {
camX = target.realX - (getWorld().getWidth() / 2);
camY = target.realY - (getWorld().getHeight() / 2);
}
}
public void updateLocation(){
setLocation(realX - camX, realY - camY);
}
public double getRealX(){
return realX;
}
public double getRealY(){
return realY;
}
public void setRealLocation(double x, double y) {
realX = x;
realY = y;
}
}