; Catch the coins: collisions, a score and a time limit Graphics 640, 480 SetBuffer BackBuffer() SeedRnd MilliSecs() basketX = 290 coinX = Rand(20, 600) : coinY = 0 score = 0 endTime = MilliSecs() + 30000 ; MilliSecs counts in thousandths of a second: this is 30 seconds away While Not KeyHit(1) timeLeft = (endTime - MilliSecs()) / 1000 If timeLeft < 0 Then timeLeft = 0 If timeLeft > 0 ; move the basket If KeyDown(203) And basketX > 0 Then basketX = basketX - 7 If KeyDown(205) And basketX < 580 Then basketX = basketX + 7 ; the coin falls coinY = coinY + 4 ; caught it? Do the basket's and the coin's rectangles overlap? If RectsOverlap(basketX, 440, 60, 20, coinX, coinY, 20, 20) score = score + 1 coinX = Rand(20, 600) : coinY = 0 EndIf ; missed it: a new coin starts at the top If coinY > 480 Then coinX = Rand(20, 600) : coinY = 0 EndIf Cls Color 255, 210, 0 Oval coinX, coinY, 20, 20 Color 120, 200, 255 Rect basketX, 440, 60, 20 Color 255, 255, 255 Text 10, 10, "Score: " + score Text 560, 10, "Time: " + timeLeft If timeLeft = 0 Then Text 320, 220, "Time's up! You caught " + score + " coins.", True, True Flip Wend End