-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cam2D.pde
56 lines (46 loc) · 1.16 KB
/
Cam2D.pde
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
/**
* The camera 2d class does the main translation of the game. acting as a camera moving around
* it does the movements smoothly, thus not 100% on the target all the time.
*
*/
class Cam2D extends GameObject {
// how fast the camera moves
float smoothFactor;
/**
* Creates a camera where 0,0 is at the center of the screen
* Also starts smooth panning
*/
Cam2D() {
super(width/2, height/2);
des = loc.copy();
smoothFactor = .1;
}
/**
* Creates a camera where 0,0 is at x,y
* Also starts smooth panning
* @param x_ x location for center
* @param y_ y location for center
*/
Cam2D(float x_, float y_, float angle_) {
super(x_, y_, angle_);
angleDes = angle_;
des = loc.copy();
smoothFactor = .1;
}
/**
* Overrides the default blank gameObject update method
* Should be ran every game tick
*/
@Override
void update() {
smoothMove(smoothFactor);
smoothRotate(smoothFactor);
for (int c = 0; c < updatePhysics; c++) {
simplePhysicsCal();
}
translate(width/2-width/4,height/2);
rotate(angle);
scale(sin(millis()*0.01)*0.05+1+0.05);
translate(loc.x, loc.y);
}
}