Canon game

 from random import randrange #random library

from turtle import * #drawing graphics

from freegames import vector #games library


ball =vector(-200, -200)

speed=vector(0,0)

targets=[]


def inside(xy):

return -200<xy.x<200 and -200 < xy.y <200


def draw():

"drawing ball and targets"

clear()

global targets

for target in targets:

goto(target.x,target.y)

dot(20,'blue')



if inside(ball):


goto(ball.x,ball.y)

dot(10,'red')

#print(ball.x," ",ball.y)


update()


def tap(inx,iny):


"respond to screen tap" 

#changing coordinates

ball.x = inx

ball.y = iny

speed.x = (inx+200)/30

speed.y = (iny+200)/30

draw()




def move():

global targets

"moving ball in the targets "

if randrange(40)==0:

y=randrange(-150,150)

target=vector(200,y)

targets.append(target)


for target in targets:

target.x-=0.5



if inside(ball):

speed.y-=0.35

ball.move(speed)


dupe=targets.copy()

targets.clear()


for target in dupe:

if abs(target - ball) > 13:

targets.append(target)


draw()


for target in targets:

if not inside(target):

return


ontimer(move,50)



setup(420,420,370,0)

hideturtle()

up()

tracer(False)

onscreenclick(tap)

move()

done()