Animating Bullets

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
MrVertigo
Posts: 105
Joined: Fri May 27, 2022 9:06 pm

Animating Bullets

Post by MrVertigo »

When I’m animating a bullet going up the screen, like in Space Invaders, I do something along these lines:

10 Let x=20
20 print at x,16;”*”
30 let x=x+1
40 print at x-1,16;” “
50 GOTO 20

Is there another, better, way to do this in BASIC (not machine code)?

I also know about swapping CLS for line 40, but it seems too much flicker for me. Swapping lines 30 and 40 is simpler code (with the -1 removed) but also seems to flicker more. (Not sure if that’s my imagination.)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Animating Bullets

Post by XavSnap »

This code:
10 LET X=19
20 PRINT AT X,16;" ";TAB 16;"*";TAB 16;" "
30 LET X=X-1
50 GOTO 20
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
MrVertigo
Posts: 105
Joined: Fri May 27, 2022 9:06 pm

Re: Animating Bullets

Post by MrVertigo »

Thank you!
MrVertigo
Posts: 105
Joined: Fri May 27, 2022 9:06 pm

Re: Animating Bullets

Post by MrVertigo »

Using these methods, is there anyway to control the speed? I sometimes change to x=x+2 to make it go faster, but again, it flickers a lot.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Animating Bullets

Post by XavSnap »

O this code (not a MC code):
Use the DF_CC system variable = "PRINT AT" video memory offset.

10 LET X=20
20 PRINT AT X,16;"*";
25 POKE (PEEK 16399*256+PEEK 16398)+32,0
30 LET X=X-1
50 IF X>=0 THEN GOTO 20
60 RUN
Last edited by XavSnap on Thu Aug 11, 2022 8:08 pm, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Animating Bullets

Post by XavSnap »

x=x+2
Bottom to the up side X=X-2
Up to the bottom side=X=X+2

Down:
10 LET X=0
20 PRINT AT X,16;"*";
25 POKE (PEEK 16399*256+PEEK 16398)-1,0
30 LET X=X+1
50 IF X<18 THEN GOTO 20
60 RUN



Up:
10 LET X=20
20 PRINT AT X,16;"*";
25 POKE (PEEK 16399*256+PEEK 16398)-1,0
30 LET X=X-1
50 IF X>0 THEN GOTO 20
60 RUN


Just change LET X=X-1 >>> LET X=X-2
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Animating Bullets

Post by XavSnap »

Withis this code:
10 LET X=19
20 PRINT AT X,16;" ";TAB 16;"*";TAB 16;" "
30 LET X=X-1
50 GOTO 20


You had to add a space line: (2 space " " due to the bidirectional move, use one eraser space in case of up to down move)
10 LET X=19
20 PRINT AT X,16;" ";TAB 16;TAB 16;"*";TAB 16;TAB 16;" "
30 LET X=X-2
50 GOTO 20
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Animating Bullets

Post by XavSnap »

To limit the flicking during the display, erase the dot before print a new one.
Keep the printed dot location in the memory, and retrieve it after the BASIC scan process .
The first erased dot in poked in the ROM (POKE 3,0).
The A variable had to be set...

5 LET A=PI
10 LET X=20
20 POKE A,0
25 PRINT AT X,16;"*";
30 LET A=(PEEK 16399*256+PEEK 16398)-1
40 LET X=X-1
50 IF X>0 THEN GOTO 20
55 POKE A,0
60 RUN
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
MrVertigo
Posts: 105
Joined: Fri May 27, 2022 9:06 pm

Re: Animating Bullets

Post by MrVertigo »

Brilliant! 🙏
Post Reply