2017년 5월 29일 월요일

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


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.

--
What have you tried?       This will help  

-- 
Here is a tutorial that shows how to fling and to make the 'target' disappear.....    Get the Gold for App Inventor 2

-- 
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.

-- 
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.

--
post an .aia file?

-- 
Working on this now. Will post when I have more complete. Thank you.

-- 
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.


-- 
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?



--
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.

-- 
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.

-- 

댓글 없음:

댓글 쓰기