Navigation

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

    Spawning obstacles

    Help
    5
    10
    437
    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.
    • H
      Holly8760 last edited by

      I am making a simple avoiding obstacles game. Currently, the player can be moved with the left joystick. I am now starting to add obstacles. My idea is to have an array that contains a structure for every obstacle. This structure has an X and Y comment which is responsible for holding the position of the obstacle. However, I am struggling to add these structures to the array. Is there a better way to do this? What is the best way to spawn obstacles at random positions on the screen? I am a beginner so baby talk, please.
      The shared game code is TWC3MNDHX
      Thank you in advance

      waldron 1 Reply Last reply Reply Quote 0
      • vinicity
        vinicity F last edited by

        I’m thinking that instead of adding structures to your array, you can add sprites directly. Sprites already have a .x and .y automatically. Also, sprites are special because you can add new custom parameters on the fly, like this:

        s = createSprite()
        s.myParam = 42
        s.anotherParam = “smurf“
        
        H 1 Reply Last reply Reply Quote 0
        • vinicity
          vinicity F last edited by

          I was assuming that you are working with a 2D game, otherwise using sprites makes less sense (although it can still be useful).

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

            And to answer your question as to how you add them to an array, one can for instance do this:

            var myArray = []
            for u = 0 to 10 loop
               s = createSprite()
               // Do more sprite init here
               myArray[len(myArray)] = s
            repeat
            
            1 Reply Last reply Reply Quote 0
            • waldron
              waldron F @Holly8760 last edited by

              @holly8760 hey, the download code is 1 character short can't download :/

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

                @Holly8760 Also I can't see your program awaiting approval (for a download code to work you must submit the program so that we can approve it for community sharing, otherwise only your switch friends will be able to download it).

                If you've not submitted it you can do so by going to the Share section from the home menu, pressing R twice to get to My Shared Programs, then pressing A on the program you want to submit and selecting Submit. :)

                H 1 Reply Last reply Reply Quote 1
                • H
                  Holly8760 @Kat last edited by

                  @kat, Ah I did not realize I needed to do that. Thank you, I'll do that from now on.

                  1 Reply Last reply Reply Quote 0
                  • H
                    Holly8760 @vinicity last edited by

                    @vinicity, Wow thanks for the help! I've never used sprites before but I'm excited to try.

                    vinicity 1 Reply Last reply Reply Quote 1
                    • vinicity
                      vinicity F @Holly8760 last edited by

                      @holly8760 Check out the sprite tutorials if you haven't already:


                      1 Reply Last reply Reply Quote 2
                      • Ben 2.0
                        Ben 2.0 last edited by

                        One very useful function that they do not mention in these tutorials is,
                        detectspritecollision(sprite_A, sprite_B)
                        This will detect a collision and return true if the specified sprites are colliding.
                        If you have trouble with the collision boxes then use this function,
                        setspritecollisionshape()

                        1 Reply Last reply Reply Quote 4
                        • First post
                          Last post