Can someone help me make a score everytimes the star touch the bottom of the border

0 votes
#PROJECT 23: STARDUST CRUSADER
import turtle
import random
import math
from turtle import Turtle,Screen
import time
Starsspeed = 10
#------------WN-------------
wn = turtle.Screen()
wn.bgcolor('black')
#-----------Game Countdown-------
def countdown(t):
    while t > 0:
        print(t)
        t -= 1
        time.sleep(1)
    print("BLAST OFF CRUSADER!")
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.setheading(90)
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()
           y-= Starsspeed
           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 by PetesHacker
• 120 points
659 views

1 answer to this question.

0 votes

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

answered Jul 30, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
1 answer
+2 votes
2 answers

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

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
1,433 views
0 votes
1 answer

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

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

answered Apr 17, 2018 in Python by anonymous
3,395 views
0 votes
1 answer

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

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

answered May 15, 2018 in Python by aryya
• 7,460 points
1,763 views
0 votes
1 answer

Can you help me understand the Global Interpreter Lock in Python

Suppose you have multiple threads which don't really touch ...READ MORE

answered Nov 23, 2018 in Python by aryya
• 7,460 points
706 views
0 votes
2 answers

How can I get the count of a list in Python?

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

answered Dec 10, 2020 in Python by anonymous
1,514 views
+2 votes
1 answer

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

answered Dec 27, 2018 in Python by anonymous
1,169 views
0 votes
1 answer

How can I get the domain name of my site within a Django template?

Hello kartik, The variation of the context processor ...READ MORE

answered Apr 23, 2020 in Python by Niroj
• 82,840 points
9,857 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP