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.
    • 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
        • Dave
          Dave Fuze Team last edited by Dave

          Hi Steve

          Awesome project idea and so far it's looking great. I will be using this idea for a video at some point down the line, as this technique is so transferable to other game ideas!

          It looks to me like you'd benefit from a slightly cleaner laid out Coins array, using a structure:

          rows = 5
          cols = 19
          array coins[rows][cols] = [
              .spr = createSprite(),
              .pos = {},
              .active = true,
              .falling = false,
              .hit = false
          ]
          
          // You'll still have to do a loop to set sprite image etc
          for r = 0 to rows loop
              for c = 0 to cols loop
                  setSpriteImage( coins[r][c].spr, coinImg )
              repeat
          repeat
          

          With this setup, you have different states a coin can be in, and it's tracked more easily than having multiple arrays for different states. If you want to check a coin:

          for r = 0 to rows loop
              for c = 0 to cols loop
                  if !coin[r][c].active then
                      setSpriteVisibility( coins[r][c].spr, false )
                  endif
                  if !coin[r + 1][c].active then
                      coin[r][c].falling = true
                  endif
                  if coins[r][c].falling then
                       // Make your coin fall
                  endif
              repeat
          repeat
          

          Just in case it's not clear, I've written "if !coin[r][c].active". This is exactly the same as "if coin[r][c].active == false".

          Apologies that this isn't exactly a solution to your problem yet - I'll be taking a look today in more detail. Will get back to you Steve!

          However, in the meantime you might have more success in experimenting with a setup similar to that above.

          Thank you to everyone helping in the thread! Also @SteveZX81, I was exactly the same with Rows and Columns... It really doesn't matter which way around you do it as long as you're consistent, but conventionally yes, row is vertical position and column is horizontal position. Rows of columns.

          It took @Luke repeatedly shouting "ROWS OF COLUMNS!" at me before it sunk in haha.

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

            @SteveZX81 said in Problem with sprites & arrays:

            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!

            Err, they are! In the real world at least.

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

              Thanks Dave! The reason I didn't use structures is that quite frankly I don't feel I understand them enough to use them, but I'll use your code above as a good learning opportunity and see if I can get this working. (edit: jeez this is hard. eek!)

              Thank you!

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

                @Martin Agreed, but in the code you're not trying to define what a row is, but indicate which row you are on.

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

                  Just want to say thanks to everyone who's tried to help. I really appreciate your help and your time but I've decided to wave the white flag on this and give up, so no point in any more replies but again thank you!

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

                    @SteveZX81 That is a shame but I understand it can be frustrating. Maybe come back to it later.

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

                      Steve, no matter what, it's very important to spend some time on structures as they are very powerful and once grasped really easy. Secondly, and this is just my opinion, coding using states is really, really important. States are not part of the language, they are just a concept.

                      I've almost finished my arcade remake of Rescue from Stern. It has taught me so much about using states that i wish i'd done it ten years ago!

                      Every single variation of an items existence is simply a state. In the case of Rescue i have a little bloke falling from the sky:

                      soldier.parachuting = 0
                      soldier.falling = 1
                      soldier.swimming = 2
                      soldier.sinking = 3

                      if soldier.state == soldier.parachuting then
                      run this bit of code
                      endif

                      If soldier.state = soldier.falling
                      run this bit of code
                      endif

                      If soldier.state = soldier.swimming
                      run this bit of code
                      endif

                      soldier.state = soldier.sinking
                      run this bit of code
                      endif

                      If I have ten different items existing the process is the same for all of them. This way it is easy to have everything happening at once all with their own little controls.

                      Generally each state, once it has been set moves on to the next state. So when my soldier has successfully parachuted into the water he changes to .swimming but if he got hit on the way then he goes into .falling and when he hits the water, well he’s dead by now so he’s .sinking – poor little thing!

                      I was really worried when I saw your ‘white flag’ post. Just a couple of days ago I sent a comment to the team listing games I’d love to see and Atari’s Canyon Bomber (1977) was in the list so I was really chuffed to see you had taken it on. Canyon Bomber was one of the first true video games I played in the grand old holiday town of Minehead in Somerset.

                      If I can be of any assistance with the project then let me know. My email is jon.silvera@fuze.co.uk and I’d be very happy to help if I can.

                      I think it should be in Black and White though!

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

                        @SteveZX81 - ignore this, I don't want to confuse you!
                        @Jonboy - quick tip, and sorry if you already know this.

                        if instead of

                        soldier.parachuting = 0
                        soldier.falling = 1
                        soldier.swimming = 2
                        soldier.sinking = 3
                        

                        You have

                        soldier.parachuting = 1
                        soldier.falling = 2
                        soldier.swimming = 4
                        soldier.sinking = 8
                        

                        Then it becomes possible to do bitwise logic on your state. It may not seem like much and is actually totally irrelevant to your use case because your soldier can't be doing two things at once, but let's say that your soldier could be both swimming and sinking at the same time (maybe he can't swim very well!) Then soldier.state would be 12. In the code you would say:

                        soldier.state = soldier.swimming | soldier.sinking
                        

                        And when you know that it is possible for your soldier to do two things at once, ask if he is swimming by saying:

                        if soldier.state & soldier.swimming then
                        

                        We don't care what else they may be doing, but we know they are at least swimming!

                        Like I say, bordering on shouldn't be in the beginning help section, and no good for your use case, but I just wanted to mention it since it ties in with the state stuff you mentioned.

                        sys64738 Dave 2 Replies Last reply Reply Quote 2
                        • sys64738
                          sys64738 F @Martin last edited by sys64738

                          @Martin this is exactly how wavetables work in the c64 sid chip so you can use 2 waveforms in single note. well not using logic, but bits in fuze 0000 0000 is square 0000 0100 is noise so 0000 0101 would be square and noise together (feel free to make fuze capable of this)

                          Thanks for the posts about states, I had been doing a ghetto version of this to tell what my octopus in the deep is up to, I might convert him to a struct since as a learning process.

                          Games looking good steve, just come back to it when you are ready, Maybe start another project for now. I have same problem with my the deep project, trying to learn too many new concepts is overwhelming, I do my best coding in the shower (when I'm away from it all) haha

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

                            I swear this software is turning me into a raving madman. I woke up at 4:32am this morning with an idea that I thought would solve my problem, so climbed out of bed in the middle of the night and tried it. of course it failed as per usual but still.. I must be insane. lol

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

                              @SteveZX81 Ah yes 4AM programming. I know it well

                              1 Reply Last reply Reply Quote 0
                              • M
                                MikeDX last edited by

                                Yep! sounds perfectly normal to me. wake up with idea and must try it. programming isn't typing, it's thinking. well actually the typing is the programming but the developer part is the thinking

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

                                  Guys, I'm really sorry for keeping spamming this thread but I feel I'm so close..

                                  I've been working on my 4am idea and that is to use an array to set the # of coins in a column (row to you guys) and then draw the coins using the array to draw however many coins in each column then deduct 1 from the index of the array when a coin in that column(row to you) is hit.

                                  This is what I have now.
                                  newcode.jpg

                                  The first bit sets up the array and sets each index to 3 (3 coins in a stack, just to test it)

                                  The second bit of code draws the coin sprites on screen using the array to see how many to add

                                  The third bit tests for a collision with the bomb and apart from adding to the score etc, it takes one away from the array (which hopefully means that column(row to you) will draw with one less coin next time)

                                  but I'm getting errors like 'array out of bounds'.

                                  I honestly feel that I'm close to this working.. well, I think so.
                                  am I on the right track or utterly clueless?

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

                                    @SteveZX81 It's line 140 that gets the error isn't it? You're looping up to 26, while the highest array index you can use for that array is 9.

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

                                      @Nisse5 said in Problem with sprites & arrays:

                                      @SteveZX81 It's line 140 that gets the error isn't it? You're looping up to 26, while the highest array index you can use for that array is 9.

                                      Right yeah! ohh damn.. that kind of trashes the whole 'approach'. as changing that to 9 means it won't detect a collision with the others. ughhhh and I really thought I was close to fixing it. hells bells

                                      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 It's line 140 that gets the error isn't it? You're looping up to 26, while the highest array index you can use for that array is 9.

                                        Right yeah! ohh damn.. that kind of trashes the whole 'approach'. as changing that to 9 means it won't detect a collision with the others. ughhhh and I really thought I was close to fixing it. hells bells

                                        I'm not actually sure the approach is wrong... I just think you use the wrong index for what you want to do. (Hint: look for example how you draw the coins and how you use array indexes there.)

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

                                          Thanks.

                                          I've tried redoing the collision bit to this but alas no joy. I've tried so many variants now that I'm about to put my fist through my monitor lol.

                                          Here is my latest lame failed attempt
                                          morecode.jpg

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

                                            @SteveZX81 Go a bit further and use "c=0" and "c+=1" as you do in the draw loop. Then reference c in the same way as you do in the draw loop. Currently, you loop in the same way, but you reference the array indexes in a different way.

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