Clearing certain sprites using an array?
Root / Programming Questions / [.]
XyoreCreated:
I'm currently making a game with many mini-games. One of the games is a shooting game of sorts where your ship shoots autonomously. Here's the code when the ship shoots:
[Every 60 ticks, create a bullet sprite at the ship's position and store it's ID in an array]
IF (_TIME - TIME) MOD (60/1+GAME*3)) == 0 THEN SPSET 3 OUT IX PUSH BULLETS, IX SPHOME IX,1,1 SPOFS 3 OUT _SHIPX, SPOFS IX,_SHIPX,SH-16 SPCOL IX ENDNow, it makes sense to clear the sprite and free up memory when a sprite goes off-screen, right? Unfortunately, that's where I run into a problem: [This code includes moving the bullet as well detecting whether or not it goes off-screen]
FOR I=0 TO LEN(BULLETS)-1 SPOFS BULLETS[I] OUT _BX,_BY SPANIM BULLETS[I],"XY",1,_BX,_BY-1 IF _BY < 0 THEN SPCLR BULLETS[I] SHIFT(BULLETS) BREAK ENDIF ENDThe problem with this code, however, is the SPCLR and SHIFT. I understand the SPCLR messing up, since when it clears the sprite and goes through the FOR loop again to move the cleared sprite, it won't exist. But why is SHIFT an illegal function? I mean, theoretically is should: 1. Clear the bullet 2. Remove the ID from the array Is there anything I could do to fix this code?
I believe that to use functions like SHIFT() and POP() you need to store the result you get from these functions. LikeA=SHIFT(BULLETS)Then you just don't use A.
you could also create a function to "eat" the return value of a functionHoly moly! Thank you both! I never realized that those functions returned a value. Again, thank you!DEF EAT SAND:END EAT SHIFT(BULLETS)