import turtle
import random
import math
from turtle import Turtle,Screen
import time
#------------WN-------------
wn = turtle.Screen()
wn.bgcolor('black')
#-----------Game Countdown-------
def countdown(t):
while t > 0:
print(t)
t -= 1
time.sleep(1)
seconds = 10

#-----------Game Instruction--------
inp1 = input('Hi player, what is your name? : ')
print('Welcome ', str(inp1), ', the instruction below will teach you how to play this game.')
print('Instruction:')
print('To control the player, use the Left and Right Keybind')
print('Rules: You are the Pilot of the Franxx, your mission is to fly your ship and dodge the Stardust Storm, It is your duty to save your ship')
print(' countdown before Launching game')
countdown(seconds)
#-------------Screen-----------------
screen = Screen()
#-------------Border----------------
border = Turtle()
border.color('white')
border.speed(100)
border.penup()
border.goto(-300,300)
border.pendown()
border.forward(600)
border.right(90)
border.forward(600)
border.right(90)
border.forward(600)
border.right(90)
border.forward(600)
#------------Player-----------------
player = turtle.Turtle()
player.shape("triangle")
player.color('white')
player.penup()
player.setpos(0,-200)
player.speed(5)
def TurnLeft():
player.left(30)
def TurnRight():
player.right(30)

#-------COLLISION-------
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

#------------Food-----------------
maxStar=10
Stars=[ ]
for i in range(maxStar):
Stars.append(Turtle())
Stars[i].shape('circle')
Stars[i].penup()
Stars[i].color('orange')
Stars[i].goto(random.randint(-300,300),random.randint(0,300))
Stars[i].speed(0)
Stars[i].goto(random.randint(-300,300),random.randint(0,300))

#----------MAIN-----------

#Keybinding:
turtle.listen()
turtle.onkey(TurnLeft, "Left")
turtle.onkey(TurnRight, 'Right')

def EdgeTouched(ch):

if ch.xcor() < -300 or ch.xcor()>300:
ch.left(180)
if ch.ycor() < -300 or ch.ycor()>300:
ch.left(180)
isLosing=False
while not isLosing:
#dieu khien star
for Star in Stars:
y = Star.ycor()
Star.sety(y)
if isCollision(player,Star):
print('YOU FAILED')
isLosing=True
if Star.ycor()<-300:
Star.goto(random.randint(-300,300),300)
#dieu khien player
player.forward(5)
EdgeTouched(player)
Jul 30, 2020 in Python 424 views

## 1 answer to this question.

Hello @PetesHacker ,

I saw you do collision detection there, can just check for the y coordinates. Assuming y positive is up.
You can create a Rectangle object for your entities.
x, y, width and height .

These four values together will represent a rectangle. With x, y being the bottom left corner coordinates.

Then you just do the following check if it touches the bottom of the border as:

`Player.y <= border.y`

Also take a look at AABB (axis aligned bounding box) collisions for 2d collisions

• 82,880 points

## What is the use of Tkinter,Flask and Django? What is the main use of them? Can any of them help me in freelancing?

Hey, all the tools that you have ...READ MORE

## I have to build a pareto frontier on the movielens data set using NSGA-II algorithm. Can anyone help me out how to do it and what inputs to be given?

You can find the explanation and implementation ...READ MORE

## In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

## Need help writing a dataframe into a csv with the help of a loop

Using the following logic you can arrive ...READ MORE

## Can someone explain the behaviour of increment and decrement operators in python

down voteaccepted ++ is not an operator. It is ...READ MORE

## How can I record the X,Y limits of a displayed X,Y plot using the matplotlib show() module?

A couple hours after posting this question ...READ MORE