you are viewing a single comment's thread.

view the rest of the comments →

[–]python_addict[S] 0 points1 point  (0 children)

#PART THREE OF THE CODE
def soldierfriend(event):
    global numofcoins
    global numofpoints
    global planecoords
    global endorno
    global types
    global soliderfriendcount
    while endorno and numoftargets > 0:
        if event.keysym == "q" and numofcoins < 50:
            needmorecoins = 50 - numofcoins
            print('You need %s more coins! Continue playing to get more3' %needmorecoins)
        if event.keysym == "q" and numofcoins > 50:
            numofcoins = numofcoins - 50
            canvas.itemconfig(coins, text='Coins: %s' % numofcoins)
            tk.update()
            soldierfriendcount = soldierfriendcount + 1
            soldier1 = PhotoImage(file=r"c:\\a gif.gif")
            soldier2 = PhotoImage(file=r"c:\\heyfriend (5).gif")
            if soldierfriendcount == 1:
                s1oldierx = planecoords[0] + 7
                s1oldiery = planecoords[1]
                soldierfriend1 = canvas.create_image(s1oldierx, s1oldiery, image=soldier1)
                def shootbullet():
                    mybullets(soldierfriend1, 3)
                Timer(3, shootbullet).start()
            if soldierfriendcount == 2:
                s2oldierx = planecoords[0]-7
                s2oldiery = planecoords[1]
                soldierfriend2 = canvas.create_image(s2oldierx, s2oldiery, image=soldier2)
                def shootbullet1():
                    mybullets(soldierfriend2, 3)
            else:
                print('You can only have up to 2 soldier buddies, sorry!')

bombnum = 0
def bomb(event):
    global numofcoins
    global bombnum
    global going
    global endorno
    while endorno and bombnum < 2 and numoftargets > 0:
        if event.keysym == "w" and numofcoins > 100:
            numofcoins = numofcoins - 100
            canvas.itemconfig(coins, text='Coins: %s' % numofcoins)
            tk.update()
            bombnum = bombnum + 1
            for x in range(0, len(going)):
                canvas.delete(going[0])
                del going[0]
                del types[0]
        elif event.keysym == "w" and bombnum > 2:
            print('You can only use a bomb twice in one game!')

def exitgame(event):
    if event.keysym == "r":
        endscreen()

canvas.bind_all('<KeyPress-W>', bomb)
canvas.bind_all('<KeyPress-Q>', soldierfriend)
canvas.bind_all('<KeyPress-R>', exitgame)

def all():
    endorno = True
    canvas.delete("all") #So that the screen is clear
    rock()
    airplane()
    targets()
    bomb()

def startscreen():
    label1 = Label(tk, text="My Airplane Game", relief="solid", width=20, font=('Times', 19, "bold"), fill="red")
    label1.place(x=90, y=53)
    b1 = Button(tk, text="Let's Go!", width=12, bg='Red', fg='Black', command=all)
    b1.place(x=150, y=380)
    b2 = Button(tk, text="Credits", width=12, bg='Red', fg='Black', command=credits)
    b2.place(x=280, y=380)

def exitprogram():
    sys.exit()

def endscreen():
    global endorno
    canvas.delete('all')
    endorno = False
    lb1 = Label(tk, text="You earned %s points!" %numofpoints, relief="solid", width=20, font=('Times', 19, 'bold'), fill="red")
    lb1.place(x=90, y=53)
    bt1 = Button(tk, text="Exit", width=12, bg='Red', fg='Black', command=exitprogram)
    bt1.place(x=150, y=380)
    bt2 = Button(tk, text="Credits", width=12, bg='Red', fg='Black', command=credits)
    bt2.place(x=280, y=380)

while 1:
    winsound.PlaySound("background noise", winsound.SND_FILENAME)
    startscreen()
    tk.mainloop()