I need help with a game in (turtle graphics - python)

Kasper kasperseidem.gamer at gmail.com
Wed Feb 22 05:27:12 EST 2017


Hi!

How can i make the score stop blinking and how can i make a high score table, in this game made with python? (this game is made on a Macbook)
(there are some files in the game that i don't haven't copied into this file! like pyth.GIF)

________________________________________________________________________________________________________________

#turtle game (take down the yellow astroides 1v1)
import turtle
import math
import random
import os

#asks for players name
print("player 1 uses W,A,S,D and player 2 are using arrow Up, Down, Left, Right.")
print("write player 1's name")
name1 = input()
print("write player 2's name")
name2 = input()




#set up screen
wn = turtle.Screen()
wn.bgcolor("black")
wn.bgpic("pyth.GIF")

#borders
mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-300)
mypen.pendown()
mypen.pensize(3)
mypen.color("white")
mypen.left(90)
mypen.forward(600)
mypen.right(90)
mypen.forward(600)
mypen.right(90)
mypen.forward(600)
mypen.right(90)
mypen.forward(600)
mypen.hideturtle()


#creates the scores
score1 = 0
score2 = 0


#create player 1
player = turtle.Turtle()
player.color("blue")
player.shape("triangle")
player.penup()
player.speed(0)
player.setposition(285, 285)


#create player 2
player2 = turtle.Turtle()
player2.color("white")
player2.shape("triangle")
player2.penup()
player2.speed(0)
player2.setposition(-285, -285)

#creats goals
maxGoals = 1
goals = []

for count in range(maxGoals):
    goals.append(turtle.Turtle())
    goals[count].color("yellow")
    goals[count].shape("circle")
    goals[count].penup()
    goals[count].speed(0)
    goals[count].setposition(random.randint(-290, 290), random.randint(-290, 290))

#set speed variable
speed = 3

#define functions
def turnleft():
    player.left(30)

def turnright():
    player.right(30)
    
def turnright2():
    player2.right(30)

def turnleft2():
    player2.left(30)

def up():
    player.forward(50)

def up2():
    player2.forward(50)

def down():
    player.right(180)
    
def down2():
    player2.right(180)

def speedup():
    global speed
    speed += 1

def stop():
    global speed
    speed = 0

def reset():
    goals[count].setposition(random.randint(-290, 290), random.randint(-290, 290))
    player.setposition(random.randint(-290, 290), random.randint(-290, 290))
    player2.setposition(random.randint(-290, 290), random.randint(-290, 290))

def isCollision(t1, t2):
    d = math.sqrt(math.pow(t1.xcor()-t2.xcor(),2) + math.pow(t1.ycor()-t2.ycor(),2))
    if d < 20:
        return True
    else:
        return False

#set keyboard bindings
turtle.listen()
turtle.onkey(turnleft, "a")
turtle.onkey(turnleft2, "Left")
turtle.onkey(turnright, "d")
turtle.onkey(turnright2, "Right")
turtle.onkey(speedup, "o")
turtle.onkey(stop, "b")
turtle.onkey(down, "s")
turtle.onkey(down2, "Down")
turtle.onkey(up, "w")
turtle.onkey(up2, "Up")
turtle.onkey(reset, "r")

while True:
    player.forward(speed)
    player2.forward(speed)

    #boundary checking player
    if player.xcor() > 290 or player.xcor() < -290:
        player.right(180)
        os.system("afplay bing.mp3&")
        
    #boundary Checking player
    if player.ycor() > 290 or player.ycor() < -290:
        player.right(180)
        os.system("afplay bing.mp3&")

    #boundary checking player2
    if player2.xcor() > 290 or player2.xcor() < -290:
        player2.right(180)
        os.system("afplay bing.mp3&")
        
    #boundary Checking player2
    if player2.ycor() > 290 or player2.ycor() < -290:
        player2.right(180)
        os.system("afplay bing.mp3&")


    #boundary checking
    if goals[count].xcor() > 290 or goals[count].xcor() < -290:
        goals[count].right(180)
        os.system("afplay bing.mp3&")

    #boundary Checking
    if goals[count].ycor() > 290 or goals[count].ycor() < -290:
        goals[count].right(180)
        os.system("afplay bing.mp3&")
            

    #move ball
    for count in range(maxGoals):
        goals[count].forward(1)



    #collision checking with goals
        if isCollision(player, goals[count]):
            goals[count].setposition(random.randint(-300, 300), random.randint(-300, 300))
            goals[count].right(random.randint(0,360))
            os.system("afplay yes.mp3&")
            score1 += 2
            speed += 0.5


    #collision checking with goals
        if isCollision(player2, goals[count]):
            goals[count].setposition(random.randint(-300, 300), random.randint(-300, 300))
            goals[count].right(random.randint(0,360))
            os.system("afplay yes.mp3&")
            score2 += 2
            speed += 0.5



    #collision checking with player 2
        if isCollision(player, player2):
            player.setposition(random.randint(-300, 300), random.randint(-290, 290))
            player.right(random.randint(0,360))
            os.system("afplay yes.mp3&")
            score1 -= 1
            speed += 0.5

        if isCollision(player2, player):
            player2.setposition(random.randint(-290, 290), random.randint(-290, 290))
            player2.right(random.randint(0,360))
            os.system("afplay yes.mp3&")
            score2 -= 1
            speed += 0.5


    #draws the score on the screen
    mypen.undo()
    mypen.penup()
    mypen.hideturtle()
    mypen.setposition(-290, 310)
    scorestring1 = (name1 + ": %s" + " points   ") %score1
    scorestring2 = (name2 + ": %s" + " points") %score2
    mypen.write(scorestring1 + scorestring2, False, align="left", font=("Arial",14, "normal"))




More information about the Python-list mailing list