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.

-- 

Why is Near Field Communication (NFC) range limited to about 20cm?


Near Field Communication (NFC) operates at 13.56 MHz.
Near Field is the region situated at a distance r << λ
λ = c/f
c = 299 792 458 m/s in the vacuum.
f = 13.56 MHz = 13.56*10^6 Hz
λ = 299.8/13.56 = 22.11 m
Of this distance, the Reactive Near field is commonly considered λ/2π. For NFC, this would be 3.51 m.
So where do the 20 cm come from?

--
Corresponding wavelength is 22.11 meters long, but we want also to emit our EM waves into the environment. This means if we get a nice half-wave dipole antenna we would need it about 11 meters in length, 
λ/2. Which is quite large for mobile device.
Ok, lets reduce size by using quarter-wave antenna as in WiFi, based on ideas of quarter-wave impedance transformer, and we get 5.53m, λ/4, which is still unacceptable from size perspective.
Maybe, we should use another antenna type? First thought to use antenna for smartphones is to use a loop antenna on the phones rim.
Theory
Maybe, we should not only switch kind of antenna, but idea of emitting data to environment. And here comes RFID antennas, as a kind of loop antennas. Note, NFC is totally based on advances in area of RFID.
Two different RFID design approaches exist for transferring energy from the reader to the tag: magnetic induction and electromagnetic wave capture. The two designs make use of these approaches and are called near field and far field:
Near field RFID
Near field RFID uses magnetic induction between a reader and a transponder. While an RFID is generating a magnetic field in its location, it passes an alternating current through a reading coil. If an RFID tag with a smaller coil is placed within range of the reader, the alternating voltage appears across it and the magnetic field is affected by data stored on the tag. The voltage is rectified and powers the tag. As it is powered, the data are sent back to the reader using load modulation.
enter image description here

Far field RFID
Tags using far field principles operate above 100 MHz, typically in the >865–915 MHz range up to 2.45 GHz. They use backscatter coupling operating principles. In far field the reader’s signal is reflected and it is modulated to an alternating potential difference in order to transmit data. The system’s range is limited by the energy transmission sent by the reader. Due to advances in semiconductor manufacturing, the energy required to power a tag continues to decrease. The possible maximum range increases accordinglyenter image description hereNear Field Communication (NFC): From Theory to Practice, by Vedat Coskun
Calculations:
loop
We are interested in near field, so consider magnetic field produced by a circular loop antenna:
 Bz=μ0INa2/2(a2+r2)3/2 ,
where I- current, r-distance from the center of wire, μ0 - permeability of free space and given as 4π107 (Henry/meter), a-radius of loop

The maximum magnetic flux that is passing through the tag coil is obtained when the two coils (reader coil and tag coil) are placed in parallel with respect to each other.
An optimum coil diameter that requires the minimum number of ampere-turns for a particular read range can be found from previous equation such as:
 NI=K(a2+r2)3/2/a2 , K=2Bz/μ0
By taking derivative with respect to the radius a,
 d(NI)/da=K3/2(a2+r2)1/2(2a3)2a(a2+r2)3/2/a4=K(a22r2)(a2+r2)1/2/a3
the above equation becomes minimized when:
 a=2r

The result indicates that the optimum loop radius, a, is 1.414 times the demanded read range r.
In detail you can read this with complex equations for spiral loops and different sizes of loop.
And consider that 20cm read range will yield loop 28.8cm, which is more acceptable for tablets than phones.

--