content:retrocomputing:sprite
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
content:retrocomputing:sprite [2022/08/16 18:41] – [Definizione] admin | content:retrocomputing:sprite [2023/08/15 14:54] (current) – [Spostamento e animazione] admin | ||
---|---|---|---|
Line 81: | Line 81: | ||
**https:// | **https:// | ||
+ | Aiuta soprattutto quando si tratta di disegnare sprite multicolore. Le righe sottostanti riempiono le locazioni con i dati degli sprite (ottenuti dal tool sopra): | ||
+ | |||
+ | < | ||
+ | 70 FOR X=12800 TO 12800+127: READ Y: POKE X,Y: NEXT X: REM SPRITE DATA | ||
+ | |||
+ | 1000 :: rem pac_0 / multicolor / color: 3 | ||
+ | 1010 data 0, | ||
+ | 1020 data 170, | ||
+ | 1030 data 126, | ||
+ | 1040 data 170, | ||
+ | 1050 :: rem pac_1 / multicolor / color: 3 | ||
+ | 1060 data 0, | ||
+ | 1070 data 170, | ||
+ | 1080 data 126, | ||
+ | 1090 data 170, | ||
+ | </ | ||
+ | |||
+ | Le **definizioni degli sprite** sono due animazioni di un fantasma di PacMan; entrambe sono associate a due sprite. Si capisce quindi che **ogni sprite può avere più definizioni/ | ||
+ | |||
+ | < | ||
+ | POKE 2040,200 | ||
+ | ... | ||
+ | POKE 2040,201 | ||
+ | </ | ||
+ | |||
+ | Qui lo stesso sprite (un fantasma) ha prima una definizione/ | ||
+ | |||
+ | In fondo alla pagina c'è il sorgente completo, che come risultato dà due fantasmini di PacMan che si spostano da sinistra a destra: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | < | ||
+ | 10 print chr$(147) | ||
+ | 20 print "w commodore!" | ||
+ | |||
+ | 40 poke 53285,1: rem multicolor 1 x tutti sprite | ||
+ | 50 poke 53286,0: rem multicolor 2 x tutti sprite | ||
+ | 60 poke 53269,255 : rem attiva tutti e 8 sprite | ||
+ | 62 poke 53276, 3: rem multicolor sprite 0 e 1 | ||
+ | 64 poke 53277, 0: rem non allargare tutti sprite | ||
+ | 66 poke 53271, 0: rem non alzare tutti sprite | ||
+ | 67 poke 53287,2: rem color sprite 0 | ||
+ | 68 poke 53288,3: rem color sprite 1 | ||
+ | 70 for x=12800 to 12800+127: read y: poke x,y: next x: rem sprite data | ||
+ | |||
+ | 85 for x=24 to 255 | ||
+ | 90 :: rem pac_0 | ||
+ | 100 poke 2040,200: rem pointer sprite 0 | ||
+ | 110 poke 53248, x: rem x pos sprite 0 | ||
+ | 120 poke 53249, 120: rem y pos sprite 0 | ||
+ | 130 poke 2040,201: rem pointer sprite 0 | ||
+ | 140 poke 53248, x: rem x pos sprite 0 | ||
+ | 150 poke 53249, 120: rem y pos sprite 0 | ||
+ | |||
+ | 160 :: rem pac_1 | ||
+ | 180 poke 2041,200: rem pointer sprite 1 | ||
+ | 190 poke 53250, x: rem x pos sprite 1 | ||
+ | 200 poke 53251, 150: rem y pos sprite 1 | ||
+ | 210 poke 2041,201: rem pointer sprite 1 | ||
+ | 220 poke 53250, x: rem x pos sprite 1 | ||
+ | 230 poke 53251, 150: rem y pos sprite 1 | ||
+ | |||
+ | 240 next x | ||
+ | |||
+ | 1000 :: rem pac_0 / multicolor / color: 3 | ||
+ | 1010 data 0, | ||
+ | 1020 data 170, | ||
+ | 1030 data 126, | ||
+ | 1040 data 170, | ||
+ | 1050 :: rem pac_1 / multicolor / color: 3 | ||
+ | 1060 data 0, | ||
+ | 1070 data 170, | ||
+ | 1080 data 126, | ||
+ | 1090 data 170, | ||
+ | </ | ||
+ | |||
+ | ===== Sprite animation e collision ===== | ||
+ | |||
+ | Il seguente esempio è tratto dal libro //Commodore 64 Graphics and Sound//; è diverso rispetto al listato sopra, perché non ridefinisce gli sprite con un altro disegno, ma visualizza alternativamente due sprite, con due definizioni diverse per creare l' | ||
+ | |||
+ | {{: | ||
+ | ==== Definizione sprite ==== | ||
+ | |||
+ | Vengono **definiti i dati di 5 sprite**, usando alcune locazioni di memoria a partire da (13*64=)832. Questa area è in realtà il //cassette buffer//, per cui se si usa il registratore, | ||
+ | |||
+ | < | ||
+ | 130 poke2040, | ||
+ | 140 poke2042, | ||
+ | 150 poke2044,15 | ||
+ | </ | ||
+ | |||
+ | ==== Spostamento e animazione ==== | ||
+ | |||
+ | Si tratta quindi di 4 sprite ' | ||
+ | |||
+ | < | ||
+ | 255 rem move sprites 0 and 2 | ||
+ | 260 pokevc, | ||
+ | ... | ||
+ | 285 rem display sprites 0 and 2 | ||
+ | 290 pokevc+21,5 | ||
+ | 300 for t=1 to 200:next | ||
+ | </ | ||
+ | |||
+ | I registri nel VIC-II per le **posizioni X degli sprite 0-3** (vc=53248, vc+2=53250, vc+4=53252 e vc+6=53254): | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Il registro ' | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Poi vengono visualizzati gli sprite 1 e 3 (2041 e 2043) con un' | ||
+ | |||
+ | < | ||
+ | 305 rem move sprites 1 and 3 | ||
+ | 310 pokevc+2, | ||
+ | ... | ||
+ | 335 rem display sprites 1 and 3 | ||
+ | 340 pokevc+21, | ||
+ | 350 for t=1 to 200:next | ||
+ | </ | ||
+ | |||
+ | L' | ||
+ | |||
+ | < | ||
+ | 100 rem sprite movement and collisions | ||
+ | 105 rem clear screen | ||
+ | 110 print chr$(147) | ||
+ | 115 rem vic chip start address | ||
+ | 120 vc=53248 | ||
+ | 125 rem set sprite pointers | ||
+ | 130 poke2040, | ||
+ | 140 poke2042, | ||
+ | 150 poke2044,15 | ||
+ | 155 rem read sprite data | ||
+ | 160 for n=0 to 191 | ||
+ | 170 read a: | ||
+ | 180 next | ||
+ | 185 rem set y positions | ||
+ | 190 poke vc+1, | ||
+ | 200 poke vc+5, | ||
+ | 205 rem set sprite colors | ||
+ | 210 pokevc+39, | ||
+ | 220 pokevc+41, | ||
+ | 230 pokevc+43, | ||
+ | 240 for n=1 to 10 | ||
+ | 241 print chr$(147) | ||
+ | 242 print" | ||
+ | 243 print" | ||
+ | 244 print " | ||
+ | 250 for x=0 to 130 step 8 | ||
+ | 255 rem move sprites 0 and 2 | ||
+ | 260 pokevc, | ||
+ | 261 print " | ||
+ | 262 print " | ||
+ | 265 rem check for collision | ||
+ | 270 cd=peek(vc+30) | ||
+ | 280 if cd<>0 then 370 | ||
+ | 285 rem display sprites 0 and 2 | ||
+ | 290 pokevc+21,5 | ||
+ | 300 for t=1 to1000:next | ||
+ | 305 rem move sprites 1 and 3 | ||
+ | 306 print " | ||
+ | 307 print " | ||
+ | 310 pokevc+2, | ||
+ | 315 rem check for collision | ||
+ | 320 cd=peek(vc+30) | ||
+ | 330 if cd<>0 then 370 | ||
+ | 335 rem display sprites 1 and 3 | ||
+ | 340 pokevc+21, | ||
+ | 350 for t=1 to1000:next | ||
+ | 360 next x | ||
+ | 365 rem display explosion sprite 4 | ||
+ | 370 pokevc+8, | ||
+ | 380 pokevc+23, | ||
+ | 390 pokevc+21, | ||
+ | 400 for t=1 to 1000:next | ||
+ | 410 pokevc+21, | ||
+ | 420 for t=1 to 500:next | ||
+ | 430 next n | ||
+ | 440 end | ||
+ | 400 for t=1 to 1000:next | ||
+ | 410 pokevc+21, | ||
+ | 420 for t=1 to 500:next | ||
+ | 430 next n | ||
+ | 440 end | ||
+ | 795 rem sprite 0 and 2 data | ||
+ | 800 data 0, | ||
+ | 810 data 15, | ||
+ | 820 data 63, | ||
+ | 830 data 63, | ||
+ | 840 data 31, | ||
+ | 850 data 3, | ||
+ | 860 data 12, | ||
+ | 870 data 48, | ||
+ | 880 data 192, | ||
+ | 890 data 0,0,0,0,0,0 | ||
+ | 900 data 0,0,0,0 | ||
+ | 905 rem sprite 1 and 3 data | ||
+ | 910 data 0, | ||
+ | 920 data 15, | ||
+ | 930 data 63, | ||
+ | 940 data 63, | ||
+ | 950 data 31, | ||
+ | 960 data 3, | ||
+ | 970 data 12, | ||
+ | 980 data 12, | ||
+ | 990 data 3, | ||
+ | 1000 data 0,0,0,0,0,0 | ||
+ | 1010 data 0,0,0,0 | ||
+ | 1015 rem sprite 4 data | ||
+ | 1020 data 96, | ||
+ | 1030 data 24, | ||
+ | 1040 data 6, | ||
+ | 1050 data 1, | ||
+ | 1060 data 0, | ||
+ | 1070 data 0, | ||
+ | 1080 data 1, | ||
+ | 1090 data 6, | ||
+ | 1100 data 24, | ||
+ | 1110 data 96, | ||
+ | 1120 data 0,0,0,0 | ||
+ | </ | ||
content/retrocomputing/sprite.1660668061.txt.gz · Last modified: 2022/08/16 18:41 by admin