Multiple sprite placement for platformer

Hi folks! I’ve trawled through this forum but can’t seem to find the answer I am looking for.
Prior to the upgrade I found it really easy placing multiple “food” spites on specific tiles, however, I cant seem to figure out how to do this now. I can set the food sprite to appear at random, but I don’t know how set multiple food sprites to appear at specific points in the platformer game I am building.

I am sure there is a simple way around this, but I just can’t figure it out. I’m doing it with block coding and introducing makecode arcade to my under 16 coding group on Wednesday and I know this issue might come up.

Any advice would be greatly appreciated!

p.s I’ve only just started teaching myself to code to I am a proper noob.

The magic ingredients are array of all XX locations (that used to be called tiles rather than locations) and borrowing the sprite’s x/y value block to use on the value when you iterate over the aforementioned array with a for element block. The second part of that is not at all obvious to a Blocks programmer.

Example in https://makecode.com/_3FcKyyK8UgDj

arcade-No-Soup-For-You-v1-screenshot-code

I’m placing the sprites in the soupList array there in case I want to change them later in the code. You don’t need the array if you don’t need to refer back to the individual sprites.

arcade-No-Soup-For-You-v1-screenshot-simoutput1

2 Likes

Thank you so much! I was sure I needed the array for location block but just couldnt figure out how to make it work. That’s perfect. I appreciate the time you’ve taken to answer me!

Great response; to add on a bit, if you want to ‘hide’ the places you put the sprites at, you change the tile back to blend in with the background after placing it:

The code in that snippet behaves the same as the snippet above besides changing the tile back, but I did switch a few things to give alternative approaches:

  • instead of using each location’s x and y positions, I used the place {sprite} on top of {location} block – this does the exact same thing as set {sprite} position to..., but should be a bit easier to read
  • instead of building up an array, you can always use the array of sprites of kind block to get all the sprites in the game of a given type that currently exist - this can help a lot in cases where certain sprites may be destroyed / added over time, as you won’t have to remember to maintain the list everywhere you go :slight_smile:
2 Likes

AH! That’s really helpful, thank you. I hadn’t realised I could change the tile to blend in with the rest, I’ll definitely do that. That also solves a new issue I was having with destroying the food sprite after the player sprite overlapped it. Thanks a million!