-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_ch13_07_pong_graph.vhd
1812 lines (1665 loc) · 84.7 KB
/
list_ch13_07_pong_graph.vhd
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
-- Listing 13.7
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY pong_graph IS
PORT (
clk, reset : STD_LOGIC;
btn : STD_LOGIC_VECTOR(1 DOWNTO 0);
pixel_x, pixel_y : IN STD_LOGIC_VECTOR(9 DOWNTO 0);
gra_still, died ,round_start: IN STD_LOGIC;
timer_up, attack_1_on, gamemode2 : IN STD_LOGIC;
keyboard_code : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
graph_on, hit, p1_damage, hit_p2, p2_damage,round_end : OUT STD_LOGIC;
rgb : OUT STD_LOGIC_VECTOR(2 DOWNTO 0)
);
END pong_graph;
ARCHITECTURE arch OF pong_graph IS
SIGNAL pix_x, pix_y : unsigned(9 DOWNTO 0);
CONSTANT MAX_X : INTEGER := 640;
CONSTANT MAX_Y : INTEGER := 480;
CONSTANT MIN_Y : INTEGER := 30;
CONSTANT WALL_X_L : INTEGER := 32;
CONSTANT WALL_X_R : INTEGER := 35;
-- --constant BAR_X_L: integer:=600;
-- --constant BAR_X_R: integer:=603;
-- CONSTANT BAR_X_L : INTEGER := 300;
-- CONSTANT BAR_X_R : INTEGER := 400;
-- SIGNAL bar_y_t, bar_y_b : unsigned(9 DOWNTO 0);
-- --constant BAR_Y_SIZE: integer:=72;
-- CONSTANT BAR_Y_SIZE : INTEGER := 3;
-- SIGNAL bar_y_reg, bar_y_next : unsigned(9 DOWNTO 0);
-- CONSTANT BAR_V : INTEGER := 8;
-- CONSTANT BALL_SIZE : INTEGER := 8; -- 8
-- SIGNAL ball_x_reg, ball_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL ball_y_reg, ball_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL ball_vx_reg, ball_vx_next : unsigned(9 DOWNTO 0);
-- SIGNAL ball_vy_reg, ball_vy_next : unsigned(9 DOWNTO 0);
-- SIGNAL keycode_reg : STD_LOGIC_VECTOR(7 DOWNTO 0);
-- SIGNAL keycode_next : STD_LOGIC_VECTOR(7 DOWNTO 0);
-- CONSTANT BALL_V_P : unsigned(9 DOWNTO 0)
-- := to_unsigned(2, 10);
-- CONSTANT BALL_V_N : unsigned(9 DOWNTO 0)
-- := unsigned(to_signed(-2, 10));
-- TYPE rom_type IS ARRAY (0 TO 7) OF
-- STD_LOGIC_VECTOR (7 DOWNTO 0);
-- CONSTANT BALL_ROM : rom_type :=
-- (
-- "00111100", -- ****
-- "01111110", -- ******
-- "11111111", -- ********
-- "11111111", -- ********
-- "11111111", -- ********
-- "11111111", -- ********
-- "01111110", -- ******
-- "00111100" -- ****
-- );
TYPE rom_type IS ARRAY (0 TO 7) OF
STD_LOGIC_VECTOR (7 DOWNTO 0);
---------------------------------
-- giga ship
---------------------------------
CONSTANT ship_SIZE : INTEGER := 16;
SIGNAL ship_x_l, ship_x_r : unsigned(9 DOWNTO 0);
SIGNAL ship_y_t, ship_y_b : unsigned(9 DOWNTO 0);
SIGNAL ship_x_reg, ship_x_next : unsigned(9 DOWNTO 0);
SIGNAL ship_y_reg, ship_y_next : unsigned(9 DOWNTO 0);
CONSTANT ship_V : INTEGER := 3;
TYPE rom_type_ship IS ARRAY (0 TO 15) OF
STD_LOGIC_VECTOR (15 DOWNTO 0);
CONSTANT ship_ROM : rom_type_ship :=
(
"0000000000000000",
"0000000011000000",
"0000000011000000",
"0000000011000000",
"0000000111100000",
"0000000111100000",
"0000011111111000",
"0000111111111100",
"0001111111111110",
"0011111111111111",
"0000001111110000",
"0000001111110000",
"0000011100111000",
"0000000100100000",
"0000000000000000",
"0000000000000000"
);
CONSTANT ship_ROM_2l : rom_type_ship :=
(
"0000000000000000",
"0000000001000000",
"0000000001000000",
"0000000011000000",
"0000000111100000",
"0000000111100000",
"0000000011100000",
"0000100011110100",
"0001111111111110",
"0011011111110111",
"0000001111110000",
"0000001111110000",
"0000011100111000",
"0000000100000000",
"0000000000000000",
"0000000000000000"
);
CONSTANT ship_ROM_1l : rom_type_ship :=
(
"0000000000000000",
"0000000001000000",
"0000000001000000",
"0000000011000000",
"0000000011000000",
"0000000010100000",
"0000000011100000",
"0000100011110100",
"0001111100011110",
"0011010001110111",
"0000000001100000",
"0000000111100000",
"0000011100110000",
"0000000100000000",
"0000000000000000",
"0000000000000000"
);
SIGNAL rom_addr_ship, rom_col_ship : unsigned(3 DOWNTO 0);
SIGNAL rom_data_ship : STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL rom_bit_ship : STD_LOGIC;
SIGNAL ship_lives_reg, ship_lives_next : unsigned(1 DOWNTO 0);
SIGNAL ship_got_hit : STD_LOGIC;
---------------------------------
-- Aliens
---------------------------------
CONSTANT ALIEN_SIZE : INTEGER := 8; -- 8
CONSTANT ALIEN_BOSS_SIZE : INTEGER := 16; -- 16
-- Alien 1
SIGNAL alien_x_l, alien_x_r : unsigned(9 DOWNTO 0);
SIGNAL alien_y_t, alien_y_b : unsigned(9 DOWNTO 0);
SIGNAL alien_x_reg, alien_x_next : unsigned(9 DOWNTO 0);
SIGNAL alien_y_reg, alien_y_next : unsigned(9 DOWNTO 0);
SIGNAL alien_vx_reg, alien_vx_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_vy_reg, alien_vy_next : unsigned(9 DOWNTO 0);
SIGNAL rom_addr_alien, rom_col_alien : unsigned(2 DOWNTO 0);
SIGNAL rom_data_alien : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL rom_bit_alien : STD_LOGIC;
-- SIGNAL alien_alive, alien_alive_reg, alien_alive_next : STD_LOGIC;
SIGNAL alien_alive_reg, alien_alive_next : STD_LOGIC;
SIGNAL alien_hits_counter_reg, alien_hits_counter_next : unsigned(2 DOWNTO 0);
SIGNAL sq_alien_1_on, rd_alien_1_on : STD_LOGIC;
-- Alien 2
SIGNAL alien_2_x_l, alien_2_x_r : unsigned(9 DOWNTO 0);
SIGNAL alien_2_y_t, alien_2_y_b : unsigned(9 DOWNTO 0);
SIGNAL alien_2_x_reg, alien_2_x_next : unsigned(9 DOWNTO 0);
SIGNAL alien_2_y_reg, alien_2_y_next : unsigned(9 DOWNTO 0);
SIGNAL alien_2_vx_reg, alien_2_vx_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_vy_reg, alien_2_vy_next : unsigned(9 DOWNTO 0);
SIGNAL rom_addr_alien_2, rom_col_alien_2 : unsigned(2 DOWNTO 0);
SIGNAL rom_data_alien_2 : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL rom_bit_alien_2 : STD_LOGIC;
-- SIGNAL alien_2_alive, alien_2_alive_reg, alien_2_alive_next : STD_LOGIC;
SIGNAL alien_2_alive_reg, alien_2_alive_next : STD_LOGIC;
SIGNAL alien_2_hits_counter_reg, alien_2_hits_counter_next : unsigned(2 DOWNTO 0);
SIGNAL sq_alien_2_on, rd_alien_2_on : STD_LOGIC;
-- Playable Alien
-- SIGNAL play_alien_x_l, play_alien_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_y_t, play_alien_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_x_reg, play_alien_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_y_reg, play_alien_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_vx_reg, play_alien_vx_next : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_vy_reg, play_alien_vy_next : unsigned(9 DOWNTO 0);
-- SIGNAL rom_addr_play_alien, rom_col_play_alien : unsigned(2 DOWNTO 0);
-- SIGNAL rom_data_play_alien : STD_LOGIC_VECTOR(7 DOWNTO 0);
-- SIGNAL rom_bit_play_alien : STD_LOGIC;
-- -- SIGNAL play_alien_alive, play_alien_alive_reg, play_alien_alive_next : STD_LOGIC;
-- -- SIGNAL play_alien_alive_reg, play_alien_alive_next : STD_LOGIC;
-- SIGNAL play_alien_hits_counter_reg, play_alien_hits_counter_next : unsigned(1 DOWNTO 0);
-- SIGNAL sq_play_alien_on, rd_play_alien_on : STD_LOGIC;
-- CONSTANT ALIEN_V : INTEGER := 4;
CONSTANT ALIEN_V_P : unsigned(9 DOWNTO 0) := to_unsigned(1, 10);
CONSTANT ALIEN_V_N : unsigned(9 DOWNTO 0) := unsigned(to_signed(-1, 10));
TYPE rom_type_alien IS ARRAY (0 TO 7) OF
STD_LOGIC_VECTOR (7 DOWNTO 0);
CONSTANT ALIEN_ROM : rom_type :=
(
"01111110", -- ******
"11011011", -- ** ** **
"01111110", -- ******
"00111100", -- ****
"01100110", -- ** **
"11111111", -- ********
"10011001", -- * ** *
"10011001" -- * ** *
);
--Alien boss
SIGNAL alien_boss_x_l, alien_boss_x_r : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_y_t, alien_boss_y_b : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_x_reg, alien_boss_x_next : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_y_reg, alien_boss_y_next : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_vx_reg, alien_boss_vx_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_boss_vy_reg, alien_boss_vy_next : unsigned(9 DOWNTO 0);
SIGNAL rom_addr_alien_boss, rom_col_alien_boss : unsigned(3 DOWNTO 0);
SIGNAL rom_data_alien_boss : STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL rom_bit_alien_boss : STD_LOGIC;
-- SIGNAL alien_boss_alive, alien_boss_alive_reg, alien_boss_alive_next : STD_LOGIC;
SIGNAL alien_boss_alive_reg, alien_boss_alive_next : STD_LOGIC;
SIGNAL alien_boss_hits_counter_reg, alien_boss_hits_counter_next : unsigned(2 DOWNTO 0);
SIGNAL alien_boss_lives_reg, alien_boss_lives_next : unsigned(3 DOWNTO 0);
TYPE rom_type_16_16 IS ARRAY (0 TO 15) OF
STD_LOGIC_VECTOR (15 DOWNTO 0);
CONSTANT ALIEN_BOSS_ROM : rom_type_16_16 :=
(
"0000000000000000",
"0000000000000000",
"0000001111000000",
"0000011111100000",
"0000111111110000",
"0001110111011000",
"0001110010011000",
"0000111111110000",
"0000001111100000",
"0001001111100100",
"0001011111110100",
"0001110000111100",
"0000011001100000",
"0000001001000000",
"0000000000000000",
"0000000000000000"
);
CONSTANT ALIEN_BOSS_2_ROM : rom_type_16_16 :=
(
"0000000000000000",
"0000000000000000",
"0000000111000000",
"0000000111100000",
"0000011111100000",
"0001110111011000",
"0001110010011000",
"0000111111110000",
"0000000111100000",
"0001000011100100",
"0001011110110100",
"0000000000111100",
"0000000001100000",
"0000000001000000",
"0000000000000000",
"0000000000000000"
);
--initial border
CONSTANT initial_border : rom_type_16_16 :=
(
"1100110000110011",
"1000000000000001",
"0000000000000000",
"0000000000000000",
"1000000000000001",
"1000000000000001",
"0000000000000000",
"0000000000000000",
"0000000000000000",
"0000000000000000",
"1000000000000001",
"1000000000000001",
"0000000000000000",
"0000000000000000",
"1000000000000001",
"1100110000110011"
);
SIGNAL sq_border_on, rd_border_on : STD_LOGIC;
SIGNAL rom_addr_border, rom_col_border : unsigned(3 DOWNTO 0);
SIGNAL rom_data_border : STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL rom_bit_border : STD_LOGIC;
SIGNAL border_x_l, border_x_r : unsigned(9 DOWNTO 0);
SIGNAL border_y_t, border_y_b : unsigned(9 DOWNTO 0);
---------------------------------
-- Aliens Projectiles
---------------------------------
CONSTANT ALIEN_PROJECTIL_SIZE : INTEGER := 12; -- 4
CONSTANT ALIEN_PROJECTIL_WIDTH : INTEGER := 4; -- 2
CONSTANT ALIEN_PROJ_V_MOVE : unsigned(9 DOWNTO 0) := to_unsigned(1, 10);
-- CONSTANT ALIEN_PROJ_V_NO_MOVE : unsigned(9 DOWNTO 0) := to_unsigned(0, 10);
-- SIGNAL projectil_timer_reg, projectil_timer_next : unsigned(4 DOWNTO 0);
-- Alien 1
SIGNAL alien_projectil_x_l, alien_projectil_x_r : unsigned(9 DOWNTO 0);
SIGNAL alien_projectil_y_t, alien_projectil_y_b : unsigned(9 DOWNTO 0);
SIGNAL alien_projectil_x_reg, alien_projectil_x_next : unsigned(9 DOWNTO 0);
SIGNAL alien_projectil_y_reg, alien_projectil_y_next : unsigned(9 DOWNTO 0);
SIGNAL alien_projectil_on, alien_projectil_hit_reg, alien_projectil_hit_next : STD_LOGIC;
-- Projectil 2
-- SIGNAL alien_projectil_2_x_l, alien_projectil_2_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_2_y_t, alien_projectil_2_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_2_x_reg, alien_projectil_2_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_2_y_reg, alien_projectil_2_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_2_on, alien_projectil_2_hit_reg, alien_projectil_2_hit_next : STD_LOGIC;
-- -- Projectil 3
-- SIGNAL alien_projectil_3_x_l, alien_projectil_3_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_3_y_t, alien_projectil_3_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_3_x_reg, alien_projectil_3_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_3_y_reg, alien_projectil_3_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_projectil_3_on, alien_projectil_3_hit_reg, alien_projectil_3_hit_next : STD_LOGIC;
---------------- Alien 2 ----------------
-- Projectil 1
SIGNAL alien_2_projectil_x_l, alien_2_projectil_x_r : unsigned(9 DOWNTO 0);
SIGNAL alien_2_projectil_y_t, alien_2_projectil_y_b : unsigned(9 DOWNTO 0);
SIGNAL alien_2_projectil_x_reg, alien_2_projectil_x_next : unsigned(9 DOWNTO 0);
SIGNAL alien_2_projectil_y_reg, alien_2_projectil_y_next : unsigned(9 DOWNTO 0);
SIGNAL alien_2_projectil_on, alien_2_projectil_hit_reg, alien_2_projectil_hit_next : STD_LOGIC;
-- Projectil 2
-- SIGNAL alien_2_projectil_2_x_l, alien_2_projectil_2_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_2_y_t, alien_2_projectil_2_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_2_x_reg, alien_2_projectil_2_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_2_y_reg, alien_2_projectil_2_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_2_on, alien_2_projectil_2_hit_reg, alien_2_projectil_2_hit_next : STD_LOGIC;
-- -- Projectil 3
-- SIGNAL alien_2_projectil_3_x_l, alien_2_projectil_3_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_3_y_t, alien_2_projectil_3_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_3_x_reg, alien_2_projectil_3_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_3_y_reg, alien_2_projectil_3_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL alien_2_projectil_3_on, alien_2_projectil_3_hit_reg, alien_2_projectil_3_hit_next : STD_LOGIC;
-- Alien Boss
SIGNAL alien_boss_projectil_x_l, alien_boss_projectil_x_r : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_projectil_y_t, alien_boss_projectil_y_b : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_projectil_x_reg, alien_boss_projectil_x_next : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_projectil_y_reg, alien_boss_projectil_y_next : unsigned(9 DOWNTO 0);
SIGNAL alien_boss_projectil_on, alien_boss_projectil_hit_reg, alien_boss_projectil_hit_next : STD_LOGIC;
SIGNAL play_alien_shoot_counter_reg, play_alien_shoot_counter_next, respawn_timer_reg,respawn_timer_next : unsigned(6 DOWNTO 0);
---------------------------------
-- Playable Alien Projectiles
---------------------------------
-- -- Porjectile 1
-- SIGNAL play_alien_projectil_1_x_l, play_alien_projectil_1_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_projectil_1_y_t, play_alien_projectil_1_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_projectil_1_x_reg, play_alien_projectil_1_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_projectil_1_y_reg, play_alien_projectil_1_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL play_alien_projectil_1_on, play_alien_projectil_1_hit_reg, play_alien_projectil_1_hit_next : STD_LOGIC;
---------------------------------
-- Ship Projectiles
---------------------------------
CONSTANT PROJ_WIDTH : INTEGER := 3;
CONSTANT PROJ_SIZE : INTEGER := 10;
SIGNAL PROJ1_V : INTEGER := 2;
SIGNAL shoot_counter_reg, shoot_counter_next : unsigned(6 DOWNTO 0);
-- Porjectile 1
SIGNAL ship_projectil_1_x_l, ship_projectil_1_x_r : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_1_y_t, ship_projectil_1_y_b : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_1_x_reg, ship_projectil_1_x_next : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_1_y_reg, ship_projectil_1_y_next : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_1_on, ship_projectil_1_hit_reg, ship_projectil_1_hit_next : STD_LOGIC;
--teste
-- SIGNAL proj1_y_t, proj1_y_b, proj1_x_r, proj1_x_l, proj1_x_l_reg, proj1_y_t_reg, proj1_y_t_next, proj1_x_l_next : unsigned(9 DOWNTO 0);
-- SIGNAL proj1_hit_reg : STD_LOGIC;
-- Porjectile 2
-- SIGNAL ship_projectil_2_x_l, ship_projectil_2_x_r : unsigned(9 DOWNTO 0);
-- SIGNAL ship_projectil_2_y_t, ship_projectil_2_y_b : unsigned(9 DOWNTO 0);
-- SIGNAL ship_projectil_2_x_reg, ship_projectil_2_x_next : unsigned(9 DOWNTO 0);
-- SIGNAL ship_projectil_2_y_reg, ship_projectil_2_y_next : unsigned(9 DOWNTO 0);
-- SIGNAL ship_projectil_2_on, ship_projectil_2_hit_reg, ship_projectil_2_hit_next : STD_LOGIC;
-- Porjectile 3
SIGNAL ship_projectil_3_x_l, ship_projectil_3_x_r : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_3_y_t, ship_projectil_3_y_b : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_3_x_reg, ship_projectil_3_x_next : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_3_y_reg, ship_projectil_3_y_next : unsigned(9 DOWNTO 0);
SIGNAL ship_projectil_3_on, ship_projectil_3_hit_reg, ship_projectil_3_hit_next : STD_LOGIC;
---------------------------------
-- HP Alien Boss Bar
---------------------------------
SIGNAL hp_alien_boss_bar_green_on, hp_alien_boss_bar_red_on : STD_LOGIC;
---------------------------------
-- Constant Keys
---------------------------------
CONSTANT left_arrow : STD_LOGIC_VECTOR (7 DOWNTO 0) := "01101011";
CONSTANT right_arrow : STD_LOGIC_VECTOR (7 DOWNTO 0) := "01110100";
CONSTANT down_arrow : STD_LOGIC_VECTOR (7 DOWNTO 0) := "01110010";
CONSTANT up_arrow : STD_LOGIC_VECTOR (7 DOWNTO 0) := "01110101";
CONSTANT d : STD_LOGIC_VECTOR (7 DOWNTO 0) := "00100011";
CONSTANT r : STD_LOGIC_VECTOR (7 DOWNTO 0) := "00101101";
CONSTANT j : STD_LOGIC_VECTOR (7 DOWNTO 0) := "00101011";
CONSTANT g : STD_LOGIC_VECTOR (7 DOWNTO 0) := "00110100";
CONSTANT f : STD_LOGIC_VECTOR (7 DOWNTO 0) := "00111011";
-- CONSTANT shoot : STD_LOGIC_VECTOR (7 DOWNTO 0) := "00101001";
CONSTANT shoot : STD_LOGIC_VECTOR (7 DOWNTO 0) := "01110000";
---------------------------------
-- Random Generator
---------------------------------
-- SIGNAL rand_reg : unsigned(9 DOWNTO 0) := "0010110101";
-- SIGNAL rand_next, rand_number : unsigned(9 DOWNTO 0);
-- SIGNAL random1 : unsigned(9 DOWNTO 0);
-------------------------------
--BOx
-------------------------------
-- CONSTANT WIDTH : INTEGER := 4;
-- CONSTANT WALL_SIZE : INTEGER := 400;
-- CONSTANT WALL1_X_R : INTEGER := (MAX_X - WALL_SIZE)/2;
-- CONSTANT WALL1_X_L : INTEGER := WALL1_X_R - WIDTH;
-- CONSTANT WALL2_X_L : INTEGER := (MAX_X + WALL_SIZE)/2;
-- CONSTANT WALL2_X_R : INTEGER := WALL2_X_L + WIDTH;
-- CONSTANT WALL_Y_T : INTEGER := 50;
-- CONSTANT WALL_Y_T2 : INTEGER := WALL_Y_T + WIDTH;
-- CONSTANT WALL_Y_B : INTEGER := WALL_Y_T2 + WALL_SIZE;
-- CONSTANT WALL_Y_B2 : INTEGER := WALL_Y_B + WIDTH;
SIGNAL sq_ship_on, rd_ship_on : STD_LOGIC;
SIGNAL proj1_rgb, ship_rgb, ship_rgb_2, ship_rgb_1, alien_rgb, play_alien_rgb, alien_boss_rgb, border_rgb :
STD_LOGIC_VECTOR(2 DOWNTO 0);
-- Alien Flags
SIGNAL sq_alien_boss_on, rd_alien_boss_on : STD_LOGIC;
SIGNAL refr_tick : STD_LOGIC;
SIGNAL rom_ship_addr, rom_ship_col : unsigned(2 DOWNTO 0);
SIGNAL rom_ship_data : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL rom_ship_bit : STD_LOGIC;
BEGIN
-- registers
PROCESS (clk, reset, died)
BEGIN
IF reset = '1' OR died = '1' THEN
-- bar_y_reg <= (OTHERS => '0');
-- ball_x_reg <= (OTHERS => '0');
-- ball_y_reg <= (OTHERS => '0');
-- ball_vx_reg <= ("0000000100");
-- ball_vy_reg <= ("0000000100");
alien_x_reg <= (OTHERS => '0');
alien_y_reg <= (OTHERS => '0');
alien_vx_reg <= ("0000000100");
-- alien_vy_reg <= ("0000000100");
alien_alive_reg <= '1';
alien_hits_counter_reg <= (OTHERS => '0');
alien_2_x_reg <= (OTHERS => '0');
alien_2_y_reg <= (OTHERS => '0');
alien_2_vx_reg <= ("0000000100");
-- alien_2_vy_reg <= ("0000000100");
alien_2_alive_reg <= '1';
alien_2_hits_counter_reg <= (OTHERS => '0');
-- play_alien_x_reg <= (OTHERS => '0');
-- play_alien_y_reg <= (OTHERS => '0');
-- play_alien_vx_reg <= ("0000000100");
-- play_alien_vy_reg <= ("0000000100");
-- -- play_alien_alive_reg <= '1';
-- play_alien_hits_counter_reg <= (OTHERS => '0');
--Alien boss
alien_boss_x_reg <= (OTHERS => '0');
alien_boss_y_reg <= (OTHERS => '0');
alien_boss_vx_reg <= ("0000000100");
-- alien_boss_vy_reg <= ("0000000100");
alien_boss_alive_reg <= '1';
alien_boss_hits_counter_reg <= (OTHERS => '0');
alien_boss_lives_reg <= "1010";
-- Alien Projectil 1 Hit Flag Initialization
alien_projectil_hit_reg <= '1';
-- Alien 2 Projectil 1 Hit Flag Initialization
alien_2_projectil_hit_reg <= '1';
-- Alien Boss projectil hit flag initialization
alien_boss_projectil_hit_reg <= '1';
-- Playable Alien Shoots Counter Initialization
play_alien_shoot_counter_reg <= (OTHERS => '0');
-- Playable Alien Projectil 1 Hit Flag Initialization
-- play_alien_projectil_1_hit_reg <= '1';
-- keycode_reg <= (OTHERS => '0');
ship_x_reg <= (OTHERS => '0');
ship_y_reg <= (OTHERS => '0');
-- proj1_y_t_reg <= (OTHERS => '0');
-- new_proj1_reg <= '0';
-- rand_reg <= "0010110101"; -- seed
-- proj1_hit_reg <= '0';
-- proj1_x_l_reg <= (OTHERS => '0');
-- proj1_y_t_reg <= (OTHERS => '0');
-- Ship Projectil 1 Hit Flag Initialization
ship_projectil_1_hit_reg <= '1';
-- Ship Projectil 2 Hit Flag Initialization
-- ship_projectil_2_hit_reg <= '0';
-- Ship Projectil 3 Hit Flag Initialization
ship_projectil_3_hit_reg <= '1';
-- Shoots Counter Initialization
shoot_counter_reg <= (OTHERS => '0');
--lives
ship_lives_reg <= "11";
respawn_timer_reg<=(OTHERS => '0');
ELSIF (clk'event AND clk = '1') THEN
-- bar_y_reg <= bar_y_next;
-- ball_x_reg <= ball_x_next;
-- ball_y_reg <= ball_y_next;
-- ball_vx_reg <= ball_vx_next;
-- ball_vy_reg <= ball_vy_next;
-- keycode_reg <= keycode_next;
alien_x_reg <= alien_x_next;
alien_y_reg <= alien_y_next;
alien_vx_reg <= alien_vx_next;
-- alien_vy_reg <= alien_vy_next;
alien_alive_reg <= alien_alive_next;
alien_hits_counter_reg <= alien_hits_counter_next;
alien_2_x_reg <= alien_2_x_next;
alien_2_y_reg <= alien_2_y_next;
alien_2_vx_reg <= alien_2_vx_next;
-- alien_2_vy_reg <= alien_2_vy_next;
alien_2_alive_reg <= alien_2_alive_next;
alien_2_hits_counter_reg <= alien_2_hits_counter_next;
-- play_alien_x_reg <= play_alien_x_next;
-- play_alien_y_reg <= play_alien_y_next;
-- play_alien_vx_reg <= play_alien_vx_next;
-- play_alien_vy_reg <= play_alien_vy_next;
-- -- play_alien_alive_reg <= play_alien_alive_next;
-- play_alien_hits_counter_reg <= play_alien_hits_counter_next;
--Alien boss
alien_boss_x_reg <= alien_boss_x_next;
alien_boss_y_reg <= alien_boss_y_next;
alien_boss_vx_reg <= alien_boss_vx_next;
-- alien_boss_vy_reg <= alien_boss_vy_next;
alien_boss_alive_reg <= alien_boss_alive_next;
alien_boss_hits_counter_reg <= alien_boss_hits_counter_next;
alien_boss_lives_reg <= alien_boss_lives_next;
-- projectil_timer_reg <= projectil_timer_next;
alien_projectil_x_reg <= alien_projectil_x_next;
alien_projectil_y_reg <= alien_projectil_y_next;
alien_projectil_hit_reg <= alien_projectil_hit_next;
-- Alien 1: Projectil 2 Position Update
-- alien_projectil_2_x_reg <= alien_projectil_2_x_next;
-- alien_projectil_2_y_reg <= alien_projectil_2_y_next;
-- alien_projectil_2_hit_reg <= alien_projectil_2_hit_next;
-- -- Alien 1: Projectil 3 Position Update
-- alien_projectil_3_x_reg <= alien_projectil_3_x_next;
-- alien_projectil_3_y_reg <= alien_projectil_3_y_next;
-- alien_projectil_3_hit_reg <= alien_projectil_3_hit_next;
-- Alien 2: Projectil 1 Position Update
alien_2_projectil_x_reg <= alien_2_projectil_x_next;
alien_2_projectil_y_reg <= alien_2_projectil_y_next;
alien_2_projectil_hit_reg <= alien_2_projectil_hit_next;
-- Alien 2: Projectil 2 Position Update
-- alien_2_projectil_2_x_reg <= alien_2_projectil_2_x_next;
-- alien_2_projectil_2_y_reg <= alien_2_projectil_2_y_next;
-- alien_2_projectil_2_hit_reg <= alien_2_projectil_2_hit_next;
-- -- Alien 2: Projectil 3 Position Update
-- alien_2_projectil_3_x_reg <= alien_2_projectil_3_x_next;
-- alien_2_projectil_3_y_reg <= alien_2_projectil_3_y_next;
-- alien_2_projectil_3_hit_reg <= alien_2_projectil_3_hit_next;
-- Playable Alien Projectil 1 Variables Update
-- play_alien_projectil_1_x_reg <= play_alien_projectil_1_x_next;
-- play_alien_projectil_1_y_reg <= play_alien_projectil_1_y_next;
-- play_alien_projectil_1_hit_reg <= play_alien_projectil_1_hit_next;
--Alien boss projectil
alien_boss_projectil_x_reg <= alien_boss_projectil_x_next;
alien_boss_projectil_y_reg <= alien_boss_projectil_y_next;
alien_boss_projectil_hit_reg <= alien_boss_projectil_hit_next;
ship_x_reg <= ship_x_next;
ship_y_reg <= ship_y_next;
-- Alien Playable Shoots Counter Variable Update
play_alien_shoot_counter_reg <= play_alien_shoot_counter_next;
-- timer respawn
respawn_timer_reg <= respawn_timer_next;
-- proj1_y_t_reg <= proj1_y_t_next;
-- rand_reg <= rand_next;
-- new_proj1_reg <= new_proj1_next;
-- proj1_hit_reg <= proj1_hit_next;
-- proj1_x_l_reg <= proj1_x_l_next;
-- proj1_y_t_reg <= proj1_y_t_next;
-- Shihp Projectil 1 Variables Update
ship_projectil_1_x_reg <= ship_projectil_1_x_next;
ship_projectil_1_y_reg <= ship_projectil_1_y_next;
ship_projectil_1_hit_reg <= ship_projectil_1_hit_next;
-- Shihp Projectil 2 Variables Update
-- ship_projectil_2_x_reg <= ship_projectil_2_x_next;
-- ship_projectil_2_y_reg <= ship_projectil_2_y_next;
-- ship_projectil_2_hit_reg <= ship_projectil_2_hit_next;
-- Shihp Projectil 3 Variables Update
ship_projectil_3_x_reg <= ship_projectil_3_x_next;
ship_projectil_3_y_reg <= ship_projectil_3_y_next;
ship_projectil_3_hit_reg <= ship_projectil_3_hit_next;
-- Shoots Counter Variable Update
shoot_counter_reg <= shoot_counter_next;
--ship lives
ship_lives_reg <= ship_lives_next;
END IF;
END PROCESS;
pix_x <= unsigned(pixel_x);
pix_y <= unsigned(pixel_y);
refr_tick <= '1' WHEN (pix_y = 481) AND (pix_x = 0) ELSE
'0';
----------------------------------------------
-- initial border
----------------------------------------------
border_y_t <= to_unsigned((MAX_Y)/2, 10) - 125;
border_x_l <= to_unsigned((MAX_X)/2, 10) - 60;
border_x_r <= border_x_l + ship_SIZE * 8 - 1-8;
border_y_b <= border_y_t + ship_SIZE * 8 - 1 -6;
-- border_y_t <= to_unsigned((MAX_Y)/2, 10);
-- border_x_l <= to_unsigned((MAX_X)/2, 10);
-- border_x_r <= border_x_l + ship_SIZE * 8;
-- border_y_b <= border_y_t + ship_SIZE * 8;
sq_border_on <=
'1' WHEN (border_x_l <= pix_x) AND (pix_x <= border_x_r) AND
(border_y_t <= pix_y) AND (pix_y <= border_y_b) ELSE
'0';
rd_border_on <=
'1' WHEN (sq_border_on = '1') AND (rom_bit_border = '1') AND (gra_still='1') ELSE
'0';
rom_addr_border <= pix_y(6 DOWNTO 3) - border_y_t(6 DOWNTO 3);
rom_col_border <= pix_x(6 DOWNTO 3) - border_x_l(6 DOWNTO 3);
-- rom_addr_border <= pix_y(6 DOWNTO 3) - border_y_t(3 DOWNTO 0);
-- rom_col_border <= pix_x(6 DOWNTO 3) - border_x_l(3 DOWNTO 0);
rom_data_border <= initial_border(to_integer(rom_addr_border));
rom_bit_border <= rom_data_border(to_integer(NOT rom_col_border));
border_rgb <= "010";
---------------------------s-------------------
-- SHIP
----------------------------------------------
-- square ship
ship_x_l <= ship_x_reg;
ship_y_t <= ship_y_reg;
ship_x_r <= ship_x_l + ship_SIZE + ship_SIZE - 1;
ship_y_b <= ship_y_t + ship_SIZE + ship_SIZE - 1;
sq_ship_on <=
'1' WHEN (ship_x_l <= pix_x) AND (pix_x <= ship_x_r) AND
(ship_y_t <= pix_y) AND (pix_y <= ship_y_b) ELSE
'0';
-- round ship
rom_addr_ship <= pix_y(4 DOWNTO 1) - ship_y_t(4 DOWNTO 1);
rom_col_ship <= pix_x(4 DOWNTO 1) - ship_x_l(4 DOWNTO 1);
rom_data_ship <= ship_ROM_2l(to_integer(rom_addr_ship)) WHEN ship_lives_reg = "10" ELSE
ship_ROM_1l(to_integer(rom_addr_ship)) WHEN ship_lives_reg = "01" ELSE
ship_ROM(to_integer(rom_addr_ship));
rom_bit_ship <= rom_data_ship(to_integer(NOT rom_col_ship));
rd_ship_on <=
'1' WHEN (sq_ship_on = '1') AND (rom_bit_ship = '1') ELSE
'0';
ship_rgb <= "011"; --white
ship_rgb_2 <= "110"; -- yellow
ship_rgb_1 <= "100";-- red
-- new ship position
PROCESS (refr_tick, gra_still, ship_y_reg, ship_x_reg, keyboard_code, ship_got_hit)
BEGIN
ship_y_next <= ship_y_reg;
ship_x_next <= ship_x_reg;
IF gra_still = '1' OR ship_got_hit = '1' THEN --initial position of ship
-- ship_x_next <= to_unsigned((WALL2_X_L + WALL1_X_R)/2, 10);
-- ship_y_next <= to_unsigned((WALL_Y_B + WALL_Y_T2)/2, 10);
ship_x_next <= to_unsigned((MAX_X)/2, 10);
ship_y_next <= to_unsigned((MAX_Y/2) + 30, 10);
ELSIF refr_tick = '1' THEN
IF (keyboard_code = down_arrow) THEN
IF (ship_y_reg > MAX_Y - 20) THEN
ship_y_next <= to_unsigned(20, 10);
ELSE
ship_y_next <= ship_y_reg + ship_V; -- move down
--projectile new initial position
-- proj1_y_initial<= to_unsigned(to_integer(ship_y_reg + ship_V) - 16 - PROJ_SIZE, 10);
END IF;
ELSIF (keyboard_code = up_arrow) THEN
--projectile new initial position
-- proj1_y_initial<= to_unsigned(to_integer(ship_y_reg + ship_V) - 16 - PROJ_SIZE, 10);
IF (ship_y_reg < 20) THEN
ship_y_next <= to_unsigned(MAX_Y - 20, 10);
ELSE
ship_y_next <= ship_y_reg - ship_V; -- move up
END IF;
ELSIF (keyboard_code = right_arrow) THEN
IF (ship_x_reg > MAX_X - 20) THEN
ship_x_next <= to_unsigned(20, 10);
ELSE
ship_x_next <= ship_x_reg + ship_V; -- move right
END IF;
ELSIF (keyboard_code = left_arrow) THEN
IF (ship_x_reg < 20) THEN
ship_x_next <= to_unsigned(MAX_X - 20, 10);
ELSE
ship_x_next <= ship_x_reg - ship_V; -- move left
END IF;
END IF;
END IF;
END PROCESS;
----------------------------------------------
-- SHIP PROJECTILES
----------------------------------------------
----------------------------------------------
--- Projectil 1
----------------------------------------------
ship_projectil_1_x_l <= ship_projectil_1_x_reg;
ship_projectil_1_y_t <= ship_projectil_1_y_reg;
ship_projectil_1_x_r <= ship_projectil_1_x_l + PROJ_WIDTH - 1;
ship_projectil_1_y_b <= ship_projectil_1_y_t + PROJ_SIZE - 1;
ship_projectil_1_on <=
'1' WHEN (ship_projectil_1_x_l <= pix_x) AND (pix_x <= ship_projectil_1_x_r) AND
(ship_projectil_1_y_t <= pix_y) AND (pix_y <= ship_projectil_1_y_b) AND
(ship_projectil_1_hit_reg = '0') ELSE
'0';
ship_projectil_1_x_next <=
ship_x_reg WHEN (keyboard_code = shoot AND ship_projectil_1_hit_reg = '1') ELSE
ship_projectil_1_x_reg;
ship_projectil_1_y_next <=
ship_y_reg WHEN (keyboard_code = shoot AND ship_projectil_1_hit_reg = '1') ELSE
ship_projectil_1_y_reg - PROJ1_V WHEN refr_tick = '1' ELSE
ship_projectil_1_y_reg;
-- Ship Projectil Hit Flag Update
ship_projectil_1_hit_next <= '1' WHEN (ship_projectil_1_y_t < 3 OR gra_still = '1') OR
-- (ship_projectil_1_on = '1' AND (rd_alien_1_on = '1' OR rd_alien_2_on = '1' OR rd_alien_boss_on = '1' OR rd_play_alien_on = '1')) ELSE
(ship_projectil_1_on = '1' AND (rd_alien_1_on = '1' OR rd_alien_2_on = '1' OR rd_alien_boss_on = '1')) ELSE
'0' WHEN (keyboard_code = shoot) ELSE
ship_projectil_1_hit_reg;
-- -- Projectil Hit State
-- PROCESS (ship_projectil_1_hit_reg, ship_projectil_1_on, ship_projectil_1_y_b, rd_alien_1_on, rd_alien_2_on)
-- BEGIN
-- ship_projectil_1_hit_next <= ship_projectil_1_hit_reg;
-- IF ship_projectil_1_hit_reg = '1' THEN
-- ship_projectil_1_hit_next <= '0';
-- ELSIF (ship_projectil_1_on = '1') AND (rd_alien_1_on = '1' OR rd_alien_2_on = '1') THEN
-- ship_projectil_1_hit_next <= '1';
-- ELSIF (ship_projectil_1_y_b < 10) THEN
-- ship_projectil_1_hit_next <= '1';
-- END IF;
-- END PROCESS;
-- proj1_y_t <= proj1_y_t_reg;
-- proj1_y_b <= proj1_y_t + PROJ_SIZE - 1;
-- proj1_x_r <= proj1_x_l_reg + PROJ_WIDTH;
-- proj1_x_l <= proj1_x_l_reg;
-- proj1_on <=
-- '1' WHEN (proj1_x_l_reg <= pix_x) AND (pix_x <= proj1_x_r) AND
-- (proj1_y_t <= pix_y) AND (pix_y <= proj1_y_b) AND (proj1_hit_reg = '0')ELSE
-- '0';
proj1_rgb <= "101"; -- magenta
-- -- new projectile1 y-position
-- --Projectile y axis
-- proj1_y_t_next <= ship_y_reg WHEN (proj1_hit_reg = '1') ELSE
-- (proj1_y_t_reg - PROJ1_V) WHEN refr_tick = '1' ELSE
-- proj1_y_t_reg;
-- proj1_hit_next <= '1' WHEN (proj1_y_t < 3 OR gra_still = '1' OR (proj1_on = '1' AND rd_play_alien_on = '1') OR (rd_alien_boss_on = '1' AND proj1_on = '1')) ELSE
-- '0' WHEN (keyboard_code = shoot) ELSE
-- proj1_hit_reg;
-- --Projectile x axis
-- proj1_x_l_next <= ship_x_reg WHEN (keyboard_code = shoot AND proj1_hit_reg = '1') ELSE
-- proj1_x_l_reg;
----------------------------------------------
-- Projectile 2
----------------------------------------------
-- ship_projectil_2_x_l <= ship_projectil_2_x_reg;
-- ship_projectil_2_y_t <= ship_projectil_2_y_reg;
-- ship_projectil_2_x_r <= ship_projectil_2_x_l + PROJ_WIDTH - 1;
-- ship_projectil_2_y_b <= ship_projectil_2_y_t + PROJ_SIZE - 1;
-- ship_projectil_2_on <=
-- '1' WHEN (ship_projectil_2_x_l <= pix_x) AND (pix_x <= ship_projectil_2_x_r) AND
-- (ship_projectil_2_y_t <= pix_y) AND (pix_y <= ship_projectil_2_y_b) AND
-- (ship_projectil_2_hit_reg = '0') ELSE
-- '0';
-- -- New Ship Projectil Position
-- ship_projectil_2_x_next <=
-- ship_x_reg + ship_SIZE WHEN (keyboard_code = shoot AND ship_projectil_2_hit_reg = '1') ELSE
-- ship_projectil_2_x_reg;
-- ship_projectil_2_y_next <=
-- ship_y_reg WHEN (keyboard_code = shoot AND ship_projectil_2_hit_reg = '1') ELSE
-- ship_projectil_2_y_reg - PROJ1_V WHEN refr_tick = '1' ELSE
-- ship_projectil_2_y_reg;
-- -- Ship Projectil Hit Flag Update
-- ship_projectil_2_hit_next <= '1' WHEN (ship_projectil_2_y_t < 10 OR gra_still = '1') OR
-- (ship_projectil_2_on = '1' AND (rd_alien_1_on = '1' OR rd_alien_2_on = '1')) ELSE
-- '0' WHEN (keyboard_code = shoot AND ship_projectil_2_hit_reg = '1' AND shoot_counter_reg > 50 AND shoot_counter_reg < 75) ELSE
-- ship_projectil_2_hit_reg;
----------------------------------------------
-- Projectile 3
----------------------------------------------
ship_projectil_3_x_l <= ship_projectil_3_x_reg;
ship_projectil_3_y_t <= ship_projectil_3_y_reg;
ship_projectil_3_x_r <= ship_projectil_3_x_l + PROJ_WIDTH - 1;
ship_projectil_3_y_b <= ship_projectil_3_y_t + PROJ_SIZE - 1;
ship_projectil_3_on <=
'1' WHEN (ship_projectil_3_x_l <= pix_x) AND (pix_x <= ship_projectil_3_x_r) AND
(ship_projectil_3_y_t <= pix_y) AND (pix_y <= ship_projectil_3_y_b) AND
(ship_projectil_3_hit_reg = '0') ELSE
'0';
-- New Ship Projectil Position
ship_projectil_3_x_next <=
ship_x_reg + ship_SIZE + ship_SIZE WHEN (ship_projectil_3_hit_reg = '1') ELSE
ship_projectil_3_x_reg;
ship_projectil_3_y_next <=
ship_y_reg WHEN (ship_projectil_3_hit_reg = '1') ELSE
ship_projectil_3_y_reg - PROJ1_V WHEN refr_tick = '1' ELSE
ship_projectil_3_y_reg;
-- Ship Projectil Hit Flag Update
ship_projectil_3_hit_next <= '1' WHEN (ship_projectil_3_y_t < 3 OR gra_still = '1') OR
-- (ship_projectil_3_on = '1' AND (rd_alien_1_on = '1' OR rd_alien_2_on = '1' OR rd_alien_boss_on = '1' OR rd_play_alien_on = '1')) ELSE
(ship_projectil_3_on = '1' AND (rd_alien_1_on = '1' OR rd_alien_2_on = '1' OR rd_alien_boss_on = '1')) ELSE
'0' WHEN (keyboard_code = shoot AND ship_projectil_3_hit_reg = '1' AND shoot_counter_reg > 100) ELSE
ship_projectil_3_hit_reg;
----------------------------------------------
-- Shoots Counter Incrementation Process
----------------------------------------------
PROCESS (shoot_counter_reg, refr_tick, ship_projectil_1_hit_reg,play_alien_shoot_counter_reg,gamemode2,alien_boss_projectil_hit_reg,respawn_timer_reg)
BEGIN
shoot_counter_next <= shoot_counter_reg;
IF (ship_projectil_1_hit_reg = '0') THEN
IF (refr_tick = '1') THEN
shoot_counter_next <= shoot_counter_reg + 1;
-- IF shoot_counter_reg = 101 THEN
-- shoot_counter_next <= (OTHERS => '0');
-- END IF;
END IF;
ELSE
shoot_counter_next <= (OTHERS => '0');
END IF;
IF (alien_boss_projectil_hit_reg = '0') THEN -- Player VS Player Mode
IF (refr_tick = '1' AND (gamemode2 = '1')) THEN
play_alien_shoot_counter_next <= play_alien_shoot_counter_reg + 1;
END IF;
ELSE
play_alien_shoot_counter_next <= (OTHERS => '0');
END IF;
END PROCESS;
-- -- square ship
-- ship_x_l <= ship_x_reg;
-- ship_y_t <= ship_y_reg;
-- ship_x_r <= ship_x_l + ship_SIZE + ship_SIZE - 1;
-- ship_y_b <= ship_y_t + ship_SIZE + ship_SIZE - 1;
-- sq_ship_on <=
-- '1' WHEN (ship_x_l <= pix_x) AND (pix_x <= ship_x_r) AND
-- (ship_y_t <= pix_y) AND (pix_y <= ship_y_b) ELSE
-- '0';
-- -- round ship
-- rom_addr_ship <= pix_y(4 DOWNTO 1) - ship_y_t(4 DOWNTO 1);
-- rom_col_ship <= pix_x(4 DOWNTO 1) - ship_x_l(4 DOWNTO 1);
-- rom_data_ship <= ship_ROM_2l(to_integer(rom_addr_ship)) WHEN ship_lives_reg = "10" ELSE
-- ship_ROM_1l(to_integer(rom_addr_ship)) WHEN ship_lives_reg = "01" ELSE
-- ship_ROM(to_integer(rom_addr_ship));
-- rom_bit_ship <= rom_data_ship(to_integer(NOT rom_col_ship));
-- rd_ship_on <=
-- '1' WHEN (sq_ship_on = '1') AND (rom_bit_ship = '1') ELSE
-- '0';
-- ship_rgb <= "111"; --white
-- ship_rgb_2 <= "110"; -- yellow
-- ship_rgb_1 <= "100";-- red
-- -- new ship position
-- PROCESS (refr_tick, gra_still, ship_y_reg, ship_x_reg, keyboard_code, ship_got_hit)
-- BEGIN
-- ship_y_next <= ship_y_reg;
-- ship_x_next <= ship_x_reg;
-- IF gra_still = '1' OR ship_got_hit = '1' THEN --initial position of ship
-- -- ship_x_next <= to_unsigned((WALL2_X_L + WALL1_X_R)/2, 10);
-- -- ship_y_next <= to_unsigned((WALL_Y_B + WALL_Y_T2)/2, 10);
-- ship_x_next <= to_unsigned((MAX_X)/2, 10);
-- ship_y_next <= to_unsigned((MAX_Y/2) + 30, 10);
-- ELSIF refr_tick = '1' THEN
-- IF (keyboard_code = down_arrow) THEN
-- IF (ship_y_reg > MAX_Y - 20) THEN
-- ship_y_next <= to_unsigned(20, 10);
-- ELSE
-- ship_y_next <= ship_y_reg + ship_V; -- move down
-- --projectile new initial position
-- -- proj1_y_initial<= to_unsigned(to_integer(ship_y_reg + ship_V) - 16 - PROJ_SIZE, 10);
-- END IF;
-- ELSIF (keyboard_code = up_arrow) THEN
-- --projectile new initial position
-- -- proj1_y_initial<= to_unsigned(to_integer(ship_y_reg + ship_V) - 16 - PROJ_SIZE, 10);
-- IF (ship_y_reg < 20) THEN
-- ship_y_next <= to_unsigned(MAX_Y - 20, 10);
-- ELSE
-- ship_y_next <= ship_y_reg - ship_V; -- move up
-- END IF;
-- ELSIF (keyboard_code = right_arrow) THEN
-- IF (ship_x_reg > MAX_X - 20) THEN
-- ship_x_next <= to_unsigned(20, 10);
-- ELSE
-- ship_x_next <= ship_x_reg + ship_V; -- move right
-- END IF;
-- ELSIF (keyboard_code = left_arrow) THEN
-- IF (ship_x_reg < 20) THEN
-- ship_x_next <= to_unsigned(MAX_X - 20, 10);
-- ELSE
-- ship_x_next <= ship_x_reg - ship_V; -- move left
-- END IF;
-- END IF;
-- END IF;
-- END PROCESS;
----------------------------------------------
--- Alien 1
----------------------------------------------
-- Square Alien
alien_x_l <= alien_x_reg;
alien_y_t <= alien_y_reg;
alien_x_r <= alien_x_l + ALIEN_SIZE + ALIEN_SIZE - 1;
alien_y_b <= alien_y_t + ALIEN_SIZE + ALIEN_SIZE - 1;
sq_alien_1_on <=
'1' WHEN (alien_x_l <= pix_x) AND (pix_x <= alien_x_r) AND
(alien_y_t <= pix_y) AND (pix_y <= alien_y_b) ELSE
'0';
-- Round Alien
rom_addr_alien <= pix_y(3 DOWNTO 1) - alien_y_t(3 DOWNTO 1);
rom_col_alien <= pix_x(3 DOWNTO 1) - alien_x_l(3 DOWNTO 1);
rom_data_alien <= ALIEN_ROM(to_integer(rom_addr_alien));
rom_bit_alien <= rom_data_alien(to_integer(NOT rom_col_alien));
rd_alien_1_on <=
'1' WHEN (sq_alien_1_on = '1') AND (rom_bit_alien = '1') AND (alien_alive_reg = '1') AND (gamemode2 = '0') ELSE
'0';
alien_rgb <= "010"; -- green
-- new alien position
alien_x_next <=
to_unsigned(50, 10) WHEN (gra_still = '1' OR alien_alive_reg = '0') ELSE
alien_x_reg + alien_vx_reg WHEN refr_tick = '1' ELSE
alien_x_reg;
alien_y_next <=
to_unsigned((MAX_Y)/2 - 50, 10) WHEN (gra_still = '1' OR alien_alive_reg = '0') ELSE
alien_y_reg WHEN refr_tick = '1' ELSE
alien_y_reg;
-- alien_alive <= alien_alive_reg;
-- New alien velocity
-- With new hit, p1_damage signals
PROCESS (alien_vx_reg, alien_x_l, alien_x_r
, gra_still, alien_alive_reg, alien_hits_counter_reg)
BEGIN
alien_vx_next <= alien_vx_reg;
-- alien_vy_next <= alien_vy_reg;
IF gra_still = '1' THEN --initial velocity
alien_vx_next <= ALIEN_V_N - alien_hits_counter_reg;
-- alien_vy_next <= ALIEN_V_P;
-- alien_vy_next <= to_unsigned(0, 10);
ELSIF (alien_alive_reg = '1') THEN
IF (alien_x_l < 1) THEN -- reach left border
alien_vx_next <= ALIEN_V_P + alien_hits_counter_reg;
ELSIF (alien_x_r > MAX_X) THEN -- reach right border
-- p1_damage <= '1'; -- a p1_damage
alien_vx_next <= ALIEN_V_N - alien_hits_counter_reg;
END IF;
END IF;
END PROCESS;