Help with somewhat difficult Battleship type game please

I have a student trying to make a battleship game.
Right now the ships are randomly generated and in groups.
The main issue we’re having right now is having the ability to click on a ship.
We’re mainly looking at ship1 which is the single ship.
Line 68 is an if statement that I can’t figure out. It seems to me that it should work, but doesn’t. I’d love to know if someone can tell me why and maybe a solution to this.

Link to the project or level: [Code.org - Game Lab]

I played around with this didn’t find a perfect solution and I can’t really see what is wrong with the line either. I was able to do something similar by comparing the x and y values of the mouse and the Sprite.

It kind of has me stumped, but here is my workaround that at least makes the sprite disappear when it’s moused over and the left button is clicked.

Hope this helps a little.

Mike

Very interesting workaround, Mike. I will show it to my student. I think a workaround like this is very educational as it seems to me that sometimes you have to go this route. In a way, it’s basically using math to do something that the program should be able to do with another(more simple) line of code.

With that said, if anyone can tell me why the previous method doesn’t work, I would love to know. I feel like there’s some little thing we’re missing.
I won’t change the remix I put in the original message to see if anyone can solve this mystery.

Thanks again, Mike!

1 Like

Yes, I agree. It’s one level of abstraction removed to manually calculate the “collision”. I’m guessing the “mouse clicked over” does something very similarly, but for whatever reason just isn’t working in this project. Could be a bug or more likely, like you say, there’s some little thing we’re missing … lol.

Mike

1 Like