My student would like to have their villain spawn where the money spawns every _ seconds. The goal is every time the villain collects money, the hero loses a heart. https://makecode.com/_R91P6mH0i2jR
Looks like right now they are using this code to make this happen:
That will set the villain and money to two different random positions on the map.
Instead, I would do something like this:
Here instead of setting the villain to a random position, I set the position to be the same as the money. I also went from using forever blocks to using “on game update every” blocks because they make a little bit more sense in this scenario. You want to be careful about having too many forevers in one project because they can slow things down!
An even better idea might be to make use of the “sprite follow” block. Then you can have the villain actually move towards the money and just reposition it when they catch it. Something like this:
In this code, the cat will constantly move towards the money. When the overlap happens, the money gets moved to a random ground tile. The “place on top of random tile” block is super useful in this instance because it makes sure the money never gets put on top of a wall where the cat can’t reach it.