Microsoft MakeCode

Why doesn't my code work?

value is a location, not a tile.

How can I fix this?

I don’t know how to fix it. :frowning:

Hi, @GameGod !

It looks like you’re trying to figure out which tile a sprite is on. I don’t think there’s an easy way to do this with blocks. I think you need to use some math to figure it out.

You can find the coordinates of the sprite. Because we know that tiles are 16 pixels wide and 16 pixels tall, we can figure out which tile the sprite is on, too. Once you know which tile the sprite is on, you can test for which kind of tile it is. I used a sprite say statement so that I could see how the values changed as I moved the car around.

If you’re still stuck, or if I misunderstood what you were trying to do, let us know. Good luck!

This is epic! Thanks for the help, @AlexK and @UnsignedArduino !

1 Like
  1. I just have a few more questions. How can I do this for sprites with dimensions of 16x32 or 16x48? I tried adding another if statement at the end and changing the values in it, but it seems to not work.

  2. How can I turn off a tile’s wall property if there is no sprite on it? Basically, I want walls on every sprite so the other sprites can’t pass. Here is my code so far. Thanks in advance.

First, I must say that I love this idea for the Game Jam!

So, I figured out how to turn the walls on and off. I only worked on Limo H3 just to work out some thoughts.

Then, I realized there was a problem. :smiley:

If you try to turn the walls on in the double-loop, then Limo H3 also can’t move. Because it’s hitting a wall. :slight_smile:

I think, instead of trying to turn walls on and off, you’re better bet instead will be to handle when two cars overlap. When two cars overlap, figure out which car is moving and then stop it from moving.

Good luck!

Ok! I actually am working on a new way to do it using for loops and on button pressed.

.

2 Likes