Files
023-turtle-crossing/src/main.py
T
Tirsvad aa77784075 Add collision detection, finish line and level up
Task: MIL-005#1
Task: MIL-005#2
Task: MIL-005#3
Task: MIL-005#4
2026-10-13 13:59:35 +08:00

46 lines
1.1 KiB
Python

"""@file main.py
@brief Entry point: sets up the screen and runs the game loop.
"""
import time
from turtle import Screen
from car_manager import CarManager
from car_shape import register_car_shapes
from constants import LOOP_DELAY, SCREEN_HEIGHT, SCREEN_WIDTH
from player import Player
from scoreboard import Scoreboard
def main() -> None:
"""@brief Run the game until the player is hit by a car."""
screen = Screen()
screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
screen.tracer(0)
register_car_shapes(screen)
player = Player()
car_manager = CarManager()
screen.listen()
screen.onkey(player.go_up, "Up")
game_is_on = True
while game_is_on:
time.sleep(LOOP_DELAY)
screen.update()
car_manager.create_cars()
car_manager.move_cars()
if car_manager.is_hit(player):
game_is_on = False
if player.is_at_finish_line():
player.go_to_start()
car_manager.level_up()
screen.exitonclick()
if __name__ == "__main__":
main()