Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setup()
- randomize()
- end
- function randomize()
- gravity = math.random(1)
- holeX = math.random(0,WIDTH)
- ballX = math.random(0,WIDTH)
- ballVertVelo = math.random(-50,10)
- ballSize = math.random(25,300)
- holeHoriVelo = math.random(-20,20)
- ballHoriVelo = math.random(-20,20)
- ballY = math.random(ballSize,HEIGHT)
- end
- function draw()
- -- clear screen to blue
- background(188, 189, 223, 255)
- -- draw the ground
- fill(56, 133, 29, 255) -- green
- noStroke()
- rect(0,0, WIDTH, 50)
- -- draw the hole
- fill(0)
- rect(holeX - ballSize/2,5,ballSize * 1.5,35)
- -- draw the ball shadow
- noStroke()
- fill(0, 0, 0, 122)
- ellipse (ballX, 25, ballSize * 0.8 + ballY/10, math.min(ballY/20,50))
- -- draw the ball
- fill(255, 0, 0, 255) -- ball colour (red)
- stroke(153, 26, 33, 255) -- ball outline colour (red)
- strokeWidth(3) -- outline thickness
- ellipse (ballX, ballY, ballSize)
- -- draw ball highlight
- stroke(223, 173, 171, 255)
- fill(255, 255, 255, 255)
- ellipse (ballX + 0.15 * ballSize, ballY + 0.2 * ballSize, ballSize * 0.4)
- -- bounce ball off walls
- if ballX < 0 or ballX >= WIDTH then
- ballHoriVelo = -ballHoriVelo
- end
- -- bounce hole off walls
- if holeX < ballSize/2 then
- holeHoriVelo = -holeHoriVelo
- holeX = ballSize/2
- elseif holeX > WIDTH - ballSize then
- holeHoriVelo = -holeHoriVelo
- holeX = WIDTH - ballSize
- end
- -- bounce ball off the ground (but not the hole)
- if ballY < 25 + ballSize/2 and (ballX >= holeX + ballSize or ballX <= holeX - ballSize) then
- sound(DATA, "ZgBAPgAfOF4fKi1AjVEFPgAAAABoZUk+CQBqfyM/R0ASQEBF")
- ballVertVelo = ballVertVelo - 2 * ballVertVelo
- else
- ballVertVelo = ballVertVelo - gravity
- end
- -- fall through hole
- if ballY > 0 then
- ballX = ballX + ballHoriVelo
- ballY = ballY + ballVertVelo
- holeX = holeX + holeHoriVelo
- else
- sound(SOUND_PICKUP, 24328)
- randomize()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement