Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
struggle on using/implementing sprite libraries
#1
since a long time i was thinking how simple or possible would be using sprite engines/libraries on zxbasic-compiler (just like those used on z88dk and so on)

so i started to try this (very glitchy and inefficient, as the code shows... Big Grin  )

(wsad or cursors for moving)

Code:
ink 1
border 1:ink 5:bright 1: paper 1: cls

sub putudgsprite(txp1 as uinteger,typ1 as uinteger,tad1 as uinteger)
  poke uinteger $5C7B,tad1+(7-(typ1 mod 8))+(txp1 mod 8)*32
  print at int(typ1/8),int(txp1/8);"\A\C"
  print at 1+int(typ1/8),int(txp1/8);"\B\D"
  end sub

yo=0:xo=0
putudgsprite(xo,yo,@udg01)
x1=128:y1=128

do
  cn1=((255-(in 64510)) band 2)/2 bor ((255-(in 65022)) band 2) bor ((255-(in 65022)) band 1)*4 bor ((255-(in 65022)) band 4)*2 :'- wsad
  cn2=((255-(in 61438)) band 8)/8 bor ((255-(in 61438)) band 16)/8 bor ((255-(in 63486)) band 16)/4 bor ((255-(in 61438)) band 4)*2 :'-7658
  cn0=cn1 bor cn2
  x1=x1-((cn0 band 4)/4)
  x1=x1+((cn0 band 8)/8)
  y1=y1-((cn0 band 1)/1)
  y1=y1+((cn0 band 2)/2)
  over 1 
  putudgsprite(xo,yo,@udg01)
  xo=x1:yo=y1
  putudgsprite(x1,y1,@udg01)
  pause 1
  loop

do:loop

udg01:
asm
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

end asm

so, any idea of using "true" sprites instead of that attempt above? Big Grin
Reply
#2
(08-25-2021, 08:02 PM)nitrofurano Wrote: since a long time i was thinking how simple or possible would be using sprite engines/libraries on zxbasic-compiler (just like those used on z88dk and so on)

so i started to try this (very glitchy and inefficient, as the code shows... Big Grin  )

(wsad or cursors for moving)

Code:
ink 1
border 1:ink 5:bright 1: paper 1: cls

sub putudgsprite(txp1 as uinteger,typ1 as uinteger,tad1 as uinteger)
  poke uinteger $5C7B,tad1+(7-(typ1 mod 8))+(txp1 mod 8)*32
  print at int(typ1/8),int(txp1/8);"\A\C"
  print at 1+int(typ1/8),int(txp1/8);"\B\D"
  end sub

yo=0:xo=0
putudgsprite(xo,yo,@udg01)
x1=128:y1=128

do
  cn1=((255-(in 64510)) band 2)/2 bor ((255-(in 65022)) band 2) bor ((255-(in 65022)) band 1)*4 bor ((255-(in 65022)) band 4)*2 :'- wsad
  cn2=((255-(in 61438)) band 8)/8 bor ((255-(in 61438)) band 16)/8 bor ((255-(in 63486)) band 16)/4 bor ((255-(in 61438)) band 4)*2 :'-7658
  cn0=cn1 bor cn2
  x1=x1-((cn0 band 4)/4)
  x1=x1+((cn0 band 8)/8)
  y1=y1-((cn0 band 1)/1)
  y1=y1+((cn0 band 2)/2)
  over 1 
  putudgsprite(xo,yo,@udg01)
  xo=x1:yo=y1
  putudgsprite(x1,y1,@udg01)
  pause 1
  loop

do:loop

udg01:
asm
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

end asm

so, any idea of using "true" sprites instead of that attempt above? Big Grin

Well this is the first approach, and some people has managed to optimize that code and make complete games!
That said, you can use PutChar (a routine which is much faster than print, but only focused in putting a char):
https://zxbasic.readthedocs.io/en/docs/l...chars.bas/

There are other many libraries (some of them bundled with ZX Basic compiler, like FourSpriter) (for 2x2 Cells sprites like your example):
https://zxbasic.readthedocs.io/en/docs/t...er-spanish

And finally the MOST advaced ones are Nirvana Engine
https://spectrumcomputing.co.uk/entry/30...ANA_ENGINE

and Dr Gusman sprite library (this last one, my favourite)
https://github.com/gusmanb/GuSprites
He also created an editor!
https://github.com/gusmanb/ResourceDesigner

Note: Nirvana and Nirvana+ engines are VERY ADVANCED and I don't provide support for them (search in this forum or contact Einar Saukas, the main author).
Reply
#3
putchars could be used to put a whole screen if you wanted! Yes, it's character based, but not just single character.

Fourspriter is also character based.

I hadn't seen GuSprites at all. That's cool! Why isn't that in the library here Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)