-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_06_sprites3.bas
102 lines (102 loc) · 4.94 KB
/
demo_06_sprites3.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
10 REM ******************************
20 REM * AGON LIGHT 2 *
30 REM * DEMO 06 *
40 REM * BBC BASIC MODE 8 *
50 REM * SPRITES PART 3 *
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 PIXELS ?.
140 X% = 152 : Y% = 112 : REM VARS FOR THE SPRITE POSITION (start at center of screen - 8 pixels).
147 VDU 23,27,16 : REM CLEAR ALL SPRITE DATA.
148 FCN% = 1 : REM VAR FOR ANIMATION.
150 :
160 REM LOAD BITMAPS TO MEMORY.
170 REM THE PATHS BELOW NEED TO POINT TO YOUR .rgb IMAGE FILES ON YOUR SDCARD.
180 PROC_LOAD_BITMAP("/B/Images/bombr1.rgb",0,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
190 PROC_LOAD_BITMAP("/B/Images/bombr2.rgb",1,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
191 PROC_LOAD_BITMAP("/B/Images/bombl1.rgb",2,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
192 PROC_LOAD_BITMAP("/B/Images/bombl2.rgb",3,16,16) : REM CALL PROC_LOAD_BITMAP (n,w,h).
200 MODE 8 : REM SET SCREEN MODE.
210 VDU 17,128+7 : REM SET BG COLOUR TO GRAY.
220 CLS : REM CLEAR THE SCREEN.
230 VDU 23,1,0 : REM DISABLE CURSOR.
240 PROC_SETUP_SPRITE1 : REM SETUP SPRITE 1, PLAYER RIGHT.
250 PROC_SETUP_SPRITE2 : REM SETUP SPRITE 2, PLAYER LEFT.
280 :
1000 REM GAME LOOP.
1020 IF FCN%=1 THEN FCN%=2 ELSE FCN%=1 : REM EACH LOOP CHANGE FCN% BETWEEN 1 & 2 FOR NEXT OR PREVIOUS FRAME.
1110 A%=INKEY(0) : REM GET KEYBOARD INPUT FROM PLAYER.
1120 IF A%=21 THEN X%=X%+2 : PROC_MOVE_SPRITE1 : REM SET AND MOVE SPRITE RIGHT.
1130 IF A%=8 THEN X%=X%-2 : PROC_MOVE_SPRITE2 : REM SET AND MOVE SPRITE LEFT.
1140 IF A%=10 THEN Y%=Y%+2 : PROC_MOVE_SPRITE1 : REM SET AND MOVE SPRITE UP.
1150 IF A%=11 THEN Y%=Y%-2 : PROC_MOVE_SPRITE2 : REM SET AND 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 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 2 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,15 : REM UPDATE THE SPRITES IN THE GPU.
1590 ENDPROC : REM END PROC_SETUP_SPRITE1.
1600 :
1700 REM SPRITE 2 PLAYER LEFT.
1710 DEF PROC_SETUP_SPRITE2
1720 VDU 23,27,4,1 : REM SELECT SPRITE 1.
1730 VDU 23,27,5 : REM CLEAR FRAMES FOR CURRENT SPRITE.
1740 VDU 23,27,6,2 : REM ADD BITMAP 2 AS FRAME 1 OF SPRITE 2.
1750 VDU 23,27,6,3 : REM ADD BITMAP 3 AS FRAME 2 OF SPRITE 2.
1760 VDU 23,27,7,2 : REM ACTIVATE SPRITE 2.
1770 ENDPROC : REM END PROC_SETUP_SPRITE2.
1780 :
1820 DEF PROC_MOVE_SPRITE1
1830 VDU 23,27,12 : REM HIDE SPRITE 2.
1840 VDU 23,27,4,0 : REM SELECT SPRITE 0.
1850 VDU 23,27,11 : REM SHOW THE CURRENT SPRITE 1.
1860 IF FCN%=1 THEN VDU 23,27,8 : IF FCN%=2 THEN VDU 23,27,9 : REM ANIMATION FRAMES.
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
1920 VDU 23,27,12 : REM HIDE SPRITE 1.
1930 VDU 23,27,4,1 : REM SELECT SPRITE 1
1940 VDU 23,27,11 : REM SHOW THE CURRENT SPRITE 2.
1950 IF FCN%=1 THEN VDU 23,27,8 : IF FCN%=2 THEN VDU 23,27,9 : REM ANIMATION FRAMES.
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 :
2400 REM LOAD BITMAP IMAGE INTO VDP RAM.
2410 REM F$ = FILENAME/PATH OF BITMAP FROM LINES 180 TO 192.
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 SPRITE 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 FOR LINE END.
2550 r% = ?(graphics+I%+0) : REM RED DATA.
2560 g% = ?(graphics+I%+1) : REM GREEN DATA.
2570 b% = ?(graphics+I%+2) : REM BLUE DATA.
2580 a% = r% OR g% OR b% : REM alpha ?.
2590 VDU r%, g%, b%, a% : REM unsure ?.
2600 NEXT : REM LOOP NEXT PIXEL.
2610 ENDPROC : REM END PROC_LOAD_BITMAP.