-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollingActor.java
More file actions
80 lines (62 loc) · 2.24 KB
/
ScrollingActor.java
File metadata and controls
80 lines (62 loc) · 2.24 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Contains the scrolling actor.
* This actor will always be in the middle of the screen
* and the objects around him will be moved.
*/
public abstract class ScrollingActor extends GameObjects {
private boolean scrollingCenter;
public ScrollingActor() {
scrollingCenter = true;
}
public ScrollingActor(boolean scrollingCenter) {
this.scrollingCenter = scrollingCenter;
}
public final void addedToWorld(World world) {
if (scrollingCenter) {
List<ScrollingActor> scrollingActors = getWorld().getObjects(ScrollingActor.class);
if (scrollingActors != null && !scrollingActors.isEmpty()) {
for (ScrollingActor scrollingActor : scrollingActors) {
if (!scrollingActor.equals(this)) {
scrollingActor.setScrollingCenter(false);
}
}
}
}
}
/**
* SetLocation method uses integer values. x - new x location; y - new y location.
*/
public final void setLocation(int x, int y) {
super.setLocation(x, y);
if (scrollingCenter) {
getWorld().resetPlayersPosition(this);
}
}
/**
* SetLocation method uses double values. x - new x location; y - new y location.
*/
public final void setLocation(double x, double y) {
super.setLocation(x, y);
if (scrollingCenter) {
getWorld().resetPlayersPosition(this);
}
}
/**
* SetLocation method which uses double values.
* Boolean = true -> reset player's position. Boolean = false -> don't reset player's position.
*/
public final void setLocation(double x, double y, boolean resetPosition) {
super.setLocation(x, y);
if (scrollingCenter && resetPosition) {
getWorld().resetPlayersPosition(this);
}
}
public final boolean isScrollingCenter() {
return scrollingCenter;
}
public final void setScrollingCenter(boolean scrollingCenter) {
this.scrollingCenter = scrollingCenter;
}
}