1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# breakout program
# 2010-06-13 j.m.reneau
# sound samples used in this program were downloaded from freesound.org
print "use mouse to bounce ball on paddle."
color black
rect 0,0,300,300
blocks = 24 # number of blocks
dx = 1 # initial ball speed
dy = 1
speedup = .2 # how much faster after each paddle strike
ball = blocks + 1 # sprite numbers for ball and paddle
paddle = blocks
spritedim blocks + 2
spriteload ball, "ball.png"
spriteplace ball,100,100
spriteshow ball
spriteload paddle, "paddle.png"
spriteplace paddle,150,270
spriteshow paddle
for block = 0 to blocks - 1
col = block % 6 * 50 + 25
row = block \ 6 * 10 + 5
spriteload block, "block.png"
spriteplace block, col, row
spriteshow block
next block
blocksleft = blocks
while spritey(ball) < 295 and blocksleft > 0
spriteplace paddle, mousex, spritey(paddle)
if spritex(ball) < 5 or spritex(ball) > 295 then
dx = dx * -1
wavplay "4361__NoiseCollector__pongblipA_3.wav"
end if
if spritey(ball) < 5 then
dy = dy * -1
wavplay "4361__NoiseCollector__pongblipA_3.wav"
end if
if spritecollide(ball, paddle) then
# bounce back and speed up the falling a bit
dy = (dy + speedup) * -1
dx = dx + ((spritex(ball)-spritex(paddle))/(spritew(paddle/2)))
wavplay "3062__SpeedY__bleep.wav"
end if
spritemove ball, dx, dy
blocksleft = 0
for block = 0 to blocks - 1
if spritev(block) then
blocksleft = blocksleft + 1
if spritecollide(block, ball) then
# hide blocks that the ball hit and send the ball bouncing back
spritehide(block)
dx = dx * -1
dy = dy * -1
wavplay "4359__NoiseCollector__PongBlipF4.wav"
end if
end if
next block
end while
print "game over."
|