Fling at random objects from list- make objects disappear when collided

53 views
Skip to first unread message

veronica stanley-hooper

unread,
May 26, 2017, 4:51:12 PM5/26/17
to MIT App Inventor Forum
Hello,

Can anyone point me to a tutorial where an object if flung at a random object selected from a list and the object disappears? I have a list of approximately 10 different objects that are randomly selected and displayed in groups of 1, 2 or 3. I want the user to fling an object at the grouping and when it collides with any object in that grouping the entire grouping disappears.

Thanks in advance,
Veronica

SteveJG

unread,
May 26, 2017, 5:10:09 PM5/26/17
to MIT App Inventor Forum
What have you tried?       This will help  

SteveJG

unread,
May 26, 2017, 9:29:11 PM5/26/17
to MIT App Inventor Forum
Here is a tutorial that shows how to fling and to make the 'target' disappear.....    http://appinventor.mit.edu/explore/ai2/get-gold.html

Abraham Getzler

unread,
May 27, 2017, 9:58:49 PM5/27/17
to MIT App Inventor Forum
The group disappearance can be handled using a 
value procedure that accepts a sprite component and returns
a group number for that sprite.

Say Sprites P1,P2,P3 belong to group 1,
P4,P5 belong to group 2,
P6,P7,P8 belong to group 3 ...

value procedure GROUP(sprite) returns (result)
  return lookupInPairs(
                  item: sprite, 
                  list: make a list(
                            make a list(p1,1),
                            make a list(p2,1),
                            make a list(p3,1),
                            make a list(p4,2),
                            make a list(p5,2),
                            make a list(p6,3),
                            make a list(p7,3),
                            make a list(p8,3)))


So your collision event of sprite Bullet5 hits other
  would be 
    for each targetSprite in list  allTargetSprites   <=== fill it at Screen.Initialize
         if group(other) = group(targetSprite) then
            setAnySprite.Visible (targetSprite, false)
         end if
end for each

You could code a common procedure hideOtherGroup(other)
and just call that procedure from each projectile collision event.

ABG

veronica stanley-hooper

unread,
May 29, 2017, 12:01:18 PM5/29/17
to MIT App Inventor Forum
Thank you for your detailed response. I am just a novice at App Inventor, so while I understand your statement above I am not sure how to apply your solution to the coding blocks.

Sincerely,
Veronica

veronica stanley-hooper

unread,
May 29, 2017, 12:01:43 PM5/29/17
to MIT App Inventor Forum
Thank you for the reference.

Abraham Getzler

unread,
May 29, 2017, 12:15:26 PM5/29/17
to MIT App Inventor Forum
post an .aia file?
ABG

veronica stanley-hooper

unread,
May 29, 2017, 12:17:25 PM5/29/17
to MIT App Inventor Forum
Working on this now. Will post when I have more complete. Thank you.

SteveJG

unread,
May 29, 2017, 12:47:45 PM5/29/17
to mitappinv...@googlegroups.com
The attached does some of what you said you wanted to do one way.  There are lots of ways to do this.
This way is simple.

Oh, forgot ... throw the green block at any of the red ones.

Regards,
Steve
Fling.aia

veronica stanley-hooper

unread,
May 29, 2017, 3:09:05 PM5/29/17
to MIT App Inventor Forum
Steve and ABG--

Steve, your example helped. The list of "or" and "=" was too long (11 items) so I took a bit of ABG's idea (made a global list of the items), then called up the list with the "is in list? thing  / list" block. See attached. It has worked for me so far, do you see any issues with doing it this way?

Thanks,

Veronica
(I am really learning a lot from this forum's helpful leaders!!!!) :)

screenshot of collide list for multiples.png

Abraham Getzler

unread,
May 29, 2017, 6:21:10 PM5/29/17
to MIT App Inventor Forum
This sample app shows how to reuse the same screen for different puzzles,
by using the image names in the sprites, as opposed to using the sprite
identities themselves ...

Using the image file names lets you load new puzzles from files.

It helps you avoid the severe AI2 screen count limits.

ABG

SteveJG

unread,
May 29, 2017, 7:08:44 PM5/29/17
to MIT App Inventor Forum
What you posted looks fine Veronica.  There are many ways to code this.  You code works and I would stick with it.  You could get fancier using the 'advanced' ImageSprite blocks but I am not convinced the App performance would be different.  For the moment, I recommend staying with what works and as always, before you change something that is working...save a copy.

"I am just a novice at App Inventor"--hmm not many novices would come up with the idea of using a list solution and implement it on your own.   Sometimes even advanced programmers can use a nudge.

Good luck with your Math game...students would love it.

--Steve

veronica stanley-hooper

unread,
May 30, 2017, 4:58:12 PM5/30/17
to MIT App Inventor Forum
Thanks Steve...now onto the next part. Adding the score keep with a Tiny DB and an 'animation' to show how the game is played! (You'll probably be seeing me around the forum again. LOL.)
Reply all
Reply to author
Forward
0 new messages