nxtbasic: 64x64 8bit sprite that I can paint.

All aspects of programming on the Commander X16.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

nxtbasic: 64x64 8bit sprite that I can paint.

Post by funkheld »

hello, good day.

I have a 64x64 8bit sprite that I can a small plot-demo with key "A".

The sprite address for the 32kb is:
$1:3000-$1:AFFF Sprite Image Data (up to $1000 per sprite at 64x64 8-bit)

The sprite could be used as a painting surface with 64x64 pixels.
The address for my first 64x64 sprite is $1:3100

Who can create a command for "line , rectangle and circle" for a 64x64 sprite with color.

greeting

Code: Select all

screen 128
Dim Sprites(3)  

Sprites(1) = ADDSPRITE("sprleer64.raw",64,64,8,0)

x=0
y=0
f=0
x1=-1
y1=-1

ShowSprite 1,100,100,3

StartEdit:
    Loop:
        Key$=GET
        if Key$="Q" then GOSUB links
        if Key$="E" then GOSUB rechts
	if Key$="W" then GOSUB oben
        if Key$="S" then GOSUB unten
	if Key$="A" then    
           x1=x1+1
	   y1=y1+1
           f=4
	   spritep(x1,y1,f)
	end if 
    Goto loop
end

links:
    x=-1
    y=0
    MoveSprite Sprites(1),x,y
return

rechts:
    x=1
    y=0
    MoveSprite Sprites(1),x,y
return

oben:
    y=-1
    x=0
    MoveSprite Sprites(1),x,y
return

unten:
    y=1
    x=0
    MoveSprite Sprites(1),x,y
return

sub spritep(xp,yp,f)
    xy=yp*64+xp
    VPOKE 1,$3100+xy,f
end sub


gruss
Attachments
sprleer64.zip
(818 Bytes) Downloaded 71 times
spriteplot.jpg
spriteplot.jpg (9.07 KiB) Viewed 1752 times
unartic
Posts: 145
Joined: Sat Oct 28, 2023 3:26 pm

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by unartic »

I'm not sure what you mean.

Do you want a line. rect and circle command to draw 'on' the sprite? Like in sprite memory?

That would be quite a chalenge for which there are no default solutions. The easiest way is probably to just draw on the bitmap layer and copy the bitmap bytes to the sprite location when you are finished with the drawing.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by funkheld »

thanks for the info.

-----------------------------
The easiest way is probably to just draw on the bitmap layer and copy the bitmap bytes to the sprite location when you are finished with the drawing.
-----------------------------

Please show me how to copy this to this address.
addresse : 1,$3100

greeting
unartic
Posts: 145
Joined: Sat Oct 28, 2023 3:26 pm

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by unartic »

Here it is :-)

The file 'splash.bin' (attached) should be in the same folder as the compiled prg file.

Code: Select all

SCREEN 128

'Load an image to the bitmap layer
BVLOAD "splash.bin",0,0

'Add a sprite
nr = ADDSPRITE("",64,64,8,0)


'Coordinates of left top corner
xStart=30
yStart=100

' Copy a bit of the bitmap layer to sprite address (NOTE: yStart*320 + xStart must be < $FFFF 
' because read bank 0 is hardcoded here)
for y = 0 to 63
    line$ = VPEEKN(0,y*320 + yStart*320 + xStart,64)
    VPOKEN 1,$3100 + (y*64),line$
next

'Show sprite
SHOWSPRITE nr,5,5,3

'Move sprite with ASDW keys
Loop:
    key$ = GET
    if key$="D" then MoveSprite nr,5,0
    if key$="A" then MoveSprite nr,-5,0
    if key$="W" then MoveSprite nr,0,-5
    if key$="S" then MoveSprite nr,0,5


goto loop
Attachments
splash.bin
(75 KiB) Downloaded 67 times
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by funkheld »

hey you master....it's great, thanks for your help.

your nxtbasic has a lot of power.

greetings
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by funkheld »

hello, you once asked who had ideas for programming games with nxtbasic.

my idea above was to create graphics on the 64x64 sprites, so that this sprite is then a moving screen 64x64.
plot-rect-circle-line etc.

if you then use several 64x64 sprites as screen graphics, it is another good basis for a game.

since you have a lot of ASM knowledge, I can see that from your ASM integrations for nextbasic, I don't think it would be that difficult for you to realize my idea.

thanks.
greeting
unartic
Posts: 145
Joined: Sat Oct 28, 2023 3:26 pm

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by unartic »

Hi!

Im unsure what your idea is all about ;-) Can you elaborate on that a bit?
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by funkheld »

Use the 64x64 sprite as a screen, draw graphics. I've just shown a line as a plot above because it was easy for me.
You then have several 64x64 sprites as screens that move, you can then create displays and other things for a
game that you can then change in the game.

greeting
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by funkheld »

hello unartic , good day.

can you please implement this in nxtbasic?

thanks.
greetings

-----------------------------
void plotLine(int x0, int y0, int x1, int y1)
{
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = dx+dy, e2; /* error value e_xy */

for(;;){ /* loop */
print x0; y0;
if (x0==x1 && y0==y1) break;
e2 = 2*err;
if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
}
}
-------------------------------


-------------------------------
void plotCircle(int xm, int ym, int r)
{
int x = -r, y = 0, err = 2-2*r; /* II. Quadrant */
do {
print xm-x ; ym+y; /* I. Quadrant */
print xm-y ; ym-x; /* II. Quadrant */
print xm+x ; ym-y; /* III. Quadrant */
print xm+y ; ym+x; /* IV. Quadrant */
r = err;
if (r <= y) err += ++y*2+1; /* e_xy+e_y < 0 */
if (r > x || err > y) err += ++x*2+1; /* e_xy+e_x > 0 or no 2nd y-step */
} while (x < 0);
}
-------------------------------
unartic
Posts: 145
Joined: Sat Oct 28, 2023 3:26 pm

Re: nxtbasic: 64x64 8bit sprite that I can paint.

Post by unartic »

funkheld wrote: Sun Aug 04, 2024 1:55 pm hello unartic , good day.

can you please implement this in nxtbasic?

thanks.
greetings

-----------------------------
void plotLine(int x0, int y0, int x1, int y1)
{
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = dx+dy, e2; /* error value e_xy */

for(;;){ /* loop */
print x0; y0;
if (x0==x1 && y0==y1) break;
e2 = 2*err;
if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
}
}
-------------------------------


-------------------------------
void plotCircle(int xm, int ym, int r)
{
int x = -r, y = 0, err = 2-2*r; /* II. Quadrant */
do {
print xm-x ; ym+y; /* I. Quadrant */
print xm-y ; ym-x; /* II. Quadrant */
print xm+x ; ym-y; /* III. Quadrant */
print xm+y ; ym+x; /* IV. Quadrant */
r = err;
if (r <= y) err += ++y*2+1; /* e_xy+e_y < 0 */
if (r > x || err > y) err += ++x*2+1; /* e_xy+e_x > 0 or no 2nd y-step */
} while (x < 0);
}
-------------------------------
Currently nxtBasic already includes a (very fast) line drawing function https://github.com/unartic/nxtBasic/blo ... cs.md#line

A circle function is still on the todo-list though :-)
Post Reply