-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclsSnake.cls
1136 lines (842 loc) · 31.3 KB
/
clsSnake.cls
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
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsSnake"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Head As tPosAndVel
Private Token() As tPosAndVel
Private Const MaxNtok As Long = 1023 ' 199
Public Ntokens As Long
Private InvNtokens As Double
Private InvNtokens2 As Double
Private SQRNtokens As Double
'Public MySIZE As Double
Public tokIDX As Long
Public MyIDX As Long
Private Color As Long
Public ColorR As Double
Public ColorG As Double
Public ColorB As Double
Private DirChange As geoVector2D
Private EyEANG As Double
Private oldANG As Double
Public Diam As Double
Public InvDiam As Double
Public Radius As Double
Public IsDying As Long
Public DyingTime As Long
Private BB As tBB
Public TongueOut As Double
Public TongueLen As Double
Private fLength As Double
Public FASTspeed As Long
Public FASTspeedCOUNT As Long
Private Const SPEED As Double = 2.5 ' 3 '3.5
Public SearchForFOODMODE As Double
Private EYESWIDE As Double
Private FlagToken As Long
Private FlagX As Double
Private FlagY As Double
Private FlagZ As Double
Private FlagVelZ As Double
'
'---------------------------------------------
' LEGS
Private FrontDist As Double
Private FrontPhase As Double
Private Feet(1 To 4) As geoVector2D
Private FeetToGO(1 To 4) As geoVector2D
Private iFront As Long
Private iRear As Long
Private lungGambaT As Double
Private INVlungGambaT As Double
Private LsPeed As Double
'---------------------------------------------
Public Property Get GetSize() As Double
GetSize = fLength
End Property
Public Property Let SetSize(V As Double)
fLength = V
'DIAM = 5 * (fLength + 10) ^ (0.4)
'Diam = 5 * (fLength + 15) ^ (0.45)
'Diam = 5 * (fLength + 15) ^ (0.5) '------ 2nd video
'Diam = 5# * (fLength + 16#) ^ (0.5) ''' OK
Diam = 1 + 4.5 * (fLength) ^ 0.5
Radius = Diam * 0.5
InvDiam = 1# / Diam
End Property
Friend Property Get GetHEADPos() As geoVector2D
GetHEADPos = Token(tokIDX).POS
End Property
Friend Property Get GetHEADVel() As geoVector2D
GetHEADVel = Token(tokIDX).Vel
End Property
Friend Property Let SetHEADVel(NV As geoVector2D)
Token(tokIDX).Vel = NV
End Property
Friend Property Get GetTokenPos(wT As Long) As geoVector2D
GetTokenPos = Token(wT).POS
End Property
Friend Function getBB() As tBB
getBB = BB
End Function
'Friend Function getBB() As tBB
' Dim I As Long
'
' getBB.minX = wMaxX * 2
' getBB.minY = wMaxY * 2
' getBB.maxX = wMinX * 2
' getBB.maxY = wMinY * 2
'
'
' For I = 0 To Ntokens
' With Token(I).Pos
' If .x < getBB.minX Then getBB.minX = .x
' If .y < getBB.minY Then getBB.minY = .y
' If .x > getBB.maxX Then getBB.maxX = .x
' If .y > getBB.maxY Then getBB.maxY = .y
' End With
' Next
'
'End Function
Friend Sub UpdateBB(Optional Extra As Boolean = False)
Dim I As Long
BB.minX = 1E+32
BB.minY = 1E+32
BB.maxX = -1E+32
BB.maxY = -1E+32
Dim D2 As Double
D2 = Diam * 2
If Extra Then D2 = Diam * 6
For I = 0 To Ntokens
With Token(I).POS
If .x - D2 < BB.minX Then BB.minX = .x - D2
If .y - D2 < BB.minY Then BB.minY = .y - D2
If .x + D2 > BB.maxX Then BB.maxX = .x + D2
If .y + D2 > BB.maxY Then BB.maxY = .y + D2
End With
Next
End Sub
Friend Sub Init(x As Double, y As Double, Idx As Long, Leng As Double)
Dim I As Long
'fLength = Leng
SetSize = Leng
Ntokens = fLength
ReDim Token(MaxNtok)
MyIDX = Idx
' If MyIDX <> PLAYER Then
' MySIZE = (1 - rndm * 0.65) * 4.5
' Else
' MySIZE = 3
' End If
''' DIAM = MySIZE * 7
tokIDX = 1
x = wMinX + (wMaxX - wMinX) * RndM
y = wMinY + (wMaxY - wMinY) * RndM
For I = 0 To Ntokens
Token(I).POS.x = x
Token(I).POS.y = y
Next
Head.POS.x = x
Head.POS.y = y
Head.Vel.x = RndM * 2 - 1
Head.Vel.y = RndM * 2 - 1
'Color = RGB(120 + rndm * 135, 120 + rndm * 135, 120 + rndm * 135)
'' ColorR = 0.45 + rndm * 0.5
'' ColorG = 0.45 + rndm * 0.5
'' ColorB = 0.45 + rndm * 0.5
Do
ColorR = RndM
ColorG = RndM
ColorB = RndM
Loop While (ColorR + ColorG + ColorB) < 1.6
UpdateBB
FlagToken = Ntokens \ 2
FlagX = Token(FlagToken).POS.x
FlagY = Token(FlagToken).POS.y
End Sub
Private Sub RandomizeMe()
Dim x As Double
Dim y As Double
Dim POS As geoVector2D
Dim I As Long
IsDying = 0 ' False
SetSize = STARTLENGTH
fLength = STARTLENGTH
Ntokens = fLength
InvNtokens = 1 / Ntokens
InvNtokens2 = 1 / (Ntokens - 2)
ReDim Token(MaxNtok)
'' MySIZE = (1 - rndm * 0.65) * 4.5
'' 'DIAM = MySIZE * 7
tokIDX = 1
POS = NewSnakePosition(MyIDX)
x = POS.x
y = POS.y
For I = 0 To Ntokens
Token(I).POS.x = x
Token(I).POS.y = y
Next
Head.POS.x = x
Head.POS.y = y
Head.Vel.x = 0 ' RndM * 2 - 1
Head.Vel.y = 0 ' RndM * 2 - 1
'Color = RGB(120 + rndm * 135, 120 + rndm * 135, 120 + rndm * 135)
ColorR = 0.45 + RndM * 0.5
ColorG = 0.45 + RndM * 0.5
ColorB = 0.45 + RndM * 0.5
UpdateBB
SearchForFOODMODE = 1.2 + RndM * 0.8
EYESWIDE = SearchForFOODMODE
FlagToken = Ntokens \ 2
FlagX = Token(FlagToken).POS.x
FlagY = Token(FlagToken).POS.y
End Sub
Friend Sub DRAW(DrawBoundingBox As Long)
Dim ANG As Double
Dim A As Double
Dim A2 As Double
Dim Reye As Double
Dim Reye2 As Double
Dim DEye As Double
Dim I As Double 'Long
Dim StepD As Double 'Long
Dim J As Long
Dim J2 As Long
Dim P As geoVector2D
Dim X1 As Double
Dim Y1 As Double
Dim x2 As Double
Dim Y2 As Double
Dim dx As Double
Dim dy As Double
Dim C As Double
Dim S As Double
Dim K As Double
' Dim InvNtokens
Dim CADD As Double
Dim LA As Long
Dim AA&
If BBOverlapping(CameraBB, BB) = False Then Exit Sub
Reye = Diam * 0.25
Reye2 = Reye * 0.85
DEye = Reye * 1.65 '2
'If MyIDX = PLAYER Then Stop
'StepD = 1 + Diam * 0.0125
'StepD = 1 + Diam * Diam * 0.0004 '1st version
'' StepD = 1 + Diam * Diam * Diam * 0.0000062 '--2024 I e stepD as double
' StepD = Diam * Diam * 0.00055 ' 0.00065
StepD = Ntokens * 0.01
If StepD < 1 Then StepD = 1
With vbDrawCC
If IsDying Then
StepD = 1
.SetSourceRGBA RndM, RndM, RndM, 0.33
' For I = tokIDX + 1 To tokIDX + Ntokens - 1 Step StepD
For J = 0 To Ntokens
' 'J = I Mod Ntokens
' DivRem I, Ntokens, J
P = Token(J).POS
'.Ellipse P.x, P.y, Diam, Diam
.Arc P.x, P.y, Radius
.Fill
Next
' If (CNT - DyingTime > 40) Then '104 '' Blinking time
' CreateFoodFromDeadSnake MyIDX
' RandomizeMe
' If MyIDX = PLAYER Then
' LIFES = LIFES - 1
' If LIFES = 0 Then
' Print #1, Level & " Lifes " & LIFES & " Score " & PlayerScore
'
' InitPool 6, True
' InitFOOD 6 * FoodXSnake
' MultipleSounds.PlaySound SoundINTRO
' End If
' End If
' End If
Else
' InvNtokens = 1# / (Ntokens)
' K = 0
' For I = tokIDX + 1 To tokIDX + Ntokens - 1 Step StepD 'Senza -1 disegna anche testa
' J = I Mod Ntokens
' P = Token(J).POS
' K = K + StepD
' CADD = Cos((-K * InvNtokens) * PI2 * 5#) * 0.2
' .SetSourceRGBA ColorR + CADD, ColorG + CADD, ColorB + CADD ', 0.9
' .Ellipse P.x, P.y, Diam, Diam
' .Fill
' Next
''''' GoTo DRAW2
'''''
''''' K = 0
''''' I = tokIDX + StepD * 1 + 1
''''' 'J = I Mod Ntokens
''''' DivRem I, Ntokens, J
'''''
''''' P = Token(J).POS
''''' K = K + StepD
'''''
''''' .MoveTo P.x, P.y
'''''
'''''
''''' K = -StepD
''''' For I = tokIDX + StepD + 2 To tokIDX + Ntokens Step StepD 'Senza -1 disegna anche testa
''''' 'J = I Mod Ntokens
''''' DivRem I, Ntokens, J
''''' P = Token(J).POS
''''' K = K + StepD
''''' 'To Avoid Head->Queue Line:
''''' DivRem (tokIDX + StepD), Ntokens, J2
''''' If J <> J2 Then
''''' ' 'CADD = Cos((-K * InvNtokens) * PI2 * 5#) * 0.2 - FASTspeed * 0.25
''''' 'CADD = Cos((K * InvNtokens2) * PI2 * 3.5) * 0.2 - FASTspeed * 0.25
'''''
''''' AA = ((K * InvNtokens2) * 360 * 4) Mod 360
''''' CADD = -COStable(AA) * 0.21 - FASTspeed * 0.25
''''' .SetSourceRGB ColorR + CADD, ColorG + CADD, ColorB + CADD
''''' .LineTo P.x, P.y
''''' .Stroke
''''' End If
''''' .MoveTo P.x, P.y
''''' Next
''''' .LineTo Head.POS.x, Head.POS.y ''REM '--2024
''''' .Stroke
''''' End If
DRAW2:
.SetLineWidth Diam
P = Token(Ntokens).POS
.MoveTo P.x, P.y
For I = Ntokens - 1 To 0 Step -StepD
P = Token(I).POS
AA = ((I * InvNtokens) * 360 * (SQRNtokens * 0.66)) Mod 360
CADD = -COStable(AA) * 0.21 - FASTspeed * 0.25
' .SetLineWidth Diam + 0.0618 * Diam * COStable(AA) '<<--- ??? experim width cosinusoidal
.SetSourceRGB ColorR + CADD, ColorG + CADD, ColorB + CADD
.LineTo P.x, P.y
.Stroke
.MoveTo P.x, P.y
Next
.LineTo Head.POS.x, Head.POS.y ''REM '--2024
.Stroke
End If
'''' LEGS
' .MoveTo Token(iFront).POS.x, Token(iFront).POS.y
' ' .LineTo Gino(1).x, Gino(1).y
' .LineTo Feet(1).x, Feet(1).y
' .Stroke
' .MoveTo Token(iFront).POS.x, Token(iFront).POS.y
' ' .LineTo Gino(2).x, Gino(2).y
' .LineTo Feet(2).x, Feet(2).y
' .Stroke
'
'
' ' .MoveTo Token(iRear).POS.x, Token(iRear).POS.y
' '' .LineTo Gino(3).x, Gino(3).y
' ' .LineTo Feet(3).x, Feet(3).y
' ' .Stroke
' ' .MoveTo Token(iRear).POS.x, Token(iRear).POS.y
' '' .LineTo Gino(2).x, Gino(2).y
' ' .LineTo Feet(4).x, Feet(4).y
' ' .Stroke
'---------------------------------------------
'........................................
'Drawhead EYES
'.SetLineWidth 1 * Diam
.SetLineWidth 0.05 * Diam
ANG = Atan2(Head.Vel.x, Head.Vel.y)
'--------Tongue
TongueLen = TongueLen * 0.3 + TongueOut * 0.7
TongueOut = TongueOut * 0.6
' C = Cos(ANG) * Diam * TongueLen * 0.55 '* 0.45
' S = Sin(ANG) * Diam * TongueLen * 0.55 '* 0.45
LA = ANG * 360 * InvPI2
C = COStable(LA) * Diam * TongueLen * 0.55 '* 0.45
S = SINtable(LA) * Diam * TongueLen * 0.55 '* 0.45
X1 = Head.POS.x + C
Y1 = Head.POS.y + S
.SetSourceRGBA 1, 0.6, 0.6, 0.4
'.Ellipse X1, Y1, Diam * 0.67, Diam * 0.67
.Arc X1, Y1, Diam * 0.335
.Fill
'-----------------Draw Head
.SetSourceRGB ColorR + CADD, ColorG + CADD, ColorB + CADD
.Ellipse Head.POS.x, Head.POS.y, Diam, Diam
.Arc Head.POS.x, Head.POS.y, Radius
.Fill
'---------------------------------
' If MyIDX = PLAYER Then
' EyEANG = Atan2(DirChange.x, DirChange.y)
EyEANG = EyEANG + 0.25 * AngleDIFF(EyEANG, Atan2(DirChange.x, DirChange.y)) '--2024
' Else
' EyEANG = oldANG
' End If
If IsDying Then EyEANG = (CNT + DyingTime) * 0.3
.SetSourceRGB 1, 1, 0.85 'EYEBALLS
A = ANG - PIh * 0.5
'C = Cos(A) * Reye * EYESWIDE
'S = Sin(A) * Reye * EYESWIDE
LA = (A * 360 * InvPI2) 'Mod 360
C = COStable(LA) * Reye * EYESWIDE
S = SINtable(LA) * Reye * EYESWIDE
X1 = Head.POS.x + C
Y1 = Head.POS.y + S
'.Ellipse X1, Y1, DEye, DEye
.Arc X1, Y1, DEye * 0.5
x2 = Head.POS.x - S
Y2 = Head.POS.y + C
'.Ellipse x2, Y2, DEye, DEye
.Arc x2, Y2, DEye * 0.5
.Fill
.SetSourceRGBA 0, 0, 0, 0.55 'eye contour
'.Ellipse X1, Y1, DEye, DEye
.Arc X1, Y1, DEye * 0.5
.Stroke
x2 = Head.POS.x - S
Y2 = Head.POS.y + C
'.Ellipse x2, Y2, DEye, DEye
.Arc x2, Y2, DEye * 0.5
.Stroke
.SetSourceColor 0 'PUPILS
dx = Cos(EyEANG) * (Reye * 0.5)
dy = Sin(EyEANG) * (Reye * 0.5)
LA = (EyEANG * InvPI2 * 360#) Mod 360
dx = COStable(LA) * (Reye * 0.5)
dy = SINtable(LA) * (Reye * 0.5)
'.Ellipse X1 + dx, Y1 + dy, Reye2, Reye2
.Arc X1 + dx, Y1 + dy, Reye2 * 0.5
'.Ellipse x2 + dx, Y2 + dy, Reye2, Reye2
.Arc x2 + dx, Y2 + dy, Reye2 * 0.5
.Fill
'........................................
If DrawBoundingBox Then
.Rectangle BB.minX, BB.minY, BB.maxX - BB.minX, BB.maxY - BB.minY
.Stroke
End If
End With
End Sub
Friend Sub DRAWFlag()
If BBOverlapping(CameraBB, BB) = False Then Exit Sub
'-------- FLAG --------------
Dim X1#, Y1#
With vbDrawCC
.SetLineWidth Diam * 0.12 '0.15
X1 = Token(FlagToken).Vel.x * Diam * 0.35 '- Diam * 0.5
Y1 = Token(FlagToken).Vel.y * Diam * 0.35 '- Diam * 0.5
.SetSourceRGB ColorR * 0.85, ColorG * 0.85, ColorB * 0.85
.Arc Token(FlagToken).POS.x, Token(FlagToken).POS.y, Diam * 0.15 '0.175
.Fill
'.SetSourceRGBA ColorR - 0.25, ColorG + 0.2, ColorB - 0.25, 0.85
.SetSourceRGBA 1.25 - ColorR, 1.25 - ColorG, 1.25 - ColorB, 0.85
.MoveTo Token(FlagToken).POS.x, Token(FlagToken).POS.y
.LineTo FlagX, FlagY
.LineTo FlagX - X1, FlagY - Y1
.Stroke
.MoveTo FlagX, FlagY
.RelLineTo -X1, -Y1
.LineTo (Token(FlagToken).POS.x + FlagX) * 0.5 - X1, (Token(FlagToken).POS.y + FlagY) * 0.5 - Y1
.RelLineTo X1, Y1
.Fill
End With
'----------------------------
End Sub
Friend Sub DRAWToMAP(CC As cCairoContext, MapS As Double)
Dim I As Double
Dim LW As Double
Dim IStep As Double
LW = Diam * MapS + 0.7
' IStep = LW * 1.66
' CC.SetSourceRGB ColorR, ColorG, ColorB
' For I = 0 To Ntokens Step IStep
' CC.Arc (Token(I).POS.x - wMinX) * MapS, (Token(I).POS.y - wMinY) * MapS, LW
' CC.Fill
' Next
CC.SetLineWidth LW
IStep = LW * 2.5
If IsDying Then
CC.SetSourceRGB RndM, RndM, RndM
Else
CC.SetSourceRGB ColorR, ColorG, ColorB
End If
CC.MoveTo (Token(0).POS.x - wMinX) * MapS, (Token(0).POS.y - wMinY) * MapS
For I = IStep To Ntokens Step IStep
CC.LineTo (Token(I).POS.x - wMinX) * MapS, (Token(I).POS.y - wMinY) * MapS
Next
CC.LineTo (Token(Ntokens).POS.x - wMinX) * MapS, (Token(Ntokens).POS.y - wMinY) * MapS
CC.Stroke
If MyIDX = PLAYER Then
CC.SetLineWidth 1.25
CC.SetSourceColor vbYellow
CC.Arc (Token(0).POS.x - wMinX) * MapS, (Token(0).POS.y - wMinY) * MapS, LW * 0.5 + 1
CC.Stroke
End If
End Sub
'''''
'''''Friend Sub MOVE()
''''' Dim I As Long
''''' Dim J As Long
''''' Dim J2 As Long
'''''
'''''
''''' If IsDying Then Exit Sub
'''''
''''' ' tokIDX = (tokIDX + 1) Mod Ntokens
''''' DivRem (tokIDX + 1), Ntokens, tokIDX
'''''
'''''
''''' If MyIDX = PLAYER And (Not (AIcontrol)) Then 'Player
''''' ' DirChange = VectorMUL(MousePos, 0.01 * InvDiam) '.001
''''' DirChange = VectorMUL(VectorNormalize(MousePos), 3.25 * InvDiam)
'''''
''''' '' DirChange = VectorSUM(DirChange, AvoidEnemy(MyIDX, HEAD.POS, HEAD.Vel))
'''''
''''' Head.Vel = VectorNormalize(VectorSUM(Head.Vel, DirChange))
'''''
''''' Else 'Other Snakes (AI)
'''''
''''' oldANG = Atan2(Head.Vel.x, Head.Vel.y)
'''''
'''''
''''' ' 'If Cos((CNT + MyIDX * 50500) * 0.0075) < -0.98 Then ''' Ramble -.75 -0.0625
''''' If Cos((CNT + MyIDX * 50500) * 0.0075) < -1# * (NSnakes - MyIDX * 0.0625) * InvNSnakes Then ''' Ramble -.75 -0.0625
''''' '--2024
''''' ' If Cos((CNT + MyIDX * 50500) * 0.0075) > (NSnakes - MyIDX * 0.0625) * InvNSnakes Then ''' Ramble -.75 -0.0625
'''''
'''''
''''' ' Debug.Print MyIDX, Cos((CNT + MyIDX * 50500) * 0.0075), (NSnakes - MyIDX * 0.0625) * InvNSnakes
''''' ' Stop
'''''
''''' DirChange.x = RndM * 2 - 1
''''' DirChange.y = RndM * 2 - 1
''''' 'Commented to make AI sometimes not to Work
''''' 'DirChange = VectorSUM(DirChange, AvoidEnemy(MyIDX, HEAD.POS, HEAD.Vel))
''''' Else
''''' DirChange = PointToNearestFood(Head, MyIDX)
''''' DirChange = VectorSUM(DirChange, AvoidEnemy(MyIDX, Head.POS, Head.Vel))
''''' End If
'''''
'''''
'''''
''''' 'DirChange = VectorMUL(DirChange, 0.15)
''''' DirChange = VectorMUL(DirChange, 3.25 * InvDiam)
'''''
''''' Head.Vel = VectorNormalize(VectorSUM(Head.Vel, DirChange))
'''''
''''' If FASTspeed Then
''''' ' If rndm < 0.025 Then FASTspeed = False
''''' If RndM < 0.02 Then FASTspeed = False
''''' Else
''''' 'If rndm < 0.00625 Then FASTspeed = True
''''' If RndM < 0.005 Then FASTspeed = True
''''' End If
'''''
'''''
''''' End If
'''''
'''''
''''' ' HEAD.POS = VectorSUM(HEAD.POS, VectorMUL(HEAD.Vel, MySIZE))
'''''
'''''
''''' If FASTspeed And (fLength > 3) Then
''''' FASTspeedCOUNT = FASTspeedCOUNT + 1
''''' Head.POS = VectorSUM(Head.POS, VectorMUL(Head.Vel, SPEED * 1.72))
''''' LsPeed = SPEED * 1.72
''''' Else
''''' Head.POS = VectorSUM(Head.POS, VectorMUL(Head.Vel, SPEED))
''''' LsPeed = SPEED
''''' End If
'''''
'''''
'''''
''''' If FASTspeedCOUNT > 25 Then '20
''''' FASTspeedCOUNT = 0
''''' AddFoodParticle Token((tokIDX + 1) Mod Ntokens).POS, False
''''' SetSize = GetSize - FoodLengthValue
''''' If MyIDX = PLAYER Then PlayerScore = PlayerScore - 10
''''' End If
'''''
''''' ' If HEAD.Pos.X < wMinX Then HEAD.Pos.X = wMaxX
''''' ' If HEAD.Pos.Y < wMinY Then HEAD.Pos.Y = wMaxY
''''' ' If HEAD.Pos.X > wMaxX Then HEAD.Pos.X = wMinX
''''' ' If HEAD.Pos.Y > wMaxY Then HEAD.Pos.Y = wMinY
'''''
''''' If Head.POS.x < wMinX Then Head.POS.x = wMinX: Head.Vel.x = -Head.Vel.x
''''' If Head.POS.y < wMinY Then Head.POS.y = wMinY: Head.Vel.y = -Head.Vel.y
''''' If Head.POS.x > wMaxX Then Head.POS.x = wMaxX: Head.Vel.x = -Head.Vel.x
''''' If Head.POS.y > wMaxY Then Head.POS.y = wMaxY: Head.Vel.y = -Head.Vel.y
'''''
'''''
'''''
''''' Token(tokIDX).POS = Head.POS
'''''
'''''
''''' For I = tokIDX + Ntokens - 1 To tokIDX + 1 Step -1
'''''' J = I Mod Ntokens
''''' DivRem I, Ntokens, J
'''''
''''' J2 = J - 1
''''' If J2 < 0 Then J2 = J2 + Ntokens
''''' 'If J2 <> tokIDX Then Token(J).POS = VectorSUM(VectorMUL(Token(J).POS, 0.18), VectorMUL(Token(J2).POS, 0.82)) '2nd Video
''''' 'If J2 <> tokIDX Then Token(J).POS = VectorSUM(VectorMUL(Token(J).POS, 0.17), VectorMUL(Token(J2).POS, 0.83))
''''' If J2 <> tokIDX Then Token(J).POS = VectorSUM(VectorMUL(Token(J).POS, 0.165), VectorMUL(Token(J2).POS, 0.835)) '--2024
'''''
''''' Next
''''' If fLength \ 1 < Ntokens Then
''''' Ntokens = Ntokens - 1
''''' InvNtokens = 1 / Ntokens
''''' InvNtokens2 = 1 / (Ntokens - 2)
''''' End If
'''''
''''' ' fLength = fLength + 0.002 * rndm
''''' If fLength \ 1 > Ntokens Then
''''' Ntokens = Ntokens + 1
''''' If Ntokens > MaxNtok Then
''''' Ntokens = MaxNtok
''''' Else
''''' 'Riordina
''''' For I = Ntokens - 1 To tokIDX + 1 Step -1
''''' 'J = I Mod Ntokens
''''' DivRem I, Ntokens, J
'''''
''''' J2 = I - 1
'''''' DivRem I - 1, Ntokens, J2
'''''
''''' Token(J).POS = Token(J2).POS
''''' Next
''''' End If
''''' InvNtokens = 1 / Ntokens
''''' InvNtokens2 = 1 / (Ntokens - 2)
''''' End If
'''''
'''''
'''''
'''''
'''''
'''''End Sub
Friend Sub MOVE2()
Dim I As Long
Dim J As Long
Dim J2 As Long
If IsDying Then
'''' TOLTO DA DRAW
If (CNT - DyingTime > 40) Then '104 '' Blinking time
CreateFoodFromDeadSnake MyIDX
RandomizeMe
If MyIDX = PLAYER Then
LIFES = LIFES - 1
If LIFES = 0 Then
Print #1, Level & " Lifes " & LIFES & " Score " & PlayerScore
InitPool 6, True
InitFOOD 6 * FoodXSnake
MultipleSounds.PlaySound SoundINTRO
End If
End If
End If
Exit Sub
End If
' tokIDX = (tokIDX + 1) Mod Ntokens
' DivRem (tokIDX + 1), Ntokens, tokIDX
tokIDX = 0
If MyIDX = PLAYER And (Not (AIcontrol)) Then 'Player
' DirChange = VectorMUL(MousePos, 0.01 * InvDiam) '.001
DirChange = VectorMUL(VectorNormalize(MousePos), 3.25 * InvDiam)
'' DirChange = VectorSUM(DirChange, AvoidEnemy(MyIDX, HEAD.POS, HEAD.Vel))
Head.Vel = VectorNormalize(VectorSUM(Head.Vel, DirChange))
Else 'Other Snakes (AI)
oldANG = Atan2(Head.Vel.x, Head.Vel.y)
' 'If Cos((CNT + MyIDX * 50500) * 0.0075) < -0.98 Then ''' Ramble -.75 -0.0625
If Cos((CNT + MyIDX * 50500) * 0.0075) < -1# * (NSnakes - MyIDX * 0.0625) * InvNSnakes Then ''' Ramble -.75 -0.0625
'--2024
' If Cos((CNT + MyIDX * 50500) * 0.0075) > (NSnakes - MyIDX * 0.0625) * InvNSnakes Then ''' Ramble -.75 -0.0625
' Debug.Print MyIDX, Cos((CNT + MyIDX * 50500) * 0.0075), (NSnakes - MyIDX * 0.0625) * InvNSnakes
' Stop
DirChange.x = RndM * 2 - 1
DirChange.y = RndM * 2 - 1
'Commented to make AI sometimes not to Work
'DirChange = VectorSUM(DirChange, AvoidEnemy(MyIDX, HEAD.POS, HEAD.Vel))
Else
DirChange = PointToNearestFood(Head, MyIDX)
DirChange = VectorSUM(DirChange, AvoidEnemy(MyIDX, Head.POS, Head.Vel))
End If
'DirChange = VectorMUL(DirChange, 0.15)
DirChange = VectorMUL(DirChange, 3.25 * InvDiam)
Head.Vel = VectorNormalize(VectorSUM(Head.Vel, DirChange))
If FASTspeed Then
' If rndm < 0.025 Then FASTspeed = False
If RndM < 0.02 Then FASTspeed = False
Else
'If rndm < 0.00625 Then FASTspeed = True
If RndM < 0.005 Then FASTspeed = True
End If
End If
If FASTspeed And (fLength > 3) Then
FASTspeedCOUNT = FASTspeedCOUNT + 1
Head.POS = VectorSUM(Head.POS, VectorMUL(Head.Vel, SPEED * 1.72))
LsPeed = SPEED * 1.72
Else
Head.POS = VectorSUM(Head.POS, VectorMUL(Head.Vel, SPEED))
LsPeed = SPEED
End If
If FASTspeedCOUNT > 25 Then '20
FASTspeedCOUNT = 0
' AddFoodParticle Token((tokIDX + 1) Mod Ntokens).POS, False
AddFoodParticle Token(Ntokens).POS, False, MyIDX
SetSize = GetSize - FoodLengthValue
If MyIDX = PLAYER Then PlayerScore = PlayerScore - 10
End If
If Head.POS.x < wMinX Then Head.POS.x = wMinX: Head.Vel.x = -Head.Vel.x
If Head.POS.y < wMinY Then Head.POS.y = wMinY: Head.Vel.y = -Head.Vel.y
If Head.POS.x > wMaxX Then Head.POS.x = wMaxX: Head.Vel.x = -Head.Vel.x
If Head.POS.y > wMaxY Then Head.POS.y = wMaxY: Head.Vel.y = -Head.Vel.y
Token(tokIDX).POS = Head.POS
'********************************************
' ' For I = Ntokens To 1 Step -1
' ' J = I - 1&
' '' Token(I).POS = VectorSUM(VectorMUL(Token(I).POS, 0.835), VectorMUL(Token(J).POS, 0.165)) '--2024
' ' Token(I).POS.x = Token(I).POS.x * 0.835 + Token(J).POS.x * 0.165 '--2024
' ' Token(I).POS.y = Token(I).POS.y * 0.835 + Token(J).POS.y * 0.165 '--2024
' ' Next
' '********************************************
' For I = 1 To Ntokens
For I = Ntokens To 1 Step -1 'OK 2ND Video (primo 2024)
J = I - 1&
' Token(I).POS = VectorSUM(VectorMUL(Token(I).POS, 0.835), VectorMUL(Token(J).POS, 0.165)) '--2024
' Token(I).POS.x = Token(I).POS.x * 0.76 + Token(J).POS.x * 0.24 '--2024
' Token(I).POS.y = Token(I).POS.y * 0.76 + Token(J).POS.y * 0.24 '--2024
Token(I).POS.x = Token(I).POS.x * 0.75 + Token(J).POS.x * 0.25
Token(I).POS.y = Token(I).POS.y * 0.75 + Token(J).POS.y * 0.25
Next
'********************************************
If fLength \ 1 < Ntokens Then
Ntokens = Ntokens - 1
InvNtokens = 1 / Ntokens
' InvNtokens2 = 1 / (Ntokens - 2)
SQRNtokens = Ntokens ^ 0.5
End If
' fLength = fLength + 0.002 * rndm
If fLength \ 1 > Ntokens Then
Ntokens = Ntokens + 1
If Ntokens > MaxNtok Then
Ntokens = MaxNtok
Else
' 'Riordina
' For I = Ntokens - 1 To tokIDX + 1 Step -1
' 'J = I Mod Ntokens
' DivRem I, Ntokens, J
'
' J2 = I - 1
'' DivRem I - 1, Ntokens, J2
'
' Token(J).POS = Token(J2).POS
' Next
End If
Token(Ntokens) = Token(Ntokens - 1)
InvNtokens = 1 / Ntokens
' InvNtokens2 = 1 / (Ntokens - 2)
SQRNtokens = Ntokens ^ 0.5
End If
'-------- FLAG --------------
Dim MZZ As Double
Dim MMUL2 As Double
Dim dx#, dy#, DZ#
Const MULUP As Double = 0.006 '0.007