Navigation

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

    Problem with sprites & arrays

    Beginners
    11
    42
    2921
    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.
    • SteveZX81
      SteveZX81 F last edited by

      Hello all,
      I require a poke in the correct direction regarding a game I'm working on.
      My game draws 100 coin sprites on screen (coins[]) and I am wanting to remove the coins when they are hit by another sprite. I am 'trying' to use a second array (coinhit[]) to keep track of the coins, (0 = draw it, 1 = don't)
      but I cannot see to get it to work, all my coins are redrawn each time and I'm not sure what I'm doing wrong.

      code.jpg

      1 Reply Last reply Reply Quote 2
      • N
        Nisse5 F last edited by

        "coins[1]" on line 94 looks strange

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

          Have you remembered to use updateSprites() in your main loop?

          1 Reply Last reply Reply Quote 1
          • Eearslya
            Eearslya Donator last edited by

            Just as @Nisse5 said, you're setting the location of coins[1], which is always the same coin, rather than the particular coin that was collided with.

            Line 94 should be:

            setspritelocation(coins[i], -1000, 0)
            
            1 Reply Last reply Reply Quote 4
            • SteveZX81
              SteveZX81 F last edited by

              Thank you all! It works now.

              Man.. I feel so embarrassed for that, should have spotted it a mile off. doh!

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

                Could barely even get to my computer before this had been completely sorted! Awesome job guys :)

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

                  @Dave They don't need us anymore

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

                    @pianofire This forum is now coated in an SEP field.

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

                      Hello again guys,
                      Yes I'm sorry I'm here begging for help again. (I have been trying honest!)

                      My problem is that when a coin underneath another one is removed, I want the coin above to drop down one row (48 pixels I think)
                      I have been trying to do this all day long and have tried several different things from changign the loop that draws the coins , changing the loop that detects and removes 'hit' coins and even setting up an array to log the coin positions and use that as a reference to see if a coin can drop or not. but all my feeble attempts have failed.

                      Here is my code for drawing the coins (two types) and the collision/removal code for one of them. Could you give me a nudge in the correct direction on how to get the coins to drop it there is no sprite underneath it?

                      code.jpg

                      Thank you all and I'm really sorry about asking for help again so soon.

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

                        @SteveZX81 Are you going to animate the drop? If not, it's easier to "fake" the drop IMO. Don't move any sprite positions. Instead of thinking that the coin is dropping, remove the coin at the top and let the coin at the bottom remain - because the end result is that the vertical stack is decreasing isn't it?

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

                          @Nisse5 said in Problem with sprites & arrays:

                          @SteveZX81 Are you going to animate the drop? If not, it's easier to "fake" the drop IMO. Don't move any sprite positions. Instead of thinking that the coin is dropping, remove the coin at the top and let the coin at the bottom remain - because the end result is that the vertical stack is decreasing isn't it?

                          Well now, isn't that a very clever idea!! hahaha love it.
                          but I think that will be just as hard? as I have to find a way to identify what 'stack' it hit and work out which to remove? of course I could be totally wrong but yes I don't care about animating the drop.

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

                            @SteveZX81 said in Problem with sprites & arrays:

                            @Nisse5 said in Problem with sprites & arrays:

                            @SteveZX81 Are you going to animate the drop? If not, it's easier to "fake" the drop IMO. Don't move any sprite positions. Instead of thinking that the coin is dropping, remove the coin at the top and let the coin at the bottom remain - because the end result is that the vertical stack is decreasing isn't it?

                            Well now, isn't that a very clever idea!! hahaha love it.
                            but I think that will be just as hard? as I have to find a way to identify what 'stack' it hit and work out which to remove? of course I could be totally wrong but yes I don't care about animating the drop.

                            If you use row/col to position the sprite, you basically do the reverse to go from position to row/col.

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

                              I honestly appreciate the help, thank you so very much. ( I sadly cannot grasp the concept but that does not matter)
                              Thanks!

                              N 1 Reply Last reply Reply Quote 1
                              • Tratax
                                Tratax F last edited by

                                Hey @SteveZX81 - Can you share a screenshot of what the game looks like so far? It sounds like the coins will be hit at the bottom row?

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

                                  Screenshot, sure!
                                  screen.png

                                  Tratax 1 Reply Last reply Reply Quote 2
                                  • N
                                    Nisse5 F @SteveZX81 last edited by

                                    @SteveZX81 said in Problem with sprites & arrays:

                                    I honestly appreciate the help, thank you so very much. ( I sadly cannot grasp the concept but that does not matter)
                                    Thanks!

                                    First, according to the screen shot it seems like you have mixed "col" and "row" in the source code. (You have 5 rows with yellow coins, not 19.)

                                    If you set the x-position of the sprite with "xpixelpos=500+col*48" (based on your source code for yellow coins), you do the reverse to get the column number from a sprite position: "col=(xpixelpos-500)/48"

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

                                      @SteveZX81 So I tend to think of grid based games in two frames of mind:

                                      1. the "logical layer", mapping out each tile,object,etc as a position on a blank grid, where each positition from x,y represents a trackable and variable location (grid paper and excel is great for this)
                                      2. the graphical representation of what may happen "above" that layer where all the creative stuff happens

                                      For your game, assuming we had 6 columns and 10 rows: I would first have a function or routine that determines where the logical layer change will occur for where the collision takes place. With that determined we then have a known position for the collisions X/Y (say the bomb falls 6 positions down) and can perform a for loop checking if state had changed then update the top value in that column from say 2, to 0.
                                      On the graphical layer as part of your draw routine, you can then associate your drawn sprite against the new grid value

                                      Does that help?

                                      Screenshot_20190920-080109_Excel.jpg

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

                                        uhm.. okay, well thank you!

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

                                          It would have been easier to store the coins in a 2 dimensional array, but since you've used a single dimension the coin above coin[i] is coin[i-width] where width is how many coins are in each row of your display, which is 19 in the case of your yellow coins. So for example if you have a collision on coin[40] the one above it would be coin[21] and the one above that would be coin[2]. Also I agree with @Nisse5 that you've got the columns and rows swapped.

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

                                            Thanks, you know I must have a blind spot when it comes to rows and columns, I've always thought that columns were vertical and rows horizontal. oops!

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