So for this project, I have to make a bullet hit a target.
The bullet is shot using degrees to hit the target.
I made the bullet be able to shoot as well as a target being randomly created.
However, everytime I shoot the bullet, it simply just asks to enter another degree
to shoot a bullet. I am not sure what im missing in order to make the bullet recognize
the for loop and if statements near the end of the code. It seems it just ignores it. The
bullet also just shoots past the target. I need to make it so it
basically creates a right angle with bullet, degree, and target. I thought
i did that but obviously something is missing.
Also, the choice=simple.dialog has no effect either and idk why.
Thanks for any help!
from tkinter import*
import time
import math
import random
master = Tk()
cw= 1000
ch=650
w = Canvas(master, width=cw, height=ch, bg="skyblue")
w.pack()
w.create_line(10, 635, 80, 610, fill="black", width= 15)
w.create_oval(30, 630, 60, 650, fill="brown")
target_x= 900
target_y= random.randrange(40, 610)
choice = simpledialog.askstring
w.create_oval(900, target_y, 900 -40, target_y -40, fill="pink")
while(True):
if choice == "n":
break;
w.create_oval(900, target_y, 900 -40, target_y -40, fill="pink")
dMove= w.create_oval(81, 600, 80+10, 600+10, fill= "red")
degree = simpledialog.askstring("Enter degree", "What is your guess",
initialvalue="Enter a degree")
degree= 90 - int(degree)
for i in range(90):
w.move(dMove, math.sin(math.radians(degree))*10,
-math.cos(math.radians(degree))*10)
time.sleep(0.06)
w.update()
b = 820
a = target_y
c = b / math.cos(math.radians(degree))
c1 = math.sqrt(math.pow(b, 2) + math.pow(target_y+10, 2))
c2 = math.sqrt(math.pow(b, 2) + math.pow(target_y-10, 2))
w.update()
if c < c2 and c > c1:
print("You got it")
break
else:
print("enter degree")
Aucun commentaire:
Enregistrer un commentaire