Hello this is my first game and the lasers just don't do what they're meant to
Instead of firing one at a time they just come out in a stream
I'm doing the magpi spaceshooter tutorial and I've looked at the code for it and it is the same as my code
I really need help
thanks
[#Drone to Home v0.1#]
The code in the post about the magpi tutorial here in the forums has the laser code wrapped in a check against a timer. The simplest way to do that from the code you have now is to replace this line
if (btn(4)) then |
with this
if (btnp(4)) then |
and then poke the repeat time locations in memory during the init() function to control the behavior of btnp().
If you want the laser to fire only once each press it's
poke(0x5f5c,255) |
If you want the laser to fire at a set amount when held it's
poke(0x5f5c,10) poke(0x5f5c,10) |
using the example of 10 frames between each shot.
Both of the above ways would still allow the player to rapidly press the button to shoot faster, though. If you want to avoid that, an actual cooldown would be needed. Here's a minimal way to accomplish that if desired:
Instead of any of the above, replace
if (btnp(4)) then makel(pl.x,pl.y) sfx(0) end |
with
pshot_time = pshot_time or 0 pshot_time -= (pshot_time > 0) and 1 or 0 if (btnp(4) and pshot_time <= 0) then pshot_time = 10 makel(pl.x,pl.y) sfx(0) end |
(again using the example of 10 frames between shots)
[Please log in to post a comment]