Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block for get closest and farthest of kind #5

Open
UnsignedArduino opened this issue Dec 15, 2020 · 3 comments
Open

Block for get closest and farthest of kind #5

UnsignedArduino opened this issue Dec 15, 2020 · 3 comments

Comments

@UnsignedArduino
Copy link

Hi!

First off, I would like to say that this is an amazing extension. It really simplifies the math needed in complex games!

Anyways, so the main reason I use this block:
image
is to find the closest or farthest sprite of a certain kind from a sprite. I was thinking of a block like:

closest sprite of kind [kind] from [sprite] with a minimum distance of [number]

and it would return a sprite, or null if there aren't any sprites of that kind. number could be hidden behind a + sign or you could pass in null in TypeScript to not have a minimum distance. And also maybe the farthest sprite like this:

farthest sprite of kind [kind] from [sprite] with a maximum distance of [number]
@jwunderl
Copy link
Owner

jwunderl commented Dec 16, 2020

Hmm @UnsignedArduino could you point me to some examples of doing this real quick? I can see the value in it, just want to see use cases where you'd use it, in case there are other options / factors we can consider; e.g. I could see some use cases could benefit from having 'n' nearest sprites (in which case I'd want to use https://github.com/jwunderl/pxt-heap to find the closest / furthest sprites, which can be done quite efficiently), but that makes the block a little more tedious to use if someone is looking for only one sprite.

@UnsignedArduino
Copy link
Author

In my tower defense game, I could find the closest enemy or the farthest enemy, or maybe even just checking if there is something within a certain range by checking if a sprite is returned. Or maybe a shark that is trying to eat the closest fish, which wouldn't need a range anyway, so we could pass in null or a number less than or equal to 0.

I could see some use cases could benefit from having 'n' nearest sprites

This is also a great idea too, but having a get all sprites within [number] pixels from [sprite] seems to be more useful to me, like for instance getting which enemy has the most health within a certain distance, or destroying all the sprites within a certain radius because of an explosion. You probably would want the closest sprite as element 0 in the array returned and the farthest sprite in the radius as the last element in the array.

@jwunderl
Copy link
Owner

(get all sprites within [number] pixels from [sprite] implemented by @livcheerful as of v0.1.0:

image

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants