Spoonweaver wrote: As far as making your code allow only one bullet at a time. That's so simple it's startling you'd ask. You set a tag or variable on when the bullet is there and off when it disappears. While having the variable/tag control whether the player can shot or not.
Oddly enough I think that's exactly what I'm doing but it's still allowing me to have multiple instances of the bullet at a give time. Here's the current code in full:
Code:
variable(collection, sl, isShooting)
if(key is pressed(key:X)) then(
if(isShooting <> 1) then(
isShooting := 1
if(hero direction == right) then(
collection := load slice collection(10)
sl := lookup slice(sli:Bullet1, collection)
set parent(sl, lookup slice(sl:walkabout layer))
put slice (sl, hero pixel X (me), hero pixel Y (me))
set slice velocity x (sl, 20, 10)
set slice velocity y (sl, 0, 10)
isShooting := 1
wait for slice(sl)
free slice(sl)
isShooting := 0
exit script
)
if(hero direction == left) then(
collection := load slice collection(10)
sl := lookup slice(sli:Bullet1, collection)
set parent(sl, lookup slice(sl:walkabout layer))
put slice (sl, hero pixel X (me), hero pixel Y (me))
set slice velocity x (sl, -20, 10)
set slice velocity y (sl, 0, 10)
wait for slice(sl)
free slice(sl)
isShooting := 0
exit script
)
if(hero direction == up) then(
collection := load slice collection(10)
sl := lookup slice(sli:Bullet1, collection)
set parent(sl, lookup slice(sl:walkabout layer))
put slice (sl, hero pixel X (me), hero pixel Y (me))
set slice velocity x (sl, 0, 10)
set slice velocity y (sl, -20, 10)
wait for slice(sl)
free slice(sl)
isShooting := 0
exit script
)
if(hero direction == down) then(
collection := load slice collection(10)
sl := lookup slice(sli:Bullet1, collection)
set parent(sl, lookup slice(sl:walkabout layer))
put slice (sl, hero pixel X (me), hero pixel Y (me))
set slice velocity x (sl, 0, 10)
set slice velocity y (sl, 20, 10)
wait for slice(sl)
free slice(sl)
isShooting := 0
exit script
)
isShooting := 0
)
)
I also noticed the wait commands in this script interfere with my LOS script causing my player to remain unseen by the guards while shooting. Perhaps I should run the bullets on timers or something...
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases