-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrafficGame.sb
779 lines (742 loc) · 20.9 KB
/
TrafficGame.sb
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
' Traffic Game
' Version 0.7b
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Last update 2017-05-24
' Program ID DHW172-5
' 2017-05-15 14:09:50 Shapes generated by Shapes 2.21b.
title = "Traffic Game 0.7b"
GraphicsWindow.Title = title
Init()
InitLane()
InitCars()
' initialize blow
Shapes_Init_Burst()
name = "Burst"
Group_Add()
Program.Delay(500)
i = nGroup
Group_Hide()
InitCaption()
' turn right
angle = 5
i = nGroup - 1
Group_Rotate()
' move right
x = 100
y = 220
For x = 110 To xLane[2] Step 10
Group_Move()
Scroll()
Program.Delay(100)
EndFor
' turn left
angle = 0
Group_Rotate()
' game start
GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.KeyUp = OnKeyUp
speed["Car 1"] = 60
time = 60 ' [sec]
While 0 < time
If keyDown["Right"] Then
' turn right
angle = 5
Group_Rotate()
Group_GetPos()
x = x + 10
Group_Move()
right = "True"
ElseIf right Then
' turn left
angle = 0
Group_Rotate()
right = "False"
EndIf
If keyDown["Left"] Then
' turn left
angle = -5
Group_Rotate()
Group_GetPos()
x = x - 10
Group_Move()
left = "True"
ElseIf left Then
' turn right
angle = 0
Group_Rotate()
left = "False"
EndIf
If keyDown["Up"] Then
speed["Car 1"] = speed["Car 1"] + 10
EndIf
If keyDown["Down"] Then
speed["Car 1"] = speed["Car 1"] - 10
EndIf
Scroll()
Stack.PushValue("local", i)
Collision()
Program.Delay(100)
If 0 < burst Then
burst = burst - 100
If burst <= 0 Then
name = "Burst"
Group_GetIndexOf()
Group_Hide()
EndIf
EndIf
If 0 < ready Then
ready = ready - 100
If ready <= 3000 Then
Shapes.SetText(caption, "READY?")
EndIf
If ready <= 0 Then
Shapes.SetText(caption, "")
Shapes.HideShape(mask)
ShowInfo()
Timer.Interval = 1000
Timer.Tick = OnTick
EndIf
Else
score = score + Math.Floor(speed["Car 1"] / 5)
Shapes.SetText(display, "SCORE " + score)
EndIf
i = Stack.PopValue("local")
EndWhile
Timer.Pause()
Shapes.ShowShape(mask)
Shapes.SetText(caption, "GAME OVER")
Sub ChangeLane
' Change lane for car n
' param n - car number
' param group[i] - of car n
' return x - position x for the changed lane
candidate = "1=1;2=2;3=3;"
m = 5 - n
candidate[lane[m]] = ""
index = Array.GetAllIndices(candidate)
iLane = Math.GetRandomNumber(2)
l = candidate[index[iLane]]
lane[n] = l
x = xLane[l]
EndSub
Sub Collision
' Collision detect
name = "Car 1"
Group_GetIndexOf()
Group_GetPos()
xCar1 = x
yCar1 = y
Group_GetSize()
wCar1 = width
hCar1 = height
cxCar1 = x + width / 2
cyCar1 = y + height / 2
For car = 2 To 3
name = "Car " + car
Group_GetIndexOf()
Group_GetPos()
Group_GetSize()
cx = x + width / 2
cy = y + height / 2
dx = Math.Abs(x - xCar1)
dy = Math.Abs(y - yCar1)
lx = (width + wCar1) / 2
ly = (height + hCar1) / 2
If (dx < lx) And (dy < ly) Then
' collision
xCollision = (cx + cxCar1) / 2
yCollision = (cy + cyCar1) / 2
name = "Burst"
Group_GetIndexOf()
Group_GetSize()
x = xCollision - width / 2
y = yCollision - height / 2
Group_Move()
Group_Show()
burst = 500
score = score - 10 * Math.Abs(speed["Car 1"])
EndIf
EndFor
EndSub
Sub Init
' Initialization
Not = "False=True;True=False;"
right = "False"
left = "False"
xLane = "1=50;2=240;3=430;"
lane = "2=3;3=1;"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
GraphicsWindow.BackgroundColor = "Gray"
SB_Workaround()
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
EndSub
Sub InitCaption
' Initialize caption
' show caption
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#99000000"
mask = Shapes.AddRectangle(gw, gh)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FontSize = 80
GraphicsWindow.FontName = "Trebuchet MS"
caption = Shapes.AddText("TRAFFIC" + CRLF + "GAME")
Shapes.Move(caption, 40, 30)
GraphicsWindow.FontSize = 20
display = Shapes.AddText("")
Shapes.Move(display, 40, 10)
ready = 5000
EndSub
Sub InitCars
' Initialize cars
' initialize truck shapes
Shapes_Init_Truck()
' add to a group
name = "Car 2"
Group_Add()
speed[name] = 40
' initialize crimson car shapes
Shapes_Init_CrimsonCar()
' add to a group
name = "Car 3"
Group_Add()
speed[name] = 40
' initialize blue car shapes
Shapes_Init_BlueCar()
' add to a group
name = "Car 1"
Group_Add()
speed[name] = 40
EndSub
Sub InitLane
' Initialize lane
' initialize lane shapes
Shapes_Init_Lane()
' add to a group
scale = 1
name = "Lane 1"
Group_Add()
' add to a group and move it
name = "Lane 2"
Group_Add()
i = nGroup
x = 0
y = 214
Group_Move()
' add to a group and move it
name = "Lane 3"
Group_Add()
i = nGroup
x = 0
y = 428
Group_Move()
EndSub
Sub OnKeyDown
' Key down event handler
key = GraphicsWindow.LastKey
keyDown[key] = "True"
EndSub
Sub OnKeyUp
' Key up event handler
key = GraphicsWindow.LastKey
keyDown[key] = ""
EndSub
Sub OnTick
' Timer event handler
time = time - 1
ShowInfo()
EndSub
Sub Scroll
' Scroll view
Stack.PushValue("local", n)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Stack.PushValue("local", name)
Stack.PushValue("local", grp)
Stack.PushValue("local", i)
For n = 1 To 3
name = "Lane " + n
Group_GetIndexOf()
grp = group[i]
x = grp["x"]
y = grp["y"]
y = y + speed["Car 1"] / 4
If gh < y Then
y = y - 1.5 * gh
ElseIf y < -0.5 * gh Then
y = y + 1.5 * gh
EndIf
Group_Move()
EndFor
For n = 2 To 3
name = "Car " + n
Group_GetIndexOf()
grp = group[i]
x = grp["x"]
y = grp["y"]
y = y - (speed[name] - speed["Car 1"]) / 4
If gh < y Then
y = y - 1.5 * gh
ChangeLane()
ElseIf y < -0.5 * gh Then
y = y + 1.5 * gh
ChangeLane()
EndIf
Group_Move()
EndFor
i = Stack.PopValue("local")
grp = Stack.PopValue("local")
name = Stack.PopValue("local")
y = Stack.PopValue("local")
x = Stack.PopValue("local")
n = Stack.PopValue("local")
EndSub
Sub ShowInfo
GraphicsWindow.Title = title + " | " + speed["Car 1"] + " km/h | " + time + " sec"
EndSub
Sub Group_Add
' Group | add shapes to a group
' param name - group name
' param shX, shY, origin of shape array
' param shape[] - shape array
' param nGroup - number of group
' return nGroup - updated number of group
' return group - group array
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
nGroup = nGroup + 1
grp = ""
grp["name"] = name
grp["x"] = shX
grp["y"] = shY
grp["angle"] = 0
grp["dir"] = 1
Shapes_CalcWidthAndHeight()
grp["width"] = shWidth
grp["cx"] = shWidth / 2
grp["height"] = shHeight
s = 1
grp["scale"] = s
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
grp["shape"] = shape
group[nGroup] = grp
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Group_GetIndexOf
' Group | Get index of a group
' param name - a group name
' return i - index of the group
Stack.PushValue("local", _i)
i = 0 ' not found
For _i = 1 To nGroup
grp = group[_i]
If grp["name"] = name Then
i = _i
_i = nGroup ' exit For
EndIf
EndFor
_i = Stack.PopValue("local")
EndSub
Sub Group_GetPos
' Group | Get position of a group
' param group[i] - a group
' return x, y - position of the group
grp = group[i]
x = grp["x"]
y = grp["y"]
EndSub
Sub Group_GetSize
' Group | Get size of a group
' param group[i] - a group
' return width, height - size of the group
grp = group[i]
width = grp["width"]
height = grp["height"]
EndSub
Sub Group_Hide
' Group | Hide a group
' param group[i] - group to move
grp = group[i]
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
Shapes.HideShape(shp["obj"])
EndFor
EndSub
Sub Group_Move
' Group | Move a group
' param group[i] - group to move
' param x, y - position to move
' return group[i] - updated group
Stack.PushValue("local", grp)
Stack.PushValue("local", s)
Stack.PushValue("local", shape)
Stack.PushValue("local", n)
Stack.PushValue("local", j)
Stack.PushValue("local", shp)
Stack.PushValue("local", _x)
Stack.PushValue("local", _y)
grp = group[i]
s = grp["scale"]
grp["x"] = x
grp["y"] = y
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], grp["x"] + _x * s, grp["y"] + _y * s)
EndFor
group[i] = grp
_y = Stack.PopValue("local")
_x = Stack.PopValue("local")
shp = Stack.PopValue("local")
j = Stack.PopValue("local")
n = Stack.PopValue("local")
shape = Stack.PopValue("local")
s = Stack.PopValue("local")
grp = Stack.PopValue("local")
EndSub
Sub Group_Remove
' Group | Remove a group
' param group[i] - group to move
group[i] = ""
EndSub
Sub Group_Rotate
' Group | Rotate a group
' param group[i] - group to move
' param cx, cy - rotation center (if given)
' param angle - to rotate
Stack.PushValue("local", x)
Stack.PushValue("local", y)
param["angle"] = angle
If cx <> "" Then
param["cx"] = cx
Else
cx = "" ' to avoid syntax error
param["cx"] = shWidth / 2
EndIf
If cy <> "" Then
param["cy"] = cy
Else
cy = "" ' to avoid syntax error
param["cy"] = shHeight / 2
EndIf
grp = group[i]
s = grp["scale"]
shape = grp["shape"]
shX = grp["x"]
shY = grp["y"]
n = Array.GetItemCount(shape)
Stack.PushValue("local", i)
For i = 1 To n
shp = shape[i]
param["x"] = shp["x"]
param["y"] = shp["y"]
param["width"] = shp["width"]
param["height"] = shp["height"]
Shapes_CalcRotatePos()
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(angle + shp["angle"])
SB_RotateWorkAround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
Shapes.Rotate(shp["obj"], angle + shp["angle"])
shape[i] = shp
EndFor
i = Stack.PopValue("local")
grp["shape"] = shape
group[i] = grp
y = Stack.PopValue("local")
x = Stack.PopValue("local")
EndSub
Sub Group_Show
' Group | Show a group
' param group[i] - group to move
grp = group[i]
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
Shapes.ShowShape(shp["obj"])
EndFor
EndSub
Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
ElseIf x = 0 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub
Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param shp - current shape
' param x, y - original coordinate
' param alpha - angle [radian]
' returns x, y - workaround coordinate
If shp["func"] = "tri" Then
x1 = -Math.Floor(shp["x3"] / 2)
y1 = -Math.Floor(shp["y3"] / 2)
ElseIf shp["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shp["x1"] - shp["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shp["y1"] - shp["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub
Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub
Sub Shapes_Init_BlueCar
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 100 ' x offset
shY = 220 ' y offset
shape = ""
shape[1] = "func=rect;x=0;y=29;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[2] = "func=rect;x=83;y=28;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[3] = "func=rect;x=1;y=141;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[4] = "func=rect;x=83;y=142;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[5] = "func=rect;x=15;y=0;width=91;height=199;bc=#5A95CD;pw=0;"
shape[6] = "func=rect;x=29;y=64;width=65;height=98;bc=#3B3B3B;pw=0;"
shape[7] = "func=rect;x=35;y=85;width=53;height=68;bc=#5A95CD;pw=0;"
shape[8] = "func=line;x=28;y=64;x1=0;y1=0;x2=8;y2=21;pc=#5A95CD;pw=2;"
shape[9] = "func=line;x=87;y=63;x1=6;y1=0;x2=0;y2=22;pc=#5A95CD;pw=2;"
shape[10] = "func=line;x=86;y=152;x1=0;y1=0;x2=7;y2=10;pc=#5A95CD;pw=2;"
shape[11] = "func=line;x=28;y=151;x1=8;y1=0;x2=0;y2=11;pc=#5A95CD;pw=2;"
shape[12] = "func=rect;x=20;y=192;width=22;height=6;bc=#800000;pw=0;"
shape[13] = "func=rect;x=78;y=192;width=22;height=6;bc=#800000;pw=0;"
shape[14] = "func=ell;x=24;y=7;width=19;height=25;bc=#66FFFFFF;pw=0;"
shape[15] = "func=ell;x=78;y=7;width=19;height=25;bc=#66FFFFFF;pw=0;"
EndSub
Sub Shapes_Init_Burst
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 100 ' x offset
shY = 160 ' y offset
shape = ""
shape[1] = "pw=0;bc=Red;func=ell;width=40;height=40;x=30;y=30;angle=0;"
shape[2] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=43.16;y=0.01;"
shape[3] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=65.26;y=8.06;angle=40;"
shape[4] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=77.02;y=28.43;angle=80;"
shape[5] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=72.94;y=51.6;angle=120;"
shape[6] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=54.92;y=66.72;angle=160;"
shape[7] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=31.39;y=66.72;angle=200;"
shape[8] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=13.37;y=51.6;angle=240;"
shape[9] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=9.29;y=28.43;angle=280;"
shape[10] = "pw=0;bc=Red;func=tri;x1=6.84;y1=0;x2=0;y2=31.2;x3=13.68;y3=31.2;x=21.05;y=8.06;angle=320;"
EndSub
Sub Shapes_Init_CrimsonCar
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 50 ' x offset
shY = 10 ' y offset
shape = ""
shape[1] = "func=rect;x=0;y=29;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[2] = "func=rect;x=83;y=28;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[3] = "func=rect;x=1;y=141;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[4] = "func=rect;x=83;y=142;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[5] = "func=rect;x=15;y=0;width=91;height=199;bc=#DC143C;pw=0;"
shape[6] = "func=rect;x=29;y=64;width=65;height=98;bc=#3B3B3B;pw=0;"
shape[7] = "func=rect;x=35;y=85;width=53;height=68;bc=#DC143C;pw=0;"
shape[8] = "func=line;x=28;y=64;x1=0;y1=0;x2=8;y2=21;pc=#DC143C;pw=2;"
shape[9] = "func=line;x=87;y=63;x1=6;y1=0;x2=0;y2=22;pc=#DC143C;pw=2;"
shape[10] = "func=line;x=86;y=152;x1=0;y1=0;x2=7;y2=10;pc=#DC143C;pw=2;"
shape[11] = "func=line;x=28;y=151;x1=8;y1=0;x2=0;y2=11;pc=#DC143C;pw=2;"
shape[12] = "func=rect;x=20;y=192;width=22;height=6;bc=#800000;pw=0;"
shape[13] = "func=rect;x=78;y=192;width=22;height=6;bc=#800000;pw=0;"
shape[14] = "func=ell;x=24;y=7;width=19;height=25;bc=#66FFFFFF;pw=0;"
shape[15] = "func=ell;x=79;y=7;width=19;height=25;bc=#66FFFFFF;pw=0;"
EndSub
Sub Shapes_Init_Lane
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 0 ' x offset
shY = 0 ' y offset
shape = ""
shape[1] = "func=line;x1=20;y1=0;x2=20;y2=107;pc=#FFFFFF;pw=8;"
shape[2] = "func=line;x1=206;y1=0;x2=206;y2=107;pc=#FFFFFF;pw=8;"
shape[3] = "func=line;x1=392;y1=0;x2=392;y2=107;pc=#FFFFFF;pw=8;"
shape[4] = "func=line;x1=578;y1=0;x2=578;y2=107;pc=#FFFFFF;pw=8;"
EndSub
Sub Shapes_Init_Truck
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 430 ' x offset
shY = 150 ' y offset
shape = ""
shape[1] = "func=rect;x=0;y=20;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[2] = "func=rect;x=77;y=23;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[3] = "func=rect;x=0;y=154;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[4] = "func=rect;x=77;y=156;width=36;height=44;bc=#3B3B3B;pw=0;"
shape[5] = "func=rect;x=11;y=0;width=93;height=230;bc=#C2C2C2;pw=0;"
shape[6] = "func=rect;x=17;y=25;width=81;height=55;bc=#3B3B3B;pw=0;"
shape[7] = "func=rect;x=27;y=35;width=62;height=48;bc=#C2C2C2;pw=0;"
shape[8] = "func=line;x=17;y=24;x1=11;y1=14;x2=0;y2=0;pc=#C2C2C2;pw=2;"
shape[9] = "func=line;x=87;y=23;x1=0;y1=16;x2=12;y2=0;pc=#C2C2C2;pw=2;"
shape[10] = "func=rect;x=17;y=222;width=22;height=6;bc=#800000;pw=0;"
shape[11] = "func=rect;x=75;y=222;width=22;height=6;bc=#800000;pw=0;"
shape[12] = "func=ell;x=77;y=4;width=21;height=15;bc=#66FFFFFF;pw=0;"
shape[13] = "func=ell;x=17;y=4;width=21;height=15;bc=#66FFFFFF;pw=0;"
shape[14] = "func=rect;x=17;y=85;width=81;height=134;bc=#807547;pw=0;"
EndSub
Sub Shapes_CalcRotatePos
' Shapes | Calculate position for rotated shape
' param["x"], param["y"] - position of a shape
' param["width"], param["height"] - size of a shape
' param ["cx"], param["cy"] - center of rotation
' param ["angle"] - rotate angle
' return x, y - rotated position of a shape
_cx = param["x"] + param["width"] / 2
_cy = param["y"] + param["height"] / 2
x = _cx - param["cx"]
y = _cy - param["cy"]
Math_CartesianToPolar()
a = a + param["angle"]
x = r * Math.Cos(a * Math.Pi / 180)
y = r * Math.Sin(a * Math.Pi / 180)
_cx = x + param["cx"]
_cy = y + param["cy"]
x = _cx - param["width"] / 2
y = _cy - param["height"] / 2
EndSub
Sub Shapes_CalcWidthAndHeight
' Shapes | Calculate total width and height of shapes
' param shape[] - shape array
' return shWidth, shHeight - total size of shapes
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
If shp["func"] = "tri" Or shp["func"] = "line" Then
xmin = shp["x1"]
xmax = shp["x1"]
ymin = shp["y1"]
ymax = shp["y1"]
If shp["x2"] < xmin Then
xmin = shp["x2"]
EndIf
If xmax < shp["x2"] Then
xmax = shp["x2"]
EndIf
If shp["y2"] < ymin Then
ymin = shp["y2"]
EndIf
If ymax < shp["y2"] Then
ymax = shp["y2"]
EndIf
If shp["func"] = "tri" Then
If shp["x3"] < xmin Then
xmin = shp["x3"]
EndIf
If xmax < shp["x3"] Then
xmax = shp["x3"]
EndIf
If shp["y3"] < ymin Then
ymin = shp["y3"]
EndIf
If ymax < shp["y3"] Then
ymax = shp["y3"]
EndIf
EndIf
shp["width"] = xmax - xmin
shp["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shp["x"] + shp["width"]
shHeight = shp["y"] + shp["height"]
Else
If shWidth < shp["x"] + shp["width"] Then
shWidth = shp["x"] + shp["width"]
EndIf
If shHeight < shp["y"] + shp["height"] Then
shHeight = shp["y"] + shp["height"]
EndIf
EndIf
shape[i] = shp
EndFor
EndSub