Like this?
physics t (b, w1, w2, w1x, w2x) = if w1x < w2x then
                           ({ b | y = b.y + t*b.vy , x = b.x + t*b.vx }, 
                           w1 |> move (5,0),
                           w2 |> move (-5,0),
                           w1x + 5,
                           w2x - 5
                           )                       
                           else if (bird.x < w1x || bird.x > w2x )then
                           (b, w1, w2)
                           else
                           (b, w1, w2, w1x, w2x)

在 2016年6月21日星期二 UTC+8下午12:09:03,Nick H写道:
>
> You will need to add another if-else condition to your physics function, 
> where you compare b.x with w1x and w2x.
>
> On Mon, Jun 20, 2016 at 8:47 PM, <cass...@gmail.com <javascript:>> wrote:
>
>> Below is my whole code. The wall is moving. I wonder know how to 
>> determine whether the bird touch the two walls. The bird will die if it 
>> touch the walls when the walls stop moving. 
>>
>>
>>
>>
>> import Color exposing (..)
>> import Graphics.Collage exposing (..)
>> import Graphics.Element exposing (..)
>> import Keyboard
>> import Text
>> import Time exposing (..)
>> import Window
>>
>> -- SIGNALS
>>
>> bird = { x=0, y=0, vx=0, vy=0 }
>>
>> -- moves the walls only
>> physics t (b, w1, w2, w1x, w2x) = if w1x < w2x then
>>                            ({ b | y = b.y + t*b.vy , x = b.x + t*b.vx }, 
>>                            w1 |> move (5,0),
>>                            w2 |> move (-5,0),
>>                            w1x + 5,
>>                            w2x - 5
>>                            )                       
>>                            else 
>>                            (b, w1, w2, w1x, w2x)
>>
>> -- moves the bird only
>> walk {x,y} (b, w1, w2, w1x, w2x) = ({ b | vx = toFloat x, vy = toFloat y 
>> }, w1, w2, w1x,  w2x)
>>
>> step (dt, keys) =
>>   walk keys >> physics dt
>>
>> (gameWidth,gameHeight) = (500,500)
>>
>>
>> wall1 = toForm (collage gameWidth gameHeight
>>   [   rect 100 100 |> filled (rgb 250 230 0) |> move (50-gameWidth/2, 
>> gameHeight/2-50)
>>       ,rect 80 100  |> filled (rgb 250 230 0) |> move (40-gameWidth/2, 
>> gameHeight/2-150)
>>       , rect 50 100  |> filled (rgb 250 230 0) |> move (25-gameWidth/2, 
>> gameHeight/2-250)
>>       , rect 100 100 |> filled (rgb 250 230 0) |> move (50-gameWidth/2, 
>> gameHeight/2-350)
>>       , rect 80 100  |> filled (rgb 250 230 0) |> move (40-gameWidth/2, 
>> gameHeight/2-450)
>>       
>>   ])
>>   
>> wall2 = toForm (collage gameWidth gameHeight
>>      [ rect 100 100 |> filled (rgb 250 230 0) |> move (gameWidth/2-50, 
>> gameHeight/2-50)
>>       , rect 120 100  |> filled (rgb 250 230 0) |> move (gameWidth/2-60, 
>> gameHeight/2-150)
>>       , rect 50 100  |> filled (rgb 250 230 0) |> move (gameWidth/2-25, 
>> gameHeight/2-250)
>>       , rect 100 100 |> filled (rgb 250 230 0) |> move (gameWidth/2-50, 
>> gameHeight/2-350)
>>       , rect 120 100  |> filled (rgb 250 230 0) |> move (gameWidth/2-60, 
>> gameHeight/2-450)])     
>>
>>
>> render (w',h') (bird, wall1, wall2, w1x, w2x) =
>>   let (w,h) = (toFloat w', toFloat h')
>>       src = "bee.PNG" 
>>   in collage w' h'
>>
>>       [ rect gameWidth gameHeight |> filled (rgb 174 238 238)
>>       , toForm (image 50 50 src) |> move (bird.x, bird.y)
>>       , wall1
>>       , wall2
>>       -- text (Text.fromString (toString (w1x, w2x)))
>>       ]  
>>
>>
>> -- bird
>> input = let delta = Signal.map (\t -> t/10) (fps 10)
>>         in  Signal.sampleOn delta (Signal.map2 (,) delta Keyboard.arrows)
>>
>> main = Signal.map2 render Window.dimensions (Signal.foldp step (bird, 
>> wall1, wall2, -gameWidth/2 + 100, gameWidth/2 - 100) input)
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to