Computer Science Canada

applying delay to a specific part of a loop

Author:  neverstopbelevin [ Thu Nov 18, 2010 7:28 pm ]
Post subject:  applying delay to a specific part of a loop

in my code, im trying to get a maple leaf to appear in a random location and the user must click it to win.

the problem is that if i delay the time it takes for a maple leaf to show up, i must delay the movement of the mouse, however I do not want to delay the mouse movement, only the amount of time it takes for a maple leaf to show up.

code:

loop
    cls
    a := Rand.Int (0, maxx)
    b := Rand.Int (0, maxy)
    c1 := a + 50
    d := b + 50
    drawfillmapleleaf (a, b, c1, d, red)
    mousewhere (mx, my, mb)
    drawline (mx - maxx, my, mx + maxx, my, red)
    drawline (mx, my - maxy, mx, my + maxy, black)
    if mb = 1 and
            whatdotcolour (mx, my) = red
            then
        put "You Win"
        exit when whatdotcolour (mx, my) = red
    end if
    View.Update
end loop

Author:  TerranceN [ Thu Nov 18, 2010 7:37 pm ]
Post subject:  RE:applying delay to a specific part of a loop

Create a counter outside your loop and increment it every time your loop goes around. Use an if statement so that once that counter gets above a certain value, it moves the maple leaf and resets the counter back to 0.

Author:  neverstopbelevin [ Thu Nov 18, 2010 8:08 pm ]
Post subject:  RE:applying delay to a specific part of a loop

okay, thats solved

Author:  neverstopbelevin [ Thu Nov 18, 2010 8:25 pm ]
Post subject:  RE:applying delay to a specific part of a loop

thhanks


: