Variable speed pong
This commit is contained in:
parent
628e55d20c
commit
4bb046cffc
11
apps/pong.py
11
apps/pong.py
@ -13,6 +13,11 @@ Nx = int(sys.argv[1])
|
||||
Ny = int(sys.argv[2])
|
||||
param = sys.argv[3]
|
||||
|
||||
speed = 1.0
|
||||
try:
|
||||
speed = float(param)
|
||||
except:
|
||||
pass
|
||||
|
||||
pygame.init()
|
||||
pygame.joystick.init()
|
||||
@ -40,7 +45,7 @@ def Reset(sign=1):
|
||||
y = Ny//2
|
||||
dy = 1*sign
|
||||
dx = random.uniform(-0.4, 0.4)
|
||||
l = math.sqrt(dx*dx+dy*dy)
|
||||
l = math.sqrt(dx*dx+dy*dy)/speed
|
||||
dx /= l
|
||||
dy /= l
|
||||
|
||||
@ -86,7 +91,7 @@ while True:
|
||||
if xi >= player1 and xi <= player1+PADDLE_LEN:
|
||||
dy = -1
|
||||
dx = x-(player1+PADDLE_LEN/2)
|
||||
l = math.sqrt(dx*dx+dy*dy)
|
||||
l = math.sqrt(dx*dx+dy*dy)/speed
|
||||
dx /= l
|
||||
dy /= l
|
||||
|
||||
@ -99,7 +104,7 @@ while True:
|
||||
if xi >= player2 and xi <= player2+PADDLE_LEN:
|
||||
dy = 1
|
||||
dx = x-(player2+PADDLE_LEN/2)
|
||||
l = math.sqrt(dx*dx+dy*dy)
|
||||
l = math.sqrt(dx*dx+dy*dy)/speed
|
||||
dx /= l
|
||||
dy /= l
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user