generated from technolyceum/ai6-m2
added asteroid
This commit is contained in:
@@ -15,23 +15,67 @@ player.hideturtle()
|
|||||||
player.color("#00FFFF")
|
player.color("#00FFFF")
|
||||||
player.penup()
|
player.penup()
|
||||||
player.goto(0,-250)
|
player.goto(0,-250)
|
||||||
player.emoji = "🚀"
|
player.emoji = "^"
|
||||||
player_speed = 20
|
player_speed = 20
|
||||||
# === GAME VARIABLES ===
|
# === GAME VARIABLES ===
|
||||||
game_active = True
|
game_active = True
|
||||||
asteroides =[]
|
asteroides =[]
|
||||||
|
|
||||||
# === FUNCTIONS ===
|
# === FUNCTIONS ===
|
||||||
|
|
||||||
def draw_player():
|
def draw_player():
|
||||||
player.clear()
|
player.clear()
|
||||||
player.write(player.emoji, align="center",
|
player.write(player.emoji, align="center",
|
||||||
font=("Arial",32, "normal"))
|
font=("Arial",32, "normal"))
|
||||||
|
|
||||||
|
def move_left():
|
||||||
|
if not game_active:
|
||||||
|
return
|
||||||
|
x = player.xcor()
|
||||||
|
x -= player_speed
|
||||||
|
if x < -280:
|
||||||
|
x = -280
|
||||||
|
player.setx(x)
|
||||||
draw_player()
|
draw_player()
|
||||||
screen.update()
|
|
||||||
turtle.done()
|
def move_right():
|
||||||
|
if not game_active:
|
||||||
|
return
|
||||||
|
x = player.xcor()
|
||||||
|
x += player_speed
|
||||||
|
if x > 280:
|
||||||
|
x = 280
|
||||||
|
player.setx(x)
|
||||||
|
draw_player()
|
||||||
|
|
||||||
|
|
||||||
|
def create_asteroid():
|
||||||
|
"""Create a new asteroid with random size"""
|
||||||
|
asteroid = turtle.Turtle()
|
||||||
|
asteroid.hideturtle()
|
||||||
|
|
||||||
|
asteroid.emoji = "🪨" # Rock emoji
|
||||||
|
asteroid.color = "#AA6644" # Brown color
|
||||||
|
asteroid.size = random.randint(20, 100)
|
||||||
|
|
||||||
|
asteroid.penup()
|
||||||
|
x = random.randint(-280, 280)
|
||||||
|
y = 300
|
||||||
|
asteroid.goto(x, y)
|
||||||
|
|
||||||
|
asteroid.speed = 5 - (asteroid.size / 25)
|
||||||
|
|
||||||
|
asteroids.append(asteroid)
|
||||||
|
return asteroid
|
||||||
|
|
||||||
# === TEST CODE ===
|
# === TEST CODE ===
|
||||||
|
|
||||||
# Uncomment this to test:
|
# Uncomment this to test:
|
||||||
# draw_player()
|
# draw_player()
|
||||||
# screen.update()
|
# screen.update()
|
||||||
|
|
||||||
|
screen.listen()
|
||||||
|
screen.onkey(move_left, "Left")
|
||||||
|
screen.onkey(move_right, "Right")
|
||||||
|
|
||||||
# turtle.done()
|
# turtle.done()
|
||||||
|
|||||||
Reference in New Issue
Block a user