Chargin' laz0rz

Since there can be more than one bullet at a time, we need to store it in an array. Arrays are basically lists of elements with a similar structure; see our guide to arrays for more information.

But before we make the subroutines, we need to decide what the array's going to look like. An array is just a list of elements, so we need to figure out the most efficient format we can use to store a bullet. What information do we need about a bullet?

So that's it. Four bytes per element. We can store the bullets in L4, which gives us 256 bytes of memory (64 elements of our array) to work with. Like with all arrays, we need to first set a variable up to store the number of elements. It should be initialized in the init code:

PROGRAM:ASHMUPI
:..INIT
:44→X
:40→Y
:0→B

Now you can add the bullet-adding subroutine to prgmASHMUPR:

PROGRAM:ASHMUPR
:..ROUTINES
:Lbl ASB
:If B<64
:r4→{r3→{r2→{r1→{B+1→B*4+L4-4}+1}+1}+1}
:End :Return

Again, see http://clrhome.org/tutorials/arrays/02/ for a full-length explanation on how this works.

+ Tweet