nxtbasic : sprite spr64.raw before bild2.raw and sprite spr32.raw

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

nxtbasic : sprite spr64.raw before bild2.raw and sprite spr32.raw

Post by funkheld »

hello, good day.

spr64.raw / spr32.raw in front of bild2.raw with nxtbasic.

greetings

Code: Select all

'Demonstration of 3 sprites, where if they are colliding the animation speed is dropped
'and which sprites are colliding is displayed. 
'Developed by Unartic, july 2024

SCREEN 128
BVLOAD "bild2.raw" ,0,0
index1 = ADDSPRITE("spr64.raw",64,64,8,0)
index2 = CLONESPRITE(index1)
index3 = CLONESPRITE(index1)

Dim vX(index3)
Dim vY(index3)


SHOWSPRITE index1,RNDINT(320),RNDINT(240),3
SHOWSPRITE index2,RNDINT(320),RNDINT(240),3
SHOWSPRITE index3,RNDINT(320),RNDINT(240),3

'Initial vectors for all three balls
vX(index1)=3
vY(index1)=3

vX(index2)=6
vY(index2)=-3

vX(index3)=-6
vY(index3)=3

Locate 0,3
PRINT "BALLS SLOW DOWN WHEN THEY OVERLAP"
PRINT " AND SHOW WHICH BALLS ARE OVERLAPPING"

Loop:
    FOR i = index1 to index3
        if SPRITEGETX(i)+vX(i)<0 THEN
            vX(i) = RNDINT(3)+1
        elseif SPRITEGETX(i)+vX(i)>256 THEN
            vX(i) = NEG(RNDINT(3))-1
        END IF

        if SPRITEGETY(i)+vY(i)<0 THEN
            vY(i) = RNDINT(3)+1
        elseif SPRITEGETY(i)+vY(i)>176 THEN
            vY(i) = NEG(RNDINT(3))-1
        END IF    
        
        MOVESPRITE i,vX(i),vy(i)
    
    next i
    
    CollidingBalls$=""
    'SPRITECOL returns a string with ascii values for all colliding sprites
    if len(SPRITECOL(index1))>0 then
        CollidingBalls$ = STR$(index1) + " AND"
        c$ = SPRITECOL(index1)
        FOR i = 1 to len(c$)
            CollidingBalls$ = CollidingBalls$ + STR$(ASC(MID$(c$,i,1)))
        NEXT i
        
        
        sleep 10
    elseif len(SPRITECOL(index2))>0 then
        CollidingBalls$ = STR$(index2) + " AND"
        c$ = SPRITECOL(index2)
        FOR i = 1 to len(c$)
            CollidingBalls$ = CollidingBalls$ + STR$(ASC(MID$(c$,i,1)))
        NEXT i
        sleep 10
    elseif len(SPRITECOL(index3))>0 then
        CollidingBalls$ = STR$(index3) + " AND"
        c$ = SPRITECOL(index3)
        FOR i = 1 to len(c$)
            CollidingBalls$ = CollidingBalls$ + STR$(ASC(MID$(c$,i,1)))
        NEXT i
        sleep 10
    end if
    locate 25,15
    print "                                                ";
    locate 25,15
    PRINT CollidingBalls$;
    
goto Loop

Code: Select all

'Demonstration of 25 sprites moving rapidly along the screen 
'Developed by Unartic, july 2024

SCREEN 128
noSprites = 25          'number of sprites to display
Dim Sprites(noSprites)  'Sprite indexes
Dim vX(noSprites)       'x-vectors
Dim vY(noSprites)       'y-vectors

'Set screen to green
'RECT 0,0,319,239,9
BVLOAD "bild2.raw" ,0,0


'Add a sprite width=32, height=32, colordepths is 8bpp, and palette offset=0, and return its index
Sprites(1) = ADDSPRITE("spr32.raw",32,32,8,0)

'Show the sprite on the screen at a random location between x(0-300) and y(0-200), in front of layer 1
ShowSprite Sprites(1),RNDINT(300),RNDINT(200),3

'Clone this sprite as much as needed
for i = 2 to noSprites
    Sprites(i) = CloneSprite(Sprites(1))
next

'Set a vector for x and y positive or negative 1 to 10 px per 'frame'
for q = 1 to noSprites
    vX(q) = RNDINT(10)+1
    if RNDINT(100)>50 THEN vX(q)=neg(vX(q))
    
    vY(q) = RNDINT(10)+1
    if RNDINT(100)>50 THEN vY(q)=neg(vY(q))
next

Loop:
    for i = 1 to noSprites
        'get current x and y of a sprite
        x = SpriteGetX(Sprites(i))
        y = SpriteGetY(Sprites(i))
        
        'check if we need to bounce left or top
        if x<16 then vX(i)=RNDINT(15)+1
        if y<16 then vY(i)=RNDINT(15)+1
        
        
        'check if we need to bounce right or bottom
        if x>304 then vX(i)=NEG(RNDINT(15)+1)
        if y>224 then vY(i)=NEG(RNDINT(15)+1)
        
        'move the sprite amount of pixels in vector array
        MoveSprite Sprites(i),vX(i),vY(i)
    next
Goto Loop
Attachments
spr32.zip
(931 Bytes) Downloaded 39 times
vielesprite.jpg
vielesprite.jpg (28.7 KiB) Viewed 775 times
spr64-bild2.zip
(5.04 KiB) Downloaded 30 times
spritecolli.jpg
spritecolli.jpg (26.54 KiB) Viewed 792 times
Last edited by funkheld on Mon Jul 29, 2024 11:23 am, edited 5 times in total.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: nxtbasic : spritecolli spr64.raw before bild2.raw and many sprite spr32.raw and spr16.raw

Post by funkheld »

here ist collisprite spr16.raw

greeting
Attachments
spr16.jpg
spr16.jpg (21.77 KiB) Viewed 719 times
spr16.zip
(845 Bytes) Downloaded 31 times
Post Reply