Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Dealing with multiple enemy shots?

    Beginners
    8
    37
    1756
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Martin
      Martin Fuze Team last edited by

      It’s not a language thing just something that I do. Check out YASS

      1 Reply Last reply Reply Quote 1
      • Willpowered
        Willpowered Fuze Team @SteveZX81 last edited by Willpowered

        @SteveZX81 said in Dealing with multiple enemy shots?:

        Thanks. The whole 'nullsprite' thing is unknown to me. I shall look into it
        Thank you

        Here's an example of how this might work, using "nullsprite" as a placeholder.

        // At program start...
        
        nullsprite = createSprite() // make a placeholder sprite indicating "empty" or "nothing"
        
        // initialize our array of shots
        array shots[100]
        for i = 0 to 100 loop
        	// no shots exist yet since the program is just starting, so set each value in the array to nullsprite.
        	shots[i] = nullsprite
        repeat
        
        // Later, in your game loop...
        
        // shoot
        c = controls(0)
        if c.a then
        	// find a free entry in the shots array
        	for i = 0 to len(shots) loop
        		// if this slot in the array is nullsprite, then we know it's empty!
        		if shots[i] == nullsprite then
        			shots[i] = createSprite()
        			// do the rest of your shot setup here (graphics, position, etc.)
        		endif
        	repeat
        endif
         
        // process shot movement
        for i = 0 to len(shots) loop
        	// if this slot in the array is NOT nullsprite, then we know it's an active shot
        	if shots[i] != nullsprite then
        		shots[i].x += 5
        		// (example movement- Move your sprite here!)
        		
        		// collision and shot removal
        		if collideSprites(shots[i], player).exists then
        			deleteSprite(shots[i])
        			shots[i] = nullsprite // this entry in the array is now free for a new shot!
        		endif
        	endif
        repeat
        

        I hope that's able to answer your question! That's how I did multiple shots for the Super Mega Arena Blaster example program. If there's any part that you're stuck on let us know.

        1 Reply Last reply Reply Quote 3
        • SteveZX81
          SteveZX81 F last edited by

          Thanks a lot for that! @Willpowered
          I have it partially working, I say partially as it only fires one shot no matter how many times I press the button, but I'm betting that's a typo by me
          so I'll check over it again.

          Thanks!

          1 Reply Last reply Reply Quote 0
          • SteveZX81
            SteveZX81 F last edited by

            Sorry for missing it but I can still only shoot one shot and no more, here is my code.
            I know there must be an error there but I can't see it.
            shootcode.png

            R 1 Reply Last reply Reply Quote 0
            • Martin
              Martin Fuze Team last edited by Martin

              You're not breaking out of the loop. Try this:

              for i = 0 to len(shots) loop
                  if shots[i] == false then
                      shots[i] = createSprite()
                      // blah, blah
                      break
                  endif
              repeat
              

              BUT

              I think that break will only break out of the IF, so you probably need this:

              foundSlot = false
              for i = 0 to len(shots) loop
                  if shots[i] == false then
                      shots[i] = createSprite()
                      // blah, blah
                      foundSlot = true
                  endif
                  if foundSlot then break endif
              repeat
              

              Or something along those lines. Again, look at YASS. I do it in a function in there.

              Furthermore, you shouldn't need to seperately move the shot. If when you create it you set it's speed then it will just move until you detect it's collision and remove it.

              1 Reply Last reply Reply Quote 0
              • R
                Richard F @SteveZX81 last edited by

                @SteveZX81 the code looks like it would create a new shot at every null sprite rather than just one, but you're getting none if one already exists. So I'm wondering if you've defined the length of shots as 1 rather than the maximum number of shots you want when you created the array. Or it is creating all of them, but in a single frame, so they're all at the same place, so it only looks like one. You could try adjusting their location by a multiple of i, just to visually see if it is creating more than one shot.

                1 Reply Last reply Reply Quote 0
                • Martin
                  Martin Fuze Team last edited by

                  He's only getting one and no more because all the slots are being filled up with the same sprite, with the same properties. So there are X number of shots but they're all on top of each other. That would be my best guess without actually running the code.

                  1 Reply Last reply Reply Quote 0
                  • R
                    Richard F last edited by

                    That's what I meant by my second option for what had gone wrong. I just didn't word it very clearly.

                    1 Reply Last reply Reply Quote 0
                    • SteveZX81
                      SteveZX81 F last edited by SteveZX81

                      Here is my code now.
                      shoot2.png

                      When I press the shoot button I get
                      --Error --
                      Line 108
                      Function N/A
                      Operation not recognized.

                      1 Reply Last reply Reply Quote 0
                      • Martin
                        Martin Fuze Team last edited by Martin

                        I will have to play about with this after work - i think that might be why I was using Will's method of assigning the nullSprite in the first place.

                        [edit] While you wait go back to assigning all empty slots to nullSprite and see if that works. The more I think about it, the more I think that's why I used that method in the first place. You will still need to break out of the loop with the 'foundSlot' boolean. But i have a feeling it is not liking you trying to assign a sprite handle to something that has previously declared as a bool.

                        1 Reply Last reply Reply Quote 0
                        • SteveZX81
                          SteveZX81 F last edited by SteveZX81

                          oops (edited)

                          1 Reply Last reply Reply Quote 0
                          • Dave
                            Dave Fuze Team last edited by

                            Mornin' @SteveZX81! I just shared a program called "particleLaser Sprites" which gives detailed comments on every section.

                            It's not doing any collision with enemies, but there is a commented out example for where the collision code would be.

                            Hope it helps mate, let me know if I can expand on anything in there.

                            SteveZX81 BildoCZ 2 Replies Last reply Reply Quote 1
                            • SteveZX81
                              SteveZX81 F @Dave last edited by

                              @Dave said in Dealing with multiple enemy shots?:

                              Mornin' @SteveZX81! I just shared a program called "particleLaser Sprites" which gives detailed comments on every section.

                              It's not doing any collision with enemies, but there is a commented out example for where the collision code would be.

                              Hope it helps mate, let me know if I can expand on anything in there.

                              oh Dave, you're too good to me! Thank you.

                              1 Reply Last reply Reply Quote 1
                              • BildoCZ
                                BildoCZ @Dave last edited by

                                @Dave Hi Dave. Where did you share "SpreadLaser Sprites"

                                1 Reply Last reply Reply Quote 0
                                • Martin
                                  Martin Fuze Team last edited by Martin

                                  Back then it would have been a user share as we did not have community sharing. If @Dave still has it then maybe he could re-share using an ID now?

                                  1 Reply Last reply Reply Quote 0
                                  • SteveZX81
                                    SteveZX81 F last edited by SteveZX81

                                    @BildoCZ I might still have it, I'll check my Switch watch this space.

                                    Edit: I do have it and I have now submitted it, the code is UQP63MNF6D but give it a few hours to clear the 'pending' state.

                                    waldron 1 Reply Last reply Reply Quote 1
                                    • Dave
                                      Dave Fuze Team last edited by

                                      @SteveZX81 - Life saver. I deleted the program recently as I was cleaning up my projects (I tend to make a lot to test individual things).

                                      Hope it helps @BildoCZ ! Let me know if you need anything

                                      waldron 1 Reply Last reply Reply Quote 1
                                      • waldron
                                        waldron F @SteveZX81 last edited by

                                        @SteveZX81 just downloaded it, looks good love the comments should be able to use this for my program hopefully

                                        1 Reply Last reply Reply Quote 2
                                        • BildoCZ
                                          BildoCZ last edited by

                                          Thx all.
                                          I'm a beginner in FUZE. But I used to work in Game Maker. :)

                                          1 Reply Last reply Reply Quote 2
                                          • waldron
                                            waldron F @Dave last edited by

                                            @Dave so i'm using the laser program for my scrolling top down game to get my plane to shoot but i cant get the y axis movement working? apart from that it works great.

                                            Dave 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post