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