-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.as
79 lines (71 loc) · 1.62 KB
/
Camera.as
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
package
{
import net.flashpunk.Entity;
import net.flashpunk.FP;
/**
* ...
* @author Bijan
*/
public class Camera extends Entity
{
private var m_player:Player;
private var m_world:GameWorld;
private var cameraOffset:Number = 200;
private var cameraSpeed:Number = 0;
private var cameraAccel:Number = 1;
private var cameraPadding:int = 10;
private var mapWidth:Number = 0;
private var mapHeight:Number = 0;
//1: horizontal, positioned ahead of player, no y movement
//2: balanced, positioned evenly, y movement
//3: vertical, y movement, no x movement
//4: default: x movement, y movement, ahead of player
private var cameraProfile:int = 1;
public function Camera(world:GameWorld)
{
m_player = world.player;
m_world = world;
mapWidth = m_world.level.mapWidth;
mapHeight = m_world.level.mapHeight;
x = FP.camera.x = 0;
y = FP.camera.y = 0;
}
override public function update():void
{
switch(cameraProfile)
{
case 1:
x = FP.camera.x = m_player.x - FP.halfWidth/2;
break;
case 2:
x = FP.camera.x = m_player.x - FP.halfWidth;
break;
case 3:
y = FP.camera.y = m_player.y - FP.halfHeight;
break;
default:
x = FP.camera.x = m_player.x - FP.halfWidth;
y = FP.camera.y = m_player.y - FP.halfHeight;
break;
}
}
public function setProfile(profile:String):void
{
switch(profile)
{
case "horizontal":
cameraProfile = 1;
break;
case "balanced":
cameraProfile = 2;
break;
case "vertical":
cameraProfile = 3;
break;
default:
cameraProfile = 4;
break;
}
}
}
}