# Simppeli pinkiponki by marGoira
import turtle
wn = turtle.Screen()
wn.title("Pinkiponki by marGoira")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)
# Tulos
score_a = 0
score_b = 0
# Maila A
maila_a = turtle.Turtle()
maila_a.speed(0)
maila_a.shape("square")
maila_a.color("blue")
maila_a.shapesize(stretch_wid=5, stretch_len=1)
maila_a.penup()
maila_a.goto(-350, 0)
# Maila B
maila_b = turtle.Turtle()
maila_b.speed(0)
maila_b.shape("square")
maila_b.color("red")
maila_b.shapesize(stretch_wid=5, stretch_len=1)
maila_b.penup()
maila_b.goto(350, 0)
# Pallo
pallo = turtle.Turtle()
pallo.speed(0)
pallo.shape("square")
pallo.color("white")
pallo.penup()
pallo.goto(0, 0)
pallo.dx = 0.1
pallo.dy = 0.1
# Pen
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 260)
pen.write("USA: 0 SOVIET: 0", align="center", font=("Courier", 24, "normal"))
# Funktiot
def maila_a_up():
y = maila_a.ycor()
y += 20
maila_a.sety(y)
def maila_a_down():
y = maila_a.ycor()
y -= 20
maila_a.sety(y)
def maila_b_up():
y = maila_b.ycor()
y += 20
maila_b.sety(y)
def maila_b_down():
y = maila_b.ycor()
y -= 20
maila_b.sety(y)
# Näppäimistö
wn.listen()
wn.onkeypress(maila_a_up, "w")
wn.onkeypress(maila_a_down, "s")
wn.onkeypress(maila_b_up, "Up")
wn.onkeypress(maila_b_down, "Down")
# Main game loop
while True:
wn.update()
# Pallon liike
pallo.setx(pallo.xcor() + pallo.dx)
pallo.sety(pallo.ycor() + pallo.dy)
# Rajojen tarkastaminen
if pallo.ycor() > 290:
pallo.sety(290)
pallo.dy *= -1
if pallo.ycor() < -290:
pallo.sety(-290)
pallo.dy *= -1
if pallo.xcor() > 390:
pallo.goto(0, 0)
pallo.dx *= -1
score_a += 1
pen.clear()
pen.write("USA: {} SOVIET: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal"))
if pallo.xcor() < -390:
pallo.goto(0, 0)
pallo.dx *= -1
score_b += 1
pen.clear()
pen.write("USA: {} SOVIET: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal"))
# mailan ja pallon yhteentörmäys
if (pallo.xcor() > 340 and pallo.xcor() < 350) and (pallo.ycor() < maila_b.ycor() + 40 and pallo.ycor() > maila_b.ycor() -40):
pallo.setx(340)
pallo.dx *= -1
if (pallo.xcor() < -340 and pallo.xcor() > -350) and (pallo.ycor() < maila_a.ycor() + 40 and pallo.ycor() > maila_a.ycor() -40):
pallo.setx(-340)
pallo.dx *= -1
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}