-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.java
More file actions
108 lines (84 loc) · 3.08 KB
/
Camera.java
File metadata and controls
108 lines (84 loc) · 3.08 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
public class Camera {
private int xSize, ySize;
private int chapterOffsetX, chapterOffsetY;
private int xOffset, yOffset;
private int clickXOffset = 0, clickYOffset = 0;
public Camera() {
}
public Camera(int pXSize, int pYSize, int chapterOffsetX, int chapterOffsetY) {
xSize = pXSize;
ySize = pYSize;
this.chapterOffsetX = chapterOffsetX;
this.chapterOffsetY = chapterOffsetY;
}
public void centerOnObject(Pointer pointer) {
// int virtualSpace = this.virtualSpace;
//
// if (clickXOffset <= GUI.GAMEPANEL_WIDTH/2) {
// virtualSpace = virtualSpace;
// } else {
// int maxLoc = xSize * Tile.TILEWIDTH - GUI.GAMEPANEL_WIDTH ;
// if (clickXOffset >= maxLoc) {
// virtualSpace = - virtualSpace;
// } // end of if
// } // end of if-else
//
// if (clickYOffset <= GUI.GAMEPANEL_WIDTH ) {
// virtualSpace = virtualSpace;
// } else {
// int maxLoc = ySize * Tile.TILEHEIGHT - GUI.GAMEPANEL_HEIGHT ;
// if (clickYOffset >= maxLoc) {
// virtualSpace = -virtualSpace;
// } // end of if
// } // end of if-else
clickXOffset = (int) pointer.getLocation().getX() - (GUI.GAMEPANEL_WIDTH / 2) + 80;
clickYOffset = (int) pointer.getLocation().getY() - (GUI.GAMEPANEL_HEIGHT / 2) + 80;
// Edge Snapping
//https://gamedev.stackexchange.com/questions/138756/smooth-camera-movement-java
//Lerp:
int targetX = clickXOffset + Character.MOVER_WIDTH / 2;
int targetY = clickYOffset + Character.MOVER_HEIGHT / 2;
xOffset += (targetX - xOffset) * 0.1f;
yOffset += (targetY - yOffset) * 0.1f;
xOffset = Math.min(chapterOffsetX + xSize * Tile.TILEWIDTH - GUI.GAMEPANEL_WIDTH, Math.max(0, xOffset));
yOffset = Math.min(chapterOffsetY + ySize * Tile.TILEHEIGHT - GUI.GAMEPANEL_HEIGHT, Math.max(0, yOffset));
// if (xSize * Tile.TILEWIDTH < GUI.GAMEPANEL_WIDTH) {
// clickXOffset = xSize * Tile.TILEWIDTH / 2;
// xOffset = xSize * Tile.TILEWIDTH / 2;
// }
// if (ySize * Tile.TILEHEIGHT < GUI.GAMEPANEL_WIDTH) {
// clickYOffset = ySize * Tile.TILEHEIGHT / 2;
// yOffset = ySize * Tile.TILEHEIGHT / 2;
// }
}
public void setxOffset(int xOffset) {
this.xOffset = xOffset;
}
public void setyOffset(int yOffset) {
this.yOffset = yOffset;
}
public int getXOffset() {
return Math.round(xOffset);
}
public int getYOffset() {
return Math.round(yOffset);
}
public int getxSize() {
return xSize;
}
public int getySize() {
return ySize;
}
public int getClickYOffset() {
return clickYOffset;
}
public void setClickYOffset(int clickYOffset) {
this.clickYOffset = clickYOffset;
}
public int getClickXOffset() {
return clickXOffset;
}
public void setClickXOffset(int clickXOffset) {
this.clickXOffset = clickXOffset;
}
}