-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_07_sprites4.bas
124 lines (124 loc) · 6.27 KB
/
demo_07_sprites4.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
10 REM ******************************
20 REM * AGON LIGHT 2 *
30 REM * DEMO 07 *
40 REM * BBC BASIC MODE 8 *
50 REM * SPRITES PART 4 *
60 REM * *
70 REM * BY LOVEJOY777 *
80 REM ******************************
90 REM USING VDU DOCUMENTAITION FROM:
100 REM http://agonconsole8.github.io/agon-docs/VDP.html.
110 :
120 MB%=&40000 : REM MEMORY BANK &40000.
130 DIM graphics 1024 : REM ARRAY FOR BITMAP DATA, 16*16*4(r,g,b,a) = 1024.
140 X% = 152 : Y% = 112 : REM VARS FOR THE SPRITE POSITION (start at center of screen - 8 pixels).
150 VDU 23,27,16 : REM CLEAR ALL GRAPHICS DATA (same as CLG).
160 :
200 REM ***** LOAD BITMAPS TO MEMORY *****.
210 REM THE PATHS BELOW NEED TO POINT TO YOUR .rgb IMAGE FILES ON YOUR SDCARD.
220 PROC_LOAD_BITMAP("/B/Images/bombr1.rgb",0,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
230 PROC_LOAD_BITMAP("/B/Images/bombr2.rgb",1,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
240 PROC_LOAD_BITMAP("/B/Images/bombl1.rgb",2,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
250 PROC_LOAD_BITMAP("/B/Images/bombl2.rgb",3,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
260 PROC_LOAD_BITMAP("/B/Images/bombud1.rgb",4,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
270 PROC_LOAD_BITMAP("/B/Images/bombud2.rgb",5,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
280 MODE 8 : REM SET SCREEN MODE.
290 VDU 17,128+7 : REM SET BG COLOUR TO GRAY.
300 CLS : REM CLEAR THE SCREEN.
310 VDU 23,1,0 : REM DISABLE CURSOR.
320 PROC_SETUP_SPRITE1 : REM SETUP SPRITE 1, RIGHT.
330 PROC_SETUP_SPRITE2 : REM SETUP SPRITE 2, LEFT.
340 PROC_SETUP_SPRITE3 : REM SETUP SPRITE 3, UP/DOWN.
350 :
1000 REM ***** GAME LOOP *****.
1030 :
1110 A%=INKEY(0) : REM GET KEYBOARD INPUT FROM PLAYER.
1120 IF A%=21 THEN X%=X%+2 : PROC_MOVE_SPRITE1 : REM MOVE SPRITE RIGHT.
1130 IF A%=8 THEN X%=X%-2 : PROC_MOVE_SPRITE2 : REM MOVE SPRITE LEFT.
1140 IF A%=10 THEN Y%=Y%+2 : PROC_MOVE_SPRITE3 : REM MOVE SPRITE UP.
1150 IF A%=11 THEN Y%=Y%-2 : PROC_MOVE_SPRITE3 : REM MOVE SPRITE DOWN.
1170 :
1200 REM KEEP THE SPRITE WITHIN THE SCREEN BOUNDS (320x240 for mode 8).
1210 IF X%>304 THEN X%=304 : REM SCREEN WIDTH - 16 PIXELS.
1220 IF X%<0 THEN X%=0
1230 IF Y%>224 THEN Y%=224 : REM SCREEN HEIGHT - 16 PIXELS.
1240 IF Y%<0 THEN Y%=0
1250 :
1300 GOTO 1000 : REM **** END GAME LOOP *****.
1310 :
1500 REM ***** SETUP SPRITE 1 PLAYER RIGHT *****.
1510 DEF PROC_SETUP_SPRITE1
1520 VDU 23,27,4,0 : REM SELECT SPRITE 0.
1530 VDU 23,27,5 : REM CLEAR FRAMES FOR CURRENT SPRITE.
1540 VDU 23,27,6,0 : REM ADD BITMAP 0 AS FRAME 1 OF SPRITE 1.
1550 VDU 23,27,6,1 : REM ADD BITMAP 1 AS FRAME 2 OF SPRITE 1.
1560 VDU 23,27,11 : REM SHOW THE CURRENT SPRITE 1 ON STARTUP.
1570 VDU 23,27,7,1 : REM ACTIVATE SPRITE 1.
1580 VDU 23,27,13, X%;Y%; : REM MOVE CURRENT SPRITE TO POS X,Y (CENTER ON START UP).
1590 VDU 23,27,15 : REM UPDATE THE SPRITES IN THE GPU.
1595 ENDPROC : REM END PROC_SETUP_SPRITE1.
1600 :
1610 REM ***** SETUP SPRITE 2 PLAYER LEFT *****.
1620 DEF PROC_SETUP_SPRITE2
1630 VDU 23,27,4,1 : REM SELECT SPRITE 1.
1640 VDU 23,27,5 : REM CLEAR FRAMES FOR CURRENT SPRITE.
1650 VDU 23,27,6,2 : REM ADD BITMAP 2 AS FRAME 1 OF SPRITE 2.
1660 VDU 23,27,6,3 : REM ADD BITMAP 3 AS FRAME 2 OF SPRITE 2.
1670 VDU 23,27,7,2 : REM ACTIVATE SPRITE 2.
1680 ENDPROC : REM END PROC_SETUP_SPRITE2.
1690 :
1700 REM ***** SETUP SPRITE 3 PLAYER UP/DOWN *****.
1710 DEF PROC_SETUP_SPRITE3
1720 VDU 23,27,4,2 : REM SELECT SPRITE 2.
1730 VDU 23,27,5 : REM CLEAR FRAMES FOR CURRENT SPRITE.
1740 VDU 23,27,6,4 : REM ADD BITMAP 4 AS FRAME 1 OF SPRITE 3.
1750 VDU 23,27,6,5 : REM ADD BITMAP 5 AS FRAME 2 OF SPRITE 3.
1760 VDU 23,27,7,3 : REM ACTIVATE SPRITE 3.
1770 ENDPROC : REM END PROC_SETUP_SPRITE2.
1780 :
1820 DEF PROC_MOVE_SPRITE1 : REM ***** MOVE PLAYER RIGHT *****.
1830 VDU 23,27,12 : REM HIDE PREVIOUS SPRITE.
1840 VDU 23,27,4,0 : REM SELECT SPRITE 0.
1850 VDU 23,27,11 : REM SHOW THE CURRENT SPRITE 1.
1860 VDU 23,27,8 : REM NEXT FRAME.
1870 VDU 23,27,13, X%;Y%; : REM MOVE CURRENT SPRITE TO POS X,Y.
1880 VDU 23,27,15 : REM UPDATE THE SPRITES IN THE GPU.
1890 ENDPROC : REM END PROC_MOVE_SPRITE1.
1900 :
1910 DEF PROC_MOVE_SPRITE2 : REM ***** MOVE PLAYER LEFT *****.
1920 VDU 23,27,12 : REM HIDE PREVIOUS SPRITE.
1930 VDU 23,27,4,1 : REM SELECT SPRITE 1
1940 VDU 23,27,11 : REM SHOW THE CURRENT SPRITE 2.
1950 VDU 23,27,8 : REM NEXT FRAME.
1960 VDU 23,27,13, X%;Y%; : REM MOVE CURRENT SPRITE TO POS X,Y.
1970 VDU 23,27,15 : REM UPDATE THE SPRITES IN THE GPU.
1980 ENDPROC : REM END PROC_MOVE_SPRITE2.
1990 :
2000 DEF PROC_MOVE_SPRITE3 : REM ***** MOVE PLAYER UP OR DOWN *****.
2010 VDU 23,27,12 : REM HIDE PREVIOUS SPRITE.
2020 VDU 23,27,4,2 : REM SELECT SPRITE 2
2030 VDU 23,27,11 : REM SHOW THE CURRENT SPRITE 3.
2040 VDU 23,27,8 : REM NEXT FRAME.
2050 VDU 23,27,13, X%;Y%; : REM MOVE CURRENT SPRITE TO POS X,Y.
2060 VDU 23,27,15 : REM UPDATE THE SPRITES IN THE GPU.
2070 ENDPROC : REM END PROC_MOVE_SPRITE3.
2100 :
2400 REM ***** LOAD BITMAP IMAGE INTO VDP RAM *****.
2410 REM F$ = FILENAME/PATH OF BITMAP FROM LINES 220 TO 270.
2420 REM N% - BITMAP NUMBER.
2430 REM W% - BITMAP WIDTH.
2440 REM H% - BITMAP HEIGHT.
2450 :
2500 DEF PROC_LOAD_BITMAP(F$,N%,W%,H%) : REM ***** PROC_LOAD_BITMAP *****.
2510 OSCLI("LOAD " + F$ + " " + STR$(MB%+graphics)) : REM OPERATING SYSTEM CLI COMMAND.
2520 VDU 23,27,0,N% : REM SELECT BITMAP n (equating to buffer ID numbered 64000+n).
2530 VDU 23,27,1,W%;H%; : REM LOAD COLOUR BITMAP DATA INTO CURRENT SPRITE.
2540 FOR I%=0 TO (W%*H%*3)-1 STEP 3 : REM LOOP 16x16x3 EACH PIXEL R,G,B, -1 (because we start the loop at 0).
2550 r% = ?(graphics+I%+0) : REM GET RED DATA WITH QUERY & ASSIGN TO r%.
2560 g% = ?(graphics+I%+1) : REM GET GREEN DATA WITH QUERY & ASSIGN TO g%.
2570 b% = ?(graphics+I%+2) : REM GET BLUE DATA WITH QUERY & ASSIGN TO b%.
2580 a% = r% OR g% OR b% : REM GET ALPHA DEPENDING ON (EITHER 255(colour/on) or 000(black/off)) & ASSIGN TO a%.
2590 VDU r%, g%, b%, a% : REM PRINT red,green,blue,alpha VALUES TO THE VDP.
2600 NEXT : REM LOOP NEXT PIXEL.
2610 REM END VDU 23,27,1 (line 2530).
2620 ENDPROC : REM END PROC_LOAD_BITMAP.