-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht_camera.bmx
147 lines (108 loc) · 4 KB
/
t_camera.bmx
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
SuperStrict
Import "common.bmx"
''camera
Global camera:t_camera
''follow
Const CF_NONE:Int = 0
Const CF_BALL:Int = 1
Const CF_TARGET:Int = 2
''speed
Const CS_NORMAL:Int = 0
Const CS_FAST:Int = 1
Const CS_WARP:Int = 2
Type t_camera
Field x:Float ''position
Field y:Float
Field vx:Float ''speed
Field vy:Float
Field offx:Int ''offset
Field offy:Int
Method set_x(x0:Int)
x = x0
End Method
Method set_y(y0:Int)
y = y0
End Method
''follow: CF_NONE, CF_BALL, CF_TARGET
''speed: CS_NORMAL, CS_FAST, CS_WARP
Method updatex:Float(follow:Int, speed:Int = CS_NORMAL, target_x:Int = 0, limit:Int = True)
Select follow
Case CF_NONE
''do nothing
Case CF_BALL
If (ball.v * Cos(ball.a) <> 0)
Self.offx = game_settings.screen_width / 20.0 * Cos(ball.a) ''"remember" last direction of movement
EndIf
''speed
If (Abs(Self.vx) > Abs(ball.v * Cos(ball.a)))
''decelerate
Self.vx = (1 - 5.0/SECOND) * Self.vx
Else
''accelerate
Self.vx = Self.vx + (2.5/SECOND) * Sgn(Self.offx) * Abs(Self.vx - ball.v * Cos(ball.a))
EndIf
Self.x = Self.x + Self.vx / SECOND
''near the point "ball+offset"
If (Abs(ball.x + Self.offx - (Self.x - CENTER_X + game_settings.screen_width/(2*game_settings.zoom/100.0))) => 10)
Local f:Float = ball.x +Self.offx -(Self.x -CENTER_X +game_settings.screen_width/(2*game_settings.zoom/100.0))
Self.x = Self.x + (10.0/SECOND) * (1 + speed) * Sgn(f) * Sqr(Abs(f))
EndIf
Case CF_TARGET
Self.x = Self.x + (10.0/SECOND) * (1 + speed) * Sgn(target_x -(Self.x -CENTER_X +game_settings.screen_width/(2*game_settings.zoom/100.0))) * Sqr( Abs(target_x -(Self.x -CENTER_X +game_settings.screen_width/(2*game_settings.zoom/100.0))))
End Select
''keep inside pitch
Local xmin:Int, xmax:Int
xmin = 0
xmax = PITCH_W - game_settings.screen_width/(game_settings.zoom/100.0)
If ((game_settings.screen_width < 1600) And limit)
xmin = CENTER_X - TOUCH_LINE - game_settings.screen_width/(8*game_settings.zoom/100.0)
xmax = CENTER_X + TOUCH_LINE + game_settings.screen_width/(8*game_settings.zoom/100.0) - game_settings.screen_width/(game_settings.zoom/100.0)
EndIf
If (Self.x < xmin)
Self.x = xmin
EndIf
If (Self.x > xmax)
Self.x = xmax
EndIf
Return Self.x
End Method
''follow: CF_NONE, CF_BALL, CF_TARGET
''speed: CS_NORMAL, CS_FAST, CS_WARP
Method updatey:Float(follow:Int, speed:Int = CS_NORMAL, target_y:Int = 0)
Select follow
Case CF_NONE
''do nothing
Case CF_BALL
If (ball.v * Cos(ball.a) <> 0)
Self.offy = game_settings.screen_height / 20.0 * Sin(ball.a) ''"remember" last direction of movement
EndIf
''speed
If (Abs(Self.vy) > Abs(ball.v * Sin(ball.a)))
''decelerate
Self.vy = (1 - 5.0/SECOND) * Self.vy
Else
''accelerate
Self.vy = Self.vy + (2.5/SECOND) * Sgn(Self.offy) * Abs(Self.vy - ball.v * Sin(ball.a))
EndIf
Self.y = Self.y + Self.vy / SECOND
''near the point "ball+offset"
If (Abs(ball.y + Self.offy - (Self.y - CENTER_Y + game_settings.screen_height/(2*game_settings.zoom/100.0))) => 10)
Local f:Float = ball.y +Self.offy -(Self.y -CENTER_Y +game_settings.screen_height/(2*game_settings.zoom/100.0))
Self.y = Self.y + (10.0/SECOND) * (1 + speed) * Sgn(f) * Sqr(Abs(f))
EndIf
Case CF_TARGET
Self.y = Self.y + (10.0/SECOND) * (1 + speed) * Sgn(target_y -(Self.y -CENTER_Y +game_settings.screen_height/(2*game_settings.zoom/100.0))) * Sqr( Abs(target_y -(Self.y -CENTER_Y +game_settings.screen_height/(2*game_settings.zoom/100.0))))
End Select
''keep inside pitch
Local ymin:Int, ymax:Int
ymin = 0
ymax = PITCH_H - game_settings.screen_height/(game_settings.zoom/100.0)
If (Self.y < ymin)
Self.y = ymin
EndIf
If (Self.y > ymax)
Self.y = ymax
EndIf
Return Self.y
End Method
End Type