Python 3 Turtle Script to Build Frogger Game GUI Desktop App Full Project For Beginners

 

 

pip install turtle

 

 

main.py

 

 

# TODO - main: Create a turtle crossing game.

# TODO: 1. Create a new screen and setup it.

# Import modules
import turtle
import player
import carclass
import scoreboard
import gameover
import random
import time

# Setup the screen:
screen = turtle.Screen()
screen.setup(width=600, height=600)
screen.bgcolor("black")
screen.title("Turtle is crossing whatever it is")
screen.tracer(0)
screen.listen()
screen.colormode(255)

# Setup players turtle:
player = player.Player()

# Setup scoreboard turtle:
score = scoreboard.ScoreBoard()

# Setup game over turtle:
game_is_over = gameover.GameOver()

# Bind key controls:
screen.onkey(fun=player.move_forward, key="w")

# Setup main loop for the game:
game_is_on = True
speed = 5
list_of_cars = []

while game_is_on:
    # Setup screen update:
    time.sleep(0.1)
    screen.update()

    # TODO: 3. Create a logic of player going back to the start position.

    # Checking if player hit the top:
    if player.ycor() >= 300:
        player.goto_start()
        score.track_score()
        speed += 2.5

    # Setup car turtle:
    number = random.randint(1, 6)
    if number % 6 == 0:
        cars = carclass.Car()
        list_of_cars.append(cars)

    # Move turtles
    for car in list_of_cars:
        car.forward(speed)

    # Detect collisions with cars:
    for cars in list_of_cars:
        if player.distance(cars) < 20:
            game_is_over.write_game_over()
            game_is_on = False


# Exit on click:
screen.exitonclick()

 

See also  Python 3 Script to Find Armstrong Number in an Interval Using While Loop Full Tutorial For Beginners

 

 

 

 

DOWNLOAD FULL SOURCE CODE

 

Leave a Reply