Created
November 19, 2008 01:02
-
-
Save ecarnevale/26358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Pong Challenge, copycat version | |
# | |
# Created by Emanuel Carnevale on 2008-11-18. | |
# Shamelessly adapted by http://billmill.org/pong.html | |
Shoes.app :width => 400, :height => 400, :resizable => false do | |
paddle_size = 75 | |
v_x, v_y = [3,4] | |
p_x, p_y = [10,10] | |
bounce = 1.2 | |
ball_diameter = 20 | |
paddle_size = 75 | |
points = [] | |
computer = app.width / 2 | |
compuspeed = 30 | |
paddle1 = rect computer, 0, paddle_size, 4 | |
paddle2 = rect app.width/2, app.height-4, paddle_size, 4 | |
ball = oval(p_x, p_y, ball_diameter, ball_diameter) | |
animate do | |
if not -ball_diameter < p_y and p_y < app.height + ball_diameter | |
clear | |
para "Game Over" | |
if p_y < 0 | |
para "You win!" | |
else | |
para "Computer wins" | |
end | |
return | |
end | |
button, left, top = self.mouse | |
paddle_left = [[left,0].min,400-paddle_size].max | |
ny = p_y + v_y | |
nx = p_x + v_x | |
if nx + (ball_diameter/2) > computer + paddle_size | |
computer += compuspeed | |
elsif nx < computer | |
computer -= compuspeed | |
end | |
paddle1.move(computer,0) | |
one = (ny + ball_diameter) > app.height | |
two = v_y > 0 | |
three = paddle_left < (nx + (ball_diameter / 2)) | |
four = (nx + (ball_diameter / 2)) < (paddle_left + paddle_size) | |
if one and two and three and four | |
v_y = -v_y * bounce | |
v_x = (nx - paddle_left - (paddle_size / 2)) * 0.25 | |
ny = app.height - ball_diameter | |
end | |
if ny < 0 and v_y < 0 and computer < nx + (ball_diameter / 2) and nx + (ball_diameter / 2) < computer + paddle_size | |
v_y = -v_y * bounce | |
v_x = (nx - computer - (paddle_size / 2)) * 0.25 | |
ny = 0 | |
elsif nx + ball_diameter > app.width or nx < 0 | |
v_x = -v_x | |
end | |
mx = [0, [left, app.width - paddle_size].min].max | |
paddle2.move(mx,app.height-4) | |
p_x = nx | |
p_y = ny | |
ball.move(p_x, p_y) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment