Zdravím,
mám úkol do školy, a to udělat hru Pong. Hra mi jde, všechno funguje, ale potřeboval bych vědět, jak mám udělat, aby hra nezačal rovnou po spuštění programu, ale aby se na obrazovce objevilo "Press any key to continue" nebo něco takového. BTW. zatím to programujem jen v codeskulptor.org.
Dík moc.
Vasary
#Pong hra
import simplegui
import random
height = 400
width = 600
score_1 = 0
score_2 = 0
ball = 10
ball_vel = [random.choice([-3,3]),random.choice([-3,3])]
bod1 = [width/2, height/2]
bod2 = [0,0]
palka_width = 10
palka_height = 60
palka1 = height/2
palka2 = height/2
p2 = palka_height/2
vp1 = 0 #rychlost palka1
vp2 = 0 #rychlost palka2
def click():
global message, bod1, ball_vel, score_1, score_2, palka1, palka2
bod1 = [300,200]
ball_vel = [random.choice([-3,3]),random.choice([-3,3])]
score_1 = 0
score_2 = 0
palka1 = height/2
palka2 = height/2
def klavesaON(key):
global bod1, vp1, vp2
if (key == simplegui.KEY_MAP["up"]):
vp2 = vp2 - 3
if (key == simplegui.KEY_MAP["down"]):
vp2 = vp2 + 3
if (key == simplegui.KEY_MAP["w"]):
vp1 = vp1 - 3
if (key == simplegui.KEY_MAP["s"]):
vp1 = vp1 + 3
def klavesaOFF(key):
global vp2, vp1
if (key == simplegui.KEY_MAP["up"]):
vp2 = 0
if (key == simplegui.KEY_MAP["down"]):
vp2 = 0
if (key == simplegui.KEY_MAP["w"]):
vp1 = 0
if (key == simplegui.KEY_MAP["s"]):
vp1 = 0
def draw(canvas):
global palka2, bod1, ball_vel, score_1, score_2
#vykresleni skore a stredove cary
canvas.draw_text(str(score_1), [width / 2 -40,40],48,"green")
canvas.draw_text(str(score_2), [width / 2 + 20,40],48,"blue")
canvas.draw_line([width/2,0], [width/2,height],4,"Grey")
global palka1
palka1 = palka1 + vp1
palka2 = palka2 + vp2
canvas.draw_line([0,palka1 - p2], [0,palka1 + p2], palka_width, "green")
canvas.draw_line([width,palka2 - p2], [width,palka2 + p2], palka_width, "blue")
if (palka1 - p2) <=0:
palka1 = p2
if (palka2 - p2) <=0:
palka2 = p2
if (palka1 + p2) >=height:
palka1 = height - p2
if (palka2 + p2) >=height:
palka2 = height - p2
if ((bod1[0] - ball) <= 0+palka_width/2):
if (bod1[1] <= palka1 + palka_height/2) and (bod1[1] >= palka1 - palka_height/2):
ball_vel[0] = -ball_vel[0]
if ((bod1[1] - ball) <= 0):
ball_vel[1] = -ball_vel[1]
if ((bod1[0] + ball) >=width-palka_width/2):
if (bod1[1] <= palka2 + palka_height/2) and (bod1[1] >= palka2 - palka_height/2):
ball_vel[0] = -ball_vel[0]
if ((bod1[1] + ball) >=height):
ball_vel[1] = -ball_vel[1]
if (bod1[0] - ball/2) <= 0:
bod1 = [300,200]
ball_vel = [+3,random.choice([-3,3])]
score_2 = score_2 + 1
palka1 = height/2
palka2 = height/2
if (bod1[0] + ball/2) >= width:
bod1 = [300,200]
ball_vel = [-3,random.choice([-3,3])]
score_1 = score_1 + 1
palka1 = height/2
palka2 = height/2
bod1[0]= bod1[0] + ball_vel[0]
bod1[1]= bod1[1] + ball_vel[1]
global bod2
bod2= [bod1[0] + 50, bod1[1] + 10]
tloustka = 3
canvas.draw_circle(bod1,ball,3,"pink", "white")
frame = simplegui.create_frame("Home", width, height )
frame.add_button("Reset", click)
frame.set_draw_handler(draw)
frame.set_keyup_handler(klavesaOFF)
frame.set_keydown_handler(klavesaON)
frame.start()