import sys
import os
import random
import time
import turtle
 
#turtle.setup(400,500)
wn = turtle.Screen() 
#wn.title("Handling keypresses!") 
#wn.bgcolor("lightgreen")
tess = turtle.Turtle()

boxes = []

def collide_check(xc,yc):
        count = 0
        for box in boxes:
                
                x1 = box[0]
                y1 = box[1]
                x2 = box[2]
                y2 = box[3]
                
                if (xc >= x1) and (xc <= x2) and (yc >= y1) and (yc <= y2):
                        print ("collision")
                        return (count)
                count = count + 1
        return(-1)
    
def do_check():
     x = tess.xcor()
     y = tess.ycor()
     result = collide_check(x,y)
     if (result >-1):
         print("do_check found collision")
         box = boxes[result]
         x1 = box[0]
         y1 = box[1]
         x2 = box[2]
         y2 = box[3]
         mk_box(x1,y1,x2,y2,"red",5)
         t_end = time.time()
         t_used = t_end - t_start
         print("\nTime of run = ",t_used,"\n")
         exit()
         
         

def mk_box(x1,y1, x2, y2,color,width):
	#print("in mk_box")
	tess.pu()
	tess.setpos(x1,y1)
	tess.pd()
	tess.color(color)
	tess.pensize(width)
	tess.setpos(x2,y1)
	tess.setpos(x2,y2)
	tess.setpos(x1,y2)
	tess.setpos(x1,y1)
	boxes.append([x1,y1,x2,y2])
	#print(boxes)
	
mk_box(10,100,100,200,"black",2)
mk_box(-50,-50,50,50,"black",2)

mk_box(-200,-200, 100,20,"black",2)
