This repository was archived by the owner on Mar 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain_Game.bas
1817 lines (1695 loc) · 59.9 KB
/
Main_Game.bas
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
Attribute VB_Name = "Main_Game"
Option Explicit
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
' ------------------ Teclas -----------------------------
Global KArriba As Boolean, KAbajo As Boolean, KDerecha As Boolean, KIzquierda As Boolean
Global KEscape As Boolean, KIntro As Boolean
'--------------------------------------------------------
Global TempoPrivado As Single
Global FondoA As Integer
Global PotenciaActual As Integer
Global MusicaActual As Integer
Global MostrandoFrase As Boolean
Global TimerMF As Single
Global PasoFondo As Single
Global Framejefe As Single
Global EntrandoE As Boolean
Global MaxPasoFondo As Single
Global OsciladorArma As Boolean
Global TempDir As String
Global tiempoMusica As Single
Global JPausado As Boolean
Global Reentrar As Boolean
Global FrameABala As Integer
' Variables rápidas!!!
Global z As Integer, w As Integer, k As Integer, ww As Integer
'------------- Variables Estaticas declaradas como globales para poder borrarlas ----
Global S_recorte As Single
Global S1_fraseanterior As String
Global S1_wr As Single, S1_cursor As Integer
Global S2_fraseanterior As String
Global S2_wr As Single, S2_cursor As Integer
'------------------------------------------------------------------------------------
Global DibujandoFrase As Boolean
Public Type tObjeto
x As Integer
y As Integer
tag As String
tagint2 As Single
tagint As Single
End Type
Public Type tNivel
key As String
frase As String
frase2 As String
vida As Boolean
energia As Boolean
upgrade As Boolean
especial2 As Boolean
TiempoFrase As Integer
especial As Boolean
TiempoA As Boolean
Jefe As Boolean
frasesecundaria As String
End Type
Public Type tUFO
x As Integer
y As Integer
vida As Integer
vidamax As Integer
tipo As Integer
End Type
Public Type tDisparoEnemigo
x As Integer
y As Integer
End Type
Public Type tMet
x As Integer
y As Integer
a As Integer
frame As Single
vida As Integer
End Type
Public Type tNave
normal As DirectDrawSurface7
derecha As DirectDrawSurface7
izquierda As DirectDrawSurface7
x As Integer
y As Integer
End Type
Public Type tExp
x As Integer
y As Integer
frame As Single
End Type
Global unaMejora As tObjeto
Global Jefe As tUFO
Global Fondos(1) As DirectDrawSurface7
Global MatrizJefes(1 To 1, 1 To 3) As DirectDrawSurface7
Global ExpActivas() As tExp
Global ExpActivasP() As tExp
Global unaVida As tObjeto
Global unaEnergia As tObjeto
Global Letras As DirectDrawSurface7
Global AnimVidas(1 To 5) As DirectDrawSurface7
Global AnimMejoras(1 To 12) As DirectDrawSurface7
Global AnimEnergias(1 To 2) As DirectDrawSurface7
Global AnimExplosion(1 To 11) As DirectDrawSurface7
Global Meteoritos(1 To 8) As DirectDrawSurface7
Global Menus(1 To 4, 1 To 2) As DirectDrawSurface7
Global Mini As DirectDrawSurface7
Global Autor As DirectDrawSurface7
Global Web As DirectDrawSurface7
Global DisparosE() As tDisparoEnemigo
Global UFOs() As tUFO
Global Niveles() As tNivel
Global NivelesB() As tNivel
Global Disparar As Boolean
Global Fondo As DirectDrawSurface7
Global Nave As tNave
Global FPS As Long
Global TimePerFrame As Single
Global EXE As String
Global SalidaCritica As Boolean
Global METs() As tMet
Global Inmunidad As Integer
Global VaivenInmunidad As Single
Global VIAumentar As Boolean
Global TiempoDDM As Integer
Global DisparoE As DirectDrawSurface7
Global Balas(1 To 30) As cBala
Global SurBalas() As DirectDrawSurface7
Global Enemigos(1 To 7, 1 To 7) As DirectDrawSurface7
Global TituloUI As DirectDrawSurface7
Global DxPowered As DirectDrawSurface7
Global CreditsTitle(1 To 2) As DirectDrawSurface7
Global Davidgf_logo As DirectDrawSurface7
Global Linkinpark_logo As DirectDrawSurface7
Global Visita_web As DirectDrawSurface7
Global Musica(1 To 4) As DirectMusicSegment
Global Disparos(1 To 5) As DirectSoundBuffer
Global Muertes(1 To 5) As DirectSoundBuffer
Global Explosion(1 To 5) As DirectSoundBuffer
Global VidasCogidas As DirectSoundBuffer
Global EnergiaCogida As DirectSoundBuffer
Global DisparosEnemigos(1 To 5) As DirectSoundBuffer
Global JefeExp As DirectSoundBuffer
Global Vaiven As Byte
Global DisparoID As Integer
Global MuerteVaiven As Integer
Global ExpVaiven As Integer
Global VaivenEnemigo As Integer
Global VidaNave As Integer
Global Vidas As Integer
Global NivelActual As Integer
Global VaivenDE As Integer
Global Seleccion As Integer
Public Const PasosBarra = 43
' ------------------ Datos Constantes ----------------------
Public Const AnchoVida = 102
Public Const AltoVida = 15
Public Const AnMini = 10
Public Const AlMini = 15
Public Const AnchoDisp = 3
Public Const AltoDisp = 8
Public Const DespNave = 10
Public Const PAlto = 600
Public Const PAncho = 800
Public Const AnchoBala = 5
Public Const AltoBala = 15
Public Const AnchoNave = 40
Public Const AltoNave = 61
Public Const AnchoEnemigo = 65
Public Const AltoEnemigo = 47
Public Const AnchoUFO = 65
Public Const AltoUFO = 47
Public Const margenSeguridad = 200
Public Const AnchoJefe = 211
Public Const AltoJefe = 145
'-----------------------------------------------------------
Sub Main()
If App.PrevInstance = True Then End
'----------------------------------------------
EXE = App.Path
If Right(EXE, 1) <> "\" Then EXE = EXE & "\"
TempDir = GetTempDir()
Cargador.Show
Cargador.info = "Cargando ficheros ..."
Cargador.Refresh: DoEvents
DescompactarFichero EXE & "game.dat", TempDir
Cargador.Refresh: DoEvents
'------------------ Niveles ---------
Cargador.info = "Cargando escenarios ...": DoEvents
CargarNiveles
NivelesB = Niveles
Cargador.IncrementarBarra
'---------------- Iniciar DX -----------
Cargador.info = "Iniciando DirectX 7 ...": DoEvents
InitDx
Cargador.IncrementarBarra
'---------------- Iniciar DD -----------
Cargador.info = "Iniciando DirectDraw ...": DoEvents
InitDD
Cargador.IncrementarBarra
'--------------- Iniciar DS -------------
Cargador.info = "Iniciando DirectSound ...": DoEvents
InitDS
Cargador.IncrementarBarra
'-------------------- Cargar Sonido -------
Cargador.info = "Cargando musica ...": DoEvents
LoadMusic
Cargador.info = "Cargando sonido ...": DoEvents
LoadSnd
Cargador.info = "Iniciando ...": DoEvents
'---------------Iniciar DD 2 ---------------
On Local Error Resume Next
Err.Number = 0
SetDisplayMode PAncho, PAlto, 32
If Err.Number <> 0 Then
Err.Number = 0
SetDisplayMode PAncho, PAlto, 16
If Err.Number <> 0 Then
BorrarTemporales
Unload Cargador
MsgBox "No se puede cargar el juego debido a que su pantalla" & vbCrLf & _
"no soporta la resolución de 800 por 600 píxeles", vbCritical, "UFO Invasion"
End
End If
End If
Call CreatePrimaryAndBackBuffer
'---------------- Cargar Imágenes --------
LoadSupers
'---------------Formulario principal------
Unload Cargador
Load Juego
'-------------------------------------------
'CerrarTodosSonidosWin
BorrarTemporales
OtraVez:
Call LimpiarVEstaticas
Call InitGlobals
Call MenuJuego
Call Jugar
If Reentrar = True Then GoTo OtraVez
BorrarTemporales
ShowCursor 1: DoEvents: ShowCursor 1
End
End Sub
Public Sub Jugar()
Dim ready As Boolean
GetAsyncKeyState vbKeyEscape
GetAsyncKeyState vbKeySpace
GetAsyncKeyState vbKeyReturn
Dim unaBala As cBala, z As Integer, Tempo As Single, w As Integer, k As Integer
Dim unaBala2 As cBala
Dim Vx As Integer, Vy As Integer, Iguala As Integer
Dim Vx2 As Integer, Vy2 As Integer
FPS = 50 'y fps, por tanto cada frame dura ...
TimePerFrame = 1000 / FPS
PotenciaActual = 1: MusicaActual = 0
NivelActual = 0
VidaNave = 4: Vidas = 3
MuerteVaiven = 1: OsciladorArma = True: FrameABala = 0
BorrarTodo
TiempoDDM = -1 'valor k indica k la nave esta mostrandose en la pantalla
'-------------------------------------------------------
Dim DestRect As RECT
Dim SrcRect As RECT
Dim subTempo As Single, subTimerMF As Single, tempoDif As Single, CLMusica As Long
Nave.x = (PAncho - AnchoNave) / 2
Nave.y = PAlto - AltoNave - 20
DoEvents: ShowCursor 0: DoEvents
Do While 1
'DoEvents
Tempo = GetTickCount()
If ready = True Then
Call ChequearInmunidad
Call ControlFondo
If PasoFondo < 1 Or FondoA < 0 Then PasoFondo = 1
' ----------------- Cargar nivel si es necesario ---------
Call JCargarNivel
' ------------------------- Mostrar frases si existe --------------
If NivelActual > 0 Then
If Niveles(NivelActual).frase <> "" Then
MostrandoFrase = True
TimerMF = GetTickCount()
Niveles(NivelActual).frase = ""
End If
End If
Call Objetos_Nave
If MostrandoFrase = False Then
' ----------- Procesar movimientos jefe -----------
If Niveles(NivelActual).Jefe = True Then Call Jefe_Nave
If UBound(METs) <> 0 Then
Call Nave_Meteoro 'Choque Nave-meteorito
Call Mover_Met 'Procesar meteoritos
End If
' ----------- Procesar UFOs parar que se muevan-------
If UBound(UFOs) <> 0 Then Call Procesa_UFOS
End If
'----------------- Procesar Coords. Nave ----------
If TiempoDDM <= 0 Then
Call Mover_Nave
If MostrandoFrase = False Then Call Nave_UFO
End If
' --------------- Disparos enemigos -----------------
If UBound(DisparosE) <> 0 Then Call DispEnem_Nave_y_Mover
If UBound(UFOs) <> 0 And MostrandoFrase = False Then Call Procesar_DispEnem
'----------------- Procesar coords. bala -------------------
If MostrandoFrase = False Then
If UBound(UFOs) <> 0 Then Call Bala_UFO
If UBound(UFOs) = 0 Then Call Bala_Met
End If
If FrameABala > 0 Then FrameABala = FrameABala - 1
If GetAsyncKeyState(vbKeySpace) <> 0 And FrameABala = 0 And TiempoDDM = -1 And _
PasoFondo = 1 Then
Call NuevoDisparo(unaBala, unaBala2)
End If
If NivelActual > 0 And MostrandoFrase = False Then
If Niveles(NivelActual).Jefe Then
Call Bala_Jefe
End If
End If
' ---------------------------- Musica --------------------
If MusicaActual = 0 Then
MusicaActual = Int(Rnd * 4) + 1
'ReproducirSonidoWin "ufo_invasion_10_music_" & Trim(Str(MusicaActual))
ReproducirMidi Musica(MusicaActual)
tiempoMusica = GetTickCount() + 5000
Else
'If Parado("ufo_invasion_10_music_" & Trim(Str(MusicaActual))) = True Then
If ReproduciendoMidi(Musica(MusicaActual)) = False And _
GetTickCount() > tiempoMusica Then
MusicaActual = MusicaActual + 1
If MusicaActual > 4 Then MusicaActual = 1
'ReproducirSonidoWin "ufo_invasion_10_music_" & Trim(Str(MusicaActual))
ReproducirMidi Musica(MusicaActual)
tiempoMusica = GetTickCount() + 5000
End If
End If
' ---------------- Comprovar frase (desaparecer) ---------------
If MostrandoFrase = True Then
If (TimerMF + Niveles(NivelActual).TiempoFrase) < GetTickCount() Then
MostrandoFrase = False
End If
If Niveles(NivelActual).especial2 = True And Niveles(NivelActual).TiempoA = False Then
Niveles(NivelActual).TiempoA = True
TimerMF = TimerMF + 2000
End If
If DibujandoFrase = True Then MostrandoFrase = True
If DibujandoFrase = True And (Niveles(NivelActual).especial = True Or _
Niveles(NivelActual).especial2 = True) Then MostrandoFrase = True
If (Niveles(NivelActual).especial = False And _
Niveles(NivelActual).especial2 = False) And DibujandoFrase = True Then TimerMF = GetTickCount()
End If
End If 'se cierra el if del ready PULSE INTRO
'-------------------- DirecDraw Dibuja ----------------------
SetRect DestRect, 0, 0, PAncho, PAlto
SetRect SrcRect, 0, 0, 1, 1
BackBuffer.Blt DestRect, Fondo, SrcRect, DDBLT_WAIT
If ready = True Then DibujaFondo Fondos(1)
If ready = True Then 'segunda condicion del ready
DibujarExplosiones
If unaVida.tag = "1" Then
If unaVida.tagint >= 5 - (30 / FPS) Then
unaVida.tagint2 = 1
ElseIf unaVida.tagint <= 1 Then
unaVida.tagint2 = 0
End If
If unaVida.tagint2 = 0 Then
unaVida.tagint = unaVida.tagint + 1 * (30 / FPS)
Else
unaVida.tagint = unaVida.tagint - 1 * (30 / FPS)
End If
DibujaAdv unaVida.x, unaVida.y, 60, 60, AnimVidas(CLng(unaVida.tagint + 0.5))
End If
If unaEnergia.tag = "1" Then
unaEnergia.tagint = unaEnergia.tagint + 1
If unaEnergia.tagint >= (10 * (FPS / 30)) Then unaEnergia.tagint = 1
If unaEnergia.tagint <= (5 * (FPS / 30)) Then
unaEnergia.tagint2 = 1
Else
unaEnergia.tagint2 = 2
End If
DibujaAdv unaEnergia.x, unaEnergia.y, 45, 45, AnimEnergias(unaEnergia.tagint2)
End If
If unaMejora.tag = "1" Then
unaMejora.tagint = unaMejora.tagint + 1 * (30 / FPS)
If unaMejora.tagint > 12 Then unaMejora.tagint = 1 * (30 / FPS)
DibujaAdv unaMejora.x, unaMejora.y, 33, 35, AnimMejoras(CLng(unaMejora.tagint + 0.5))
End If
For z = 1 To UBound(DisparosE)
Dibuja DisparosE(z).x, DisparosE(z).y, AnchoDisp, AltoDisp, DisparoE
Next
If TiempoDDM = -1 Then
If KDerecha = True Then
Dibuja Nave.x, Nave.y, AnchoNave, AltoNave, Nave.derecha
ElseIf KIzquierda = True Then
Dibuja Nave.x, Nave.y, AnchoNave, AltoNave, Nave.izquierda
Else
Dibuja Nave.x, Nave.y, AnchoNave, AltoNave, Nave.normal
End If
If Inmunidad <> 0 Then
BackBuffer.setDrawWidth 1
BackBuffer.SetForeColor RGB(Int(Rnd * 50), Int(Rnd * 50), 255)
If VaivenInmunidad <= 0 Then
VaivenInmunidad = 10 * (FPS / 30)
Else
If VIAumentar = True Then
VaivenInmunidad = VaivenInmunidad + 1
If VaivenInmunidad > 10 Then VIAumentar = False
Else
VaivenInmunidad = VaivenInmunidad - 1
If VaivenInmunidad < 5 Then VIAumentar = True
End If
End If
BackBuffer.SetFillStyle 1
BackBuffer.DrawCircle (Nave.x + AnchoNave / 2), (Nave.y + AltoNave / 2), AltoNave / 2 + (VaivenInmunidad / (FPS / 30)) - 1
BackBuffer.DrawCircle (Nave.x + AnchoNave / 2), (Nave.y + AltoNave / 2), AltoNave / 2 + VaivenInmunidad / (FPS / 30)
BackBuffer.SetForeColor 16744508
BackBuffer.DrawCircle (Nave.x + AnchoNave / 2), (Nave.y + AltoNave / 2), AltoNave / 2 + VaivenInmunidad / (FPS / 30) + 2
End If
End If
If MostrandoFrase = False And NivelActual > 0 Then
If Niveles(NivelActual).Jefe Then
Framejefe = Framejefe + 0.1 * (30 / FPS)
If Framejefe >= 5 Then Framejefe = 0.25 * (30 / FPS)
If CLng(Framejefe + 0.5) > 3 Then
DibujaJefe Jefe.x, Jefe.y, AnchoJefe, AltoJefe, MatrizJefes(Val(Niveles(NivelActual).key), CLng(Framejefe + 0.5) - 2)
Else
DibujaJefe Jefe.x, Jefe.y, AnchoJefe, AltoJefe, MatrizJefes(Val(Niveles(NivelActual).key), CLng(Framejefe + 0.5))
End If
End If
For z = 1 To UBound(UFOs)
DibujaAdv UFOs(z).x, UFOs(z).y, AnchoUFO, AltoUFO, Enemigos(UFOs(z).tipo, (UFOs(z).tipo - UFOs(z).vida + 1))
Next
For z = 1 To UBound(METs)
DibujaAdv METs(z).x, METs(z).y, 50, 50, Meteoritos(Int(METs(z).frame))
Next
End If
For z = 1 To 30
If Balas(z) Is Nothing Then
Else
Balas(z).y = Balas(z).y - (15 * (30 / FPS)) 'Aprovechamos para eliminar las balas k salen
DibujaAdv Balas(z).x, Balas(z).y, AnchoBala, AltoBala, SurBalas(Balas(z).potencia)
If Balas(z).y < -30 Then
Set Balas(z) = Nothing
End If
End If
Next
If NivelActual <> 0 Then
If Niveles(NivelActual).Jefe Then
BackBuffer.SetForeColor vbWhite
BackBuffer.SetFillStyle 1
BackBuffer.DrawRoundedBox PAncho - 25 - 5 - 1, 5 - 1, PAncho - 5 + 1 + 1, 5 + 300 + 2, 8, 8
BackBuffer.SetFillColor RGB(255, 128, 0) 'naranja
w = 3 + ((300) / Jefe.vidamax) * Jefe.vida
BackBuffer.SetFillStyle 0
BackBuffer.SetForeColor RGB(255, 128, 0)
If Jefe.vida > 0 Then BackBuffer.DrawRoundedBox PAncho - 25 - 5 + 3, 5 + 3, PAncho - 5 - 2, w, 8, 8
End If
End If
DibujarExplosionesP
'Dibuja 5, 5, AnchoVida, AltoVida, BarraVida(VidaNave)
BackBuffer.SetForeColor RGB(0, 75, 0)
BackBuffer.SetFillStyle 1
BackBuffer.DrawRoundedBox 6, 6, 104, 19, 3, 3
BackBuffer.SetFillColor RGB(0, 150, 0) 'verde
BackBuffer.SetFillStyle 0
BackBuffer.SetForeColor RGB(0, 150, 0)
BackBuffer.DrawRoundedBox 8, 8, (25.4 * VidaNave), 17, 0, 0
For z = 1 To Vidas
Dibuja 117 + (z - 1) * (5 + AnMini), 5, AnMini, AlMini, Mini
Next
If MostrandoFrase = True And NivelActual <> 0 Then
If Niveles(NivelActual).frase2 <> "" Then
DibujarFrase 50, 600 - 50, Niveles(NivelActual).frase2
Else
DibujarFraseRC 50, 600 - 50, Niveles(NivelActual).frasesecundaria
End If
End If
End If 'cierre del segundo ready
' ---------- Inicio -----------------
If ready = False Then
DibujarFrase -1, -1, "Pulse intro"
End If
'----------------------------------
Mostrar
DoEvents
If (TimePerFrame - (GetTickCount() - Tempo)) > 0 Then
If (TimePerFrame - (GetTickCount() - Tempo)) <= TimePerFrame Then
'Esperar (TimePerFrame - (GetTickCount() - Tempo))
Sleep (TimePerFrame - (GetTickCount() - Tempo)) 'Se "duerme" el tiempo sobrante para regular la velocidad
End If
End If
'Tiempo empleado para el frame=GetTickCount() - Tempo)
'Tiempo que ha de durar cada frametimeperframe
'por tanto el resto será el tiempo "muerto"
If KEscape = True Or SalidaCritica = True Then GoTo SALIDA
If KIntro = True Then ready = True
If JPausado Then
subTimerMF = TimerMF - GetTickCount()
subTempo = Tempo - GetTickCount()
PararMidi Musica(MusicaActual)
CLMusica = DMusicPerformance.GetMusicTime()
End If
Do While JPausado
DoEvents
Sleep TimePerFrame
If GetAsyncKeyState(vbKeyEscape) Then GoTo SALIDA
Loop
If subTempo <> 0 Then
tiempoMusica = GetTickCount() + 5000
TimerMF = subTimerMF + GetTickCount()
Tempo = subTempo + GetTickCount()
subTempo = 0
ReproducirMidi Musica(MusicaActual), CLMusica
End If
Loop
SALIDA:
'PararSonidoWin "ufo_invasion_10_music_" & Trim(Str(MusicaActual))
On Local Error Resume Next
PararMidi Musica(MusicaActual)
'RestoreDisplayMode
'DestruirDS
'Set View = Nothing
'Set BackBuffer = Nothing
'DDraw.SetCooperativeLevel Juego.hWnd, DDSCL_NORMAL
'Set DDraw = Nothing: Set Dx = Nothing
'Unload Juego
'ShowCursor 1
DoEvents
Reentrar = True
If SalidaCritica = True Then End
End Sub
Public Sub LoadSupers()
Dim Color As DDCOLORKEY, jj As Integer
Color.high = vbBlack
Color.low = vbBlack
ReDim SurBalas(1 To 7)
LoadS TempDir & "NR.bmp", Nave.normal, AnchoNave, AltoNave
LoadS TempDir & "NI.bmp", Nave.izquierda, AnchoNave, AltoNave
LoadS TempDir & "ND.bmp", Nave.derecha, AnchoNave, AltoNave
LoadS TempDir & "black.bmp", Fondo, PAncho, PAlto
LoadS TempDir & "disp.bmp", DisparoE, AnchoDisp, AltoDisp
LoadS TempDir & "mini.bmp", Mini, AnMini, AlMini
Mini.SetColorKey DDCKEY_SRCBLT, Color
DisparoE.SetColorKey DDCKEY_SRCBLT, Color
Nave.normal.SetColorKey DDCKEY_SRCBLT, Color
Nave.izquierda.SetColorKey DDCKEY_SRCBLT, Color
Nave.derecha.SetColorKey DDCKEY_SRCBLT, Color
Dim j As Integer, j2 As Integer
For j = 1 To 7
LoadS TempDir & "bala" & Trim(Str(j)) & ".bmp", SurBalas(j), AnchoBala, AltoBala
SurBalas(j).SetColorKey DDCKEY_SRCBLT, Color
Next
On Local Error Resume Next
For j = 1 To 7
For jj = 1 To 7
If Existe(TempDir & "enemigo" & Trim(Str(j)) & "-" & Trim(Str(jj)) & ".bmp") Then
LoadS TempDir & "enemigo" & Trim(Str(j)) & "-" & Trim(Str(jj)) & ".bmp", Enemigos(j, jj), AnchoEnemigo, AltoEnemigo
Enemigos(j, jj).SetColorKey DDCKEY_SRCBLT, Color
End If
Next
Next
Err.Clear: Err.Number = 0
On Local Error GoTo 0
For j = 1 To 11
LoadS TempDir & "e" & Trim(Str(j)) & ".bmp", AnimExplosion(j), 64, 64
AnimExplosion(j).SetColorKey DDCKEY_SRCBLT, Color
Next
LoadS TempDir & "fondo1.bmp", Fondos(1), 800, 3200
Fondos(1).SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "davidgf_logo.bmp", Davidgf_logo, 309, 71
Davidgf_logo.SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "linkin.bmp", Linkinpark_logo, 312, 73
Linkinpark_logo.SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "credits1.bmp", CreditsTitle(1), 367, 36
CreditsTitle(1).SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "credits2.bmp", CreditsTitle(2), 96, 31
CreditsTitle(2).SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "dx7logo.bmp", DxPowered, 191, 104
DxPowered.SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "visita.bmp", Visita_web, 279, 37
Visita_web.SetColorKey DDCKEY_SRCBLT, Color
For j = 1 To 8
LoadS TempDir & "met" & Trim(Str(j)) & ".bmp", Meteoritos(j), 50, 50
Meteoritos(j).SetColorKey DDCKEY_SRCBLT, Color
Next
LoadS TempDir & "letras.bmp", Letras, 600, 20
Letras.SetColorKey DDCKEY_SRCBLT, Color
For j = 1 To 5
LoadS TempDir & "vida" & Trim(Str(j)) & ".bmp", AnimVidas(j), 60, 60
AnimVidas(j).SetColorKey DDCKEY_SRCBLT, Color
Next
For j = 1 To 12
LoadS TempDir & "u" & Trim(Str(j)) & ".bmp", AnimMejoras(j), 33, 35
AnimMejoras(j).SetColorKey DDCKEY_SRCBLT, Color
Next
For j = 1 To 2
LoadS TempDir & "energia" & Trim(Str(j)) & ".bmp", AnimEnergias(j), 45, 45
AnimEnergias(j).SetColorKey DDCKEY_SRCBLT, Color
Next
For j = 1 To 1
For j2 = 1 To 3
LoadS TempDir & "jefe" & Trim(Str(j)) & Trim(Str(j2)) & ".bmp", MatrizJefes(j, j2), AnchoJefe, AltoJefe
MatrizJefes(j, j2).SetColorKey DDCKEY_SRCBLT, Color
Next
Next
LoadS TempDir & "titulo.bmp", TituloUI, 402, 86
TituloUI.SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "davidgf.bmp", Autor, 206, 20
Autor.SetColorKey DDCKEY_SRCBLT, Color
LoadS TempDir & "web.bmp", Web, 156, 20
Web.SetColorKey DDCKEY_SRCBLT, Color
For j = 1 To 4
For jj = 1 To 2
LoadS TempDir & "menu" & Trim(Str(j)) & "-" & Trim(Str(jj)) & ".bmp", Menus(j, jj), 251, 61
Menus(j, jj).SetColorKey DDCKEY_SRCBLT, Color
Next
Next
End Sub
Public Sub LoadSnd()
Dim d As Integer
For d = 1 To 5
Set Disparos(d) = CargarSonido(TempDir & "snd1.wav")
Cargador.IncrementarBarra
Next
For d = 1 To 5
Set Muertes(d) = CargarSonido(TempDir & "snd2.wav")
Cargador.IncrementarBarra
Next
For d = 1 To 5
Set Explosion(d) = CargarSonido(TempDir & "snd3.wav")
Cargador.IncrementarBarra
Next
For d = 1 To 5
Set DisparosEnemigos(d) = CargarSonido(TempDir & "snd4.wav")
Cargador.IncrementarBarra
Next
Set VidasCogidas = CargarSonido(TempDir & "snd5.wav")
Set EnergiaCogida = CargarSonido(TempDir & "snd6.wav")
Set JefeExp = CargarSonido(TempDir & "snd7.wav")
End Sub
Public Sub LoadMusic()
InitDM
Dim d As Integer, j As Integer
For d = 1 To 4
Set Musica(d) = CargarMidi(TempDir & Trim(Str(d)) & ".mid")
For j = 1 To 5
Cargador.IncrementarBarra
Next
Next
End Sub
Public Sub DestruirDS()
Dim d As Integer
For d = 1 To 5
Set Disparos(d) = Nothing
Next
For d = 1 To 5
Set Muertes(d) = Nothing
Next
For d = 1 To 5
Set Explosion(d) = Nothing
Next
Set DSound = Nothing
PararMidi Musica(MusicaActual)
DMusicPerformance.CloseDown
Set DMusicLoader = Nothing
Set DMusicPerformance = Nothing
Set estado = Nothing
End Sub
Public Sub CargarNiveles()
Dim libre As Integer, lin As String, str1 As String, str2 As String, int1 As Integer
Dim f As Integer
libre = FreeFile
Open EXE & "Data.dat" For Input As #libre
Do While Not EOF(libre)
f = f + 1
Line Input #libre, lin
ReDim Preserve Niveles(1 To f)
Niveles(f).key = lin
Line Input #libre, lin
lin = UCase(lin)
If InStr(1, lin, "U") <> 0 Then Niveles(f).upgrade = True
If InStr(1, lin, "E") <> 0 Then Niveles(f).energia = True
If InStr(1, lin, "V") <> 0 Then Niveles(f).vida = True
If InStr(1, lin, "S") <> 0 Then Niveles(f).especial = True
If InStr(1, lin, "J") <> 0 Then Niveles(f).Jefe = True
If InStr(1, lin, "Z") <> 0 Then Niveles(f).especial2 = True
Line Input #libre, lin
If lin <> "" Then
int1 = InStr(1, lin, ":")
str1 = Left(lin, int1 - 1)
str2 = Mid(lin, int1 + 1)
Niveles(f).frase = str1
Niveles(f).frase2 = str1
Niveles(f).TiempoFrase = Val(str2)
int1 = InStr(1, lin, "\")
If int1 <> 0 Then
str2 = Mid(lin, int1 + 1)
Niveles(f).frasesecundaria = str2
End If
End If
Loop
Close #libre
End Sub
Public Sub DibujarExplosiones()
Dim g As Integer, h As Integer
Inicio:
For g = 1 To UBound(ExpActivas)
If ExpActivas(g).frame >= (11 - (30 / FPS)) Then
If UBound(ExpActivas) = 1 Then
ReDim ExpActivas(0)
Else
If g <> UBound(ExpActivas) Then
For h = g To UBound(ExpActivas) - 1
ExpActivas(h).x = ExpActivas(h + 1).x
ExpActivas(h).y = ExpActivas(h + 1).y
ExpActivas(h).frame = ExpActivas(h + 1).frame
Next
End If
ReDim Preserve ExpActivas(UBound(ExpActivas) - 1)
GoTo Inicio
End If
End If
Next
For g = 1 To UBound(ExpActivas)
ExpActivas(g).frame = ExpActivas(g).frame + (1 * (30 / FPS))
If ExpActivas(g).frame > 0 Then DibujaAdv ExpActivas(g).x, ExpActivas(g).y, 64, 64, AnimExplosion(CLng(ExpActivas(g).frame + 0.5))
Next
End Sub
Public Sub DibujarExplosionesP()
Dim g As Integer, h As Integer
Inicio:
For g = 1 To UBound(ExpActivasP)
If ExpActivasP(g).frame >= (10 - (30 / FPS)) Then
If UBound(ExpActivasP) = 1 Then
ReDim ExpActivasP(0)
Else
If g <> UBound(ExpActivasP) Then
For h = g To UBound(ExpActivasP) - 1
ExpActivasP(h).x = ExpActivasP(h + 1).x
ExpActivasP(h).y = ExpActivasP(h + 1).y
ExpActivasP(h).frame = ExpActivasP(h + 1).frame
Next
End If
ReDim Preserve ExpActivasP(UBound(ExpActivasP) - 1)
GoTo Inicio
End If
End If
Next
For g = 1 To UBound(ExpActivasP)
ExpActivasP(g).frame = ExpActivasP(g).frame + (2 * (30 / FPS))
If ExpActivasP(g).frame > 0 Then Dibuja ExpActivasP(g).x, ExpActivasP(g).y, 24, 24, AnimExplosion(CLng(ExpActivasP(g).frame + 0.5))
Next
End Sub
Public Sub NuevaExplosion(ByVal x As Integer, ByVal y As Integer, Optional ByVal FrameInicial As Integer = 0)
ReDim Preserve ExpActivas(UBound(ExpActivas) + 1)
ExpActivas(UBound(ExpActivas)).x = x
ExpActivas(UBound(ExpActivas)).y = y
ExpActivas(UBound(ExpActivas)).frame = FrameInicial
End Sub
Public Sub NuevaExplosionP(ByVal x As Integer, ByVal y As Integer, Optional ByVal FrameInicial As Integer = 0)
ReDim Preserve ExpActivasP(UBound(ExpActivasP) + 1)
ExpActivasP(UBound(ExpActivasP)).x = x
ExpActivasP(UBound(ExpActivasP)).y = y
ExpActivasP(UBound(ExpActivasP)).frame = FrameInicial
End Sub
Public Sub DibujaFondo(obj As DirectDrawSurface7)
Dim recorteR As Integer
If CLng(S_recorte - PasoFondo * (FPS / 30)) <= 0 Then
S_recorte = 2600
Else
S_recorte = S_recorte - PasoFondo * (30 / FPS)
End If
recorteR = Int(S_recorte)
Dim SrcRect As RECT
SetRect SrcRect, 0, recorteR, PAncho, PAlto
BackBuffer.BltFast 0, 0, obj, SrcRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
End Sub
Public Sub BorrarTodo()
Dim z As Integer
ReDim UFOs(0): ReDim DisparosE(0): ReDim ExpActivas(0): ReDim METs(0): ReDim ExpActivasP(0)
Inmunidad = 0: TiempoDDM = 0: VaivenEnemigo = 0
KArriba = False: KAbajo = False: KDerecha = False: KIzquierda = False
For z = 1 To 30
Set Balas(z) = Nothing
Next
End Sub
Public Sub DibujarCaracter(x As Integer, y As Integer, ByVal caracter As String)
'On Local Error Resume Next
caracter = UCase(caracter)
Dim SrcRect As RECT
Dim z As Integer
If Asc(caracter) = 33 Then
z = 27
ElseIf Asc(caracter) = 161 Then
z = 28
ElseIf Asc(caracter) = 32 Then
z = 29
ElseIf Asc(caracter) = 45 Then
z = 30
ElseIf Asc(caracter) >= 65 And Asc(caracter) <= 90 Then
z = Asc(caracter) - 64
Else
z = 27
End If
SetRect SrcRect, (z - 1) * 20, 0, 20, 20
BackBuffer.BltFast x, y, Letras, SrcRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
End Sub
Public Sub DibujarFrase(x As Integer, y As Integer, ByVal frase As String)
'On Local Error Resume Next
Dim hl As Integer
If S1_fraseanterior = "" Then S1_fraseanterior = frase: S1_wr = 0
If S1_fraseanterior <> frase Then S1_fraseanterior = frase: S1_wr = 0
S1_wr = S1_wr + 0.2 * (50 / FPS)
S1_cursor = S1_cursor + 1
If S1_cursor >= (10 * (FPS / 50)) Then
S1_cursor = -10 * (FPS / 50)
End If
Dim h As Integer, x2 As Integer, y2 As Integer
If x < 0 Then
x2 = ((PAncho - (Len(frase) * 20)) / 2)
Else
x2 = x
End If
If y < 0 Then
y2 = (PAlto - 20) / 2
Else
y2 = y
End If
If S1_wr > Len(frase) Then
S1_wr = Len(frase)
DibujandoFrase = False
Else
DibujandoFrase = True
End If
For h = 0 To (S1_wr - 1)
hl = Int(h) + 1
DibujarCaracter x2 + ((hl - 1) * 20), y2, Mid(frase, hl, 1)
Next
If S1_cursor < 0 Then
h = S1_wr
hl = Int(h) + 1
DibujarCaracter x2 + ((hl - 1) * 20), y2, "-"
End If
End Sub
Public Function ComSepUFOs() As Boolean
Dim d As Integer
For d = 1 To UBound(UFOs) - 1
If (UFOs(d + 1).x - UFOs(d).x) > (65 * 3 / 2) Then
ComSepUFOs = True
Exit Function
End If
Next
End Function
Public Function ComSep2UFOs(ByVal ufo1 As Integer, ufo2 As Integer) As Boolean
If (UFOs(ufo2).x - UFOs(ufo1).x) > (65 * 3 / 2) Then
ComSep2UFOs = True
End If
End Function
Public Function ComSep2UFOsLargo(ByVal ufo1 As Integer, ufo2 As Integer) As Boolean
If (UFOs(ufo2).x - UFOs(ufo1).x) > (65 * 2) Then
ComSep2UFOsLargo = True
End If
End Function
Public Function ComSepUFOsLargo() As Boolean
'Comprueba las separacion entre UFOS, la utiliza
'la funcion Juntar UFOS
Dim d As Integer
For d = 1 To UBound(UFOs) - 1
If (UFOs(d + 1).x - UFOs(d).x) > (65 * 6 / 5) Then
ComSepUFOsLargo = True
Exit Function
End If
Next
End Function
Public Sub JuntarUFOS()
' La funcion 'magica' k junta los ufos si kedan wecos entre ellos.
'Muy larga pork admite todas las posibilidades
Select Case UBound(UFOs)
Case 6
If ComSepUFOsLargo() = True Then
If ComSep2UFOsLargo(5, 6) Then
UFOs(6).x = UFOs(6).x - Distancia2UFOs(5, 6)
End If
If ComSep2UFOs(1, 2) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(1, 2)
End If
If ComSep2UFOs(2, 3) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(2, 3)
UFOs(2).x = UFOs(2).x + Distancia2UFOs(2, 3)
End If
If ComSep2UFOs(4, 5) Then
UFOs(6).x = UFOs(6).x - Distancia2UFOs(4, 5)
UFOs(5).x = UFOs(5).x - Distancia2UFOs(4, 5)
End If
If ComSep2UFOs(3, 4) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(3, 4)
UFOs(2).x = UFOs(2).x + Distancia2UFOs(3, 4)
UFOs(3).x = UFOs(3).x + Distancia2UFOs(3, 4)
UFOs(6).x = UFOs(6).x - Distancia2UFOs(3, 4)
UFOs(5).x = UFOs(5).x - Distancia2UFOs(3, 4)
UFOs(4).x = UFOs(4).x - Distancia2UFOs(3, 4)
End If
End If
Case 5
If ComSepUFOsLargo() = True Then
If ComSep2UFOsLargo(4, 5) Then
UFOs(5).x = UFOs(5).x - Distancia2UFOs(4, 5)
End If
If ComSep2UFOs(1, 2) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(1, 2)
End If
If ComSep2UFOs(3, 4) Then
UFOs(4).x = UFOs(4).x - Distancia2UFOs(3, 4)
UFOs(5).x = UFOs(5).x - Distancia2UFOs(3, 4)
End If
If ComSep2UFOs(2, 3) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(2, 3)
UFOs(2).x = UFOs(2).x + Distancia2UFOs(2, 3)
End If
End If
Case 4
If ComSepUFOs() = True Then
If ComSep2UFOs(2, 3) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(2, 3)
UFOs(2).x = UFOs(2).x + Distancia2UFOs(2, 3)
UFOs(3).x = UFOs(3).x - Distancia2UFOs(2, 3)
UFOs(4).x = UFOs(4).x - Distancia2UFOs(2, 3)
End If
If ComSep2UFOs(3, 4) Then
UFOs(4).x = UFOs(4).x - Distancia2UFOs(3, 4)
End If
If ComSep2UFOs(1, 2) Then
UFOs(1).x = UFOs(1).x + Distancia2UFOs(1, 2)
End If
End If
Case 3
If ComSepUFOs() = True Then
If ComSep2UFOs(2, 3) Then
UFOs(3).x = UFOs(3).x - Distancia2UFOs(2, 3)
End If