Okay, invisible bullets. Lancer-X loves these and I may be depriving him but anyway,
: "check"
wait 1
. "This erases the gun burst, created later in the code."
change overlay c0e '*' c07 ' '
. "if the A key (Code 30) is OFF, go back and wait"
if "key30" = 0 "check"
. "Reset things."
set "increaseX" to 0
set "increaseY" to 0
set "bulletX" to "playerX"
set "bulletY" to "playerY"
. "Because of the &playerfacedir& here, we'll go to different labels depending on what way the player is facing."
goto "shoot&playerfacedir&"
: "shoot0"
. "Facing North"
. "We want the bullet to go up. When you travel up, the Y-coordinate decreases."
set "increaseY" to -1
goto "shoot"
: "shoot1"
. "Facing South"
. "We want the bullet to go down. When you travel down, the Y-coordinate increases."
set "increaseY" to 1
goto "shoot"
: "shoot2"
. "Facing East"
. "We want the bullet to go east. When you travel east, the X-coordinate increases."
set "increaseX" to 1
goto "shoot"
: "shoot3"
. "Facing West"
. "We want the bullet to go west. When you travel west, the X-coordinate decreases."
set "increaseX" to -1
goho "shoot"
. "What this loop does is it silently increases the bullet's position one step at a time. When it hits something, we'll get out of the loop."
loop start
. "Update the position. For example, if we are going right, this would make bulletX go up by one since increaseX is 1, so the bullet is actually going right."
inc "bulletX" by "increaseX"
inc "bulletY" by "increaseY"
. "Is there something at this position?"
if c?? Robot p?? at "bulletX" "bulletY" then "hit"
if c?? PushableRobot p?? at "bulletX" "bulletY" then "hit"
if c?? CustomBlock p?? at "bulletX" "bulletY" then "hit"
if c?? Solid p?? at "bulletX" "bulletY" then "hit"
if c?? Normal p?? at "bulletX" "bulletY" then "hit"
. "There must be nothing good there, so let's return to the top of the loop and travel more."
loop for 80
. "If you get here, that loop happened 80 times, meaning the bullet has traveled 80 spaces and is no longer ''visible'' since 80 is the maximum viewport size possible. Let's act like it never hit and go back to the main loop."
goto "check"
: "hit"
. "There's something hittable at (bulletX,bulletY). Let's put a little burst there. There's code in the main loop to erase the burst after one cycle."
put c0e '*' overlay at "bulletX" "bulletY"
. "If a Robot is there, make it go to the SHOT label."
send at "bulletX" "bulletY" to "shot"
. "And that's all there is to do."
goto "check"
Also note that if the overlay is static the gun burst will show up in the wrong place on scrolling boards. Here's an idea for a status engine not needing the static overlay:
: "loop"
. "scrolledX and scrolledY always refer to the top corner of the visible screen no matter how far you've scrolled."
write overlay c0f "Ammo &ammo&" "scrolledX" "scrolledY"
. "Let the player see it"
wait 1
. "This loop turns every last white character on the overlay into space."
loop start
change overlay c0f "loopcount" c07 ' '
loop 255
goto "loop"
Lastly, make sure to set the "commands" counter to something like 32767 (in your global robot) so that these loops can do a lot of stuff without having to wait 1 every 40 commands.
There's a way to get this counter extremely high but I don't use it because if there's a loop somewhere without wait 1, it'll freeze MZX.
Need a dispenser here.