Attempting to really dive into block coding (vs my go-to typescript coding) to see what the fuss is about but also prepare myself to help the kids I teach with debugging and such.
Anyway I have a simple missile and a target that the missile was set to to follow. The idea is that you shoot several of these missiles and they will explode when they reach their target (the target being the exact location I designated).
Currently the code:
- User presses A = place a target sprite on the screen
- Spawn a missile sprite and have it follow the target sprite
- When the target sprite and missile sprite collide, destroy both (animations aside)
The problem comes when a missile hits a target that isn’t it’s own. It’ll trigger the “On Collide” event and remove itself + the target BUT any missiles that were attempting to go to their target that’s now destroyed will stop… And then by extension the original target is left behind.
Visually this looks like:
It’s somewhat easy to link things together via objects in Typescript, I’m just trying to figure out how someone would accomplish something like this in blocks. Everything is a bit “global” and there’s been more than once where tieing other sprites or attributes to a sprite would be handy when you are listening to the collision events (since you only know about the sprites in those events).
The status bar extension has some of this with “sprite that status is attached to”. Something similar for basically creating objects would be awesome (and from my experience so far, likely exists already somewhere):
Typescript version (psudo code):
const missiles = []
// on A press
missiles.push({
missileSprite: sprites.create.....
targetSprite: sprites.create.....
})
// on sprites collide
missiles.find(m => {
// basically run through the list of missiles and find if
// the one we just hit is the one we are targeting
collisionSprite === m.targetSprite