Skip to content

Commit 5abc208

Browse files
examples.maskedsprites
1 parent 7042d42 commit 5abc208

1 file changed

Lines changed: 161 additions & 0 deletions

File tree

examples/maskedsprites.bas

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
' ----------------------------------------------------------------
2+
' This file is released under the MIT License
3+
'
4+
' Copyright (C) 2026 Conrado Badenas <conbamen@gmail.com>
5+
'
6+
' Example for
7+
' Print Masked (AND+OR) Sprites, version 2026.03.06
8+
' ----------------------------------------------------------------
9+
10+
#include <cb/maskedsprites.bas>
11+
12+
#include <random.bas>
13+
14+
CONST NUMMAXSPRITES as UByte = 10
15+
CONST NUMSPRITES as UByte = 7
16+
if NUMSPRITES>NUMMAXSPRITES then stop
17+
18+
dim i,temp as Integer
19+
dim pointx1,pointx2,pointy1,pointy2 as Integer 'for subtractions
20+
dim x0(0 to NUMSPRITES-1) as UByte
21+
dim y0(0 to NUMSPRITES-1) as UByte
22+
dim x1(0 to NUMSPRITES-1) as UByte
23+
dim y1(0 to NUMSPRITES-1) as UByte
24+
25+
for i=0 to NUMSPRITES-1
26+
y0(i)=255:y1(i)=255:x1(i)=randomLimit(240)
27+
next i:x1(0)=120
28+
29+
SetVisibleScreen(5):if GetVisibleScreen()<>5 then STOP
30+
paper 1:ink 7:border 0:cls
31+
32+
for i=0 to 127
33+
pointx1=randomLimit(255):pointy1=randomLimit(191)
34+
pointx2=randomLimit(255):pointy2=randomLimit(191)
35+
plot pointx1,pointy1:draw pointx2-pointx1,pointy2-pointy1
36+
next i
37+
38+
CopyScreen5ToScreen7()
39+
'print at 11,8;"Esto es Screen5"
40+
SetDrawingScreen7() 'Bank7 is set at $c000
41+
'print at 13,8;"Esto es Screen7"
42+
SetDrawingScreen5() 'Bank7 is still set at $c000
43+
'print at 15,8;"Esto es Screen5"
44+
45+
ASM
46+
xor a ; 4 Ts reseteamos el contador
47+
ld (23672),a ; 13 Ts de FRAMES a 0
48+
END ASM
49+
50+
' Empezamos con VisibleScreen = DrawingScreen = 5
51+
bucle:
52+
53+
' La nueva VisibleScreen está lista para que la ULA la saque por la tele
54+
' Pero vamos a esperar al principio de un frame para que no haya tearing
55+
' El 2 de luego significa que obtendremos 25 FPS como máximo
56+
ASM
57+
ld hl,23672
58+
wait:
59+
ld a,(hl) ; A = contador de FRAMES
60+
cp 2 ; 25 FPS como máximo
61+
jr c,wait ; repetimos si A < 2
62+
xor a
63+
ld (hl),a ; reseteamos el contador de FRAMES a 0
64+
END ASM
65+
66+
ToggleVisibleScreen()
67+
' Ahora se puede modificar la DrawingScreen porque no está Visible
68+
69+
' Restauramos fondo en x0,y0 si está guardado en MaskedSpritesBackground
70+
for i=0 to NUMSPRITES-1
71+
if y0(i)<>255 then RestoreBackground(x0(i),y0(i),MaskedSpritesBackground(i))
72+
next i
73+
74+
' Actualizamos x0,y0 y calculamos nuevos x1,y1
75+
for i=1 to NUMSPRITES-1
76+
temp=x1(i): x0(i)=temp
77+
temp=temp-1
78+
if temp<0 then temp=240
79+
x1(i)=temp
80+
temp=y1(i): y0(i)=temp
81+
if temp=255 then temp=randomLimit(176)
82+
if randomLimit(3)=0 then temp=temp+randomLimit(2)-1
83+
if temp<0 then temp=0
84+
if temp>176 then temp=176
85+
y1(i)=temp
86+
next i
87+
88+
'Código especial para el prota
89+
temp=x1(0): x0(0)=temp
90+
temp=temp+1 -2*(in($dffe) bAND 1) +2*((in($dffe)>>1) bAND 1) '-noP+noO
91+
if temp<0 then temp=240
92+
if temp>240 then temp=0
93+
x1(0)=temp
94+
temp=y1(0): y0(0)=temp
95+
if temp=255 then temp=randomLimit(176)
96+
temp=temp -(in($fdfe) bAND 1) +(in($fbfe) bAND 1) '-noA+noQ
97+
if temp<0 then temp=0
98+
if temp>176 then temp=176
99+
y1(0)=temp
100+
101+
' Guardamos fondo en MaskedSpritesBackground y dibujamos sprites en x,y
102+
for i=NUMSPRITES-1 to 1 step -1
103+
SaveBackgroundAndDrawSprite(x1(i),y1(i),MaskedSpritesBackground(i),@enemigo0)
104+
next i
105+
SaveBackgroundAndDrawSprite(x1(0),y1(0),MaskedSpritesBackground(0),@prota0)
106+
107+
' Cambiamos el Set de Backgrounds para la siguiente iteración
108+
ChangeMaskedSpritesBackgroundSet()
109+
110+
' Hemos terminado de dibujar
111+
' DrawingScreen actual está lista para ser mostrada ahora mismo
112+
' Cambiamos de DrawingScreen para el siguiente ciclo de dibujo
113+
ToggleDrawingScreen()
114+
115+
' Ahora VisibleScreen = DrawingScreen y
116+
' lo que se dibuje se verá mientras se dibuja
117+
118+
goto bucle
119+
120+
stop
121+
122+
prota0:
123+
ASM
124+
defb %11000000,%00000000,%00001111,%00000000;1
125+
defb %10000000,%00011111,%00000000,%11100000;2
126+
defb %00000000,%00100000,%00000000,%00111110;3
127+
defb %00000000,%01001110,%00000000,%11111000;4
128+
defb %00000000,%01011001,%00000001,%00001100;5
129+
defb %00000000,%01011010,%00000000,%00010100;6
130+
defb %00000000,%00000011,%00000000,%11100010;7
131+
defb %00000000,%01111100,%00000000,%00100010;8
132+
defb %00000000,%01111100,%00000000,%00100010;8
133+
defb %00000000,%00000011,%00000000,%11100010;7
134+
defb %00000000,%01011010,%00000000,%00010100;6
135+
defb %00000000,%01011001,%00000001,%00001100;5
136+
defb %00000000,%01001110,%00000000,%11111000;4
137+
defb %00000000,%00100000,%00000000,%00111110;3
138+
defb %10000000,%00011111,%00000000,%11100000;2
139+
defb %11000000,%00000000,%00001111,%00000000;1
140+
END ASM
141+
142+
enemigo0:
143+
ASM
144+
defb %00000011,%00000000,%11000000,%00000000;1
145+
defb %00000011,%01111000,%11000000,%00011110;2
146+
defb %00000011,%01000000,%11000000,%00010000;3
147+
defb %00000001,%01010000,%10000000,%00010100;4
148+
defb %00000000,%01001000,%00000000,%00100010;5
149+
defb %00000000,%00000010,%00000000,%01110000;6
150+
defb %11100000,%00000111,%00000111,%11100000;7
151+
defb %11110000,%00000010,%00001111,%01000000;8
152+
defb %11110000,%00000010,%00001111,%01000000;8
153+
defb %11100000,%00000111,%00000111,%11100000;7
154+
defb %00000000,%00001110,%00000000,%01000000;6'
155+
defb %00000000,%01110100,%00000000,%00011110;5'
156+
defb %00000001,%01000000,%10000000,%00010000;4'
157+
defb %00000011,%01010000,%11000000,%00010100;3'
158+
defb %00000011,%01001000,%11000000,%00010010;2'
159+
defb %00000011,%00000000,%11000000,%00000000;1
160+
END ASM
161+

0 commit comments

Comments
 (0)