ArcBasicDocs

tutorials/beginner

10_coins.abs

46 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.

Download 10_coins.absAll files in this folder

10_coins.abs
; Catch the coins: collisions, a score and a time limitGraphics 640, 480SetBuffer BackBuffer()SeedRnd MilliSecs()basketX = 290coinX = Rand(20, 600) : coinY = 0score = 0endTime = MilliSecs() + 30000       ; MilliSecs counts in thousandths of a second: this is 30 seconds awayWhile 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	FlipWendEnd