Python Game Coding: Splash Screen and Game Over Screen

preview_player
Показать описание
Here's another video that answers TWO questions I get ALL THE TIME. The first is "How do I create a splash screen?" The second is "How do I create a game over screen?"

Links:

NEED HELP?

❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️

Click Join and Become a Channel Member Today!
Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.

Amazon Affiliate Links

Other Affiliate Links

LINKS

LEARN MORE PYTHON

LEARN MORE JAVA

#Python #Tutorial #Beginner
Рекомендации по теме
Комментарии
Автор

Love your videos. Just stayed up coding for 5 hours in python. Its all your fault for getting me into it. TY

StoopidMonkiy
Автор

I wasn’t really wandering how to do this but it could help in future games I create.

thisismyapple
Автор

I love the way you're organizing your script it's very logical. Thank you for the video.

simplepycodes
Автор

Thank you soo much for this tutorial! I plan to use this for many of my games.

monkeymass
Автор

I was waiting for this video. You really helped me a lot.

sujoydas
Автор

Thanks soooo much! Helped me a lot! Great video!

shreyanshgupta
Автор

Nice Video! Will you make some pygame tutorials in the future?

juliuskrebber
Автор

Thank you for your video... It is so easy to learn and get along...

RonaldChristy
Автор

and how do you make a starting menu so u can change the sounds of the game and size and other settings

enfysgreen
Автор

The game is made from images so I don't think they are interactive but I was still wondering if there was a way. Also, good job for 3mil views!

EthanJbleethan
Автор

Hello sir, I saw how you added segments to your snake, could you also tell me the code to remove segments from the snake? Thanks a lot!

gautamkappagal
Автор

Hello sir! Thanks a lot for the video, really helpful. I tried modifying the game by adding superfood which increases the score and segments by 3 and danger particles which reduce the score and segments by 5.

I've encountered a couple of problems.
1. Whenever the snake eats superfood, it works fine, score and segments increase by 3; but a segments blinks at (0, 0) for a second and disappears.

2. I want a code to end the game when you eat danger particles and the length of your snake (segments only) becomes less than 0.

Can you please help me with these two problems? I'll be really grateful.

My Code (PyCharm 2020.2.3)
import turtle

import time
import random
import math

delay = 0.08

# Score
score = 0
high_score = 0

# Screen Setup
wn = turtle.Screen()
wn.title("Snake Game")
wn.bgcolor("black")
wn.setup(width=500, height=500)
wn.tracer(0) # Turns off the screen updates

# Snake Head
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("Gray")
head.penup()
head.goto(0, 0)
head.direction = "stop"

# Snake Food
food = turtle.Turtle()
food.speed(0)
food.color("yellow")
food.shape("circle")
food.penup()
food.goto(0, 100)

#Super Food
super_food = turtle.Turtle()
super_food.speed(0)
super_food.color("blue")
super_food.shape("circle")
super_food.penup()
super_food.goto(20, 80)

#Danger

danger = turtle.Turtle()
danger.speed(0)
danger.color("red")
danger.shape("square")
danger.penup()
danger.goto(-40, -60)

segments = []

# Pen
pen = turtle.Turtle()
pen.speed(0)
pen.shape("square")
pen.color("cyan")
pen.penup()
pen.hideturtle()
pen.goto(0, 210)
pen.write("Score: 0 High Score: 0", align = "center", font=("Impact", 24, "normal"))

#Pen2
pen2 = turtle.Turtle()
pen2.speed(0)
pen2.shape("square")
pen2.color("red")
pen2.penup()
pen2.hideturtle()
pen2.goto(0, 0)

#Pen3
pen3 = turtle.Turtle()
pen3.speed(0)
pen3.shape("square")
pen3.color("red")
pen3.penup()
pen3.hideturtle()
pen3.goto(0, 150)

# Functionsa
def go_up():
if head.direction != "down":
head.direction = "up"


def go_down():
if head.direction != "up":
head.direction = "down"


def go_right():
if head.direction != "left":
head.direction = "right"


def go_left():
if head.direction != "right":
head.direction = "left"


def move():
if head.direction == "up":
y = head.ycor()
head.sety(y + 20)

if head.direction == "down":
y = head.ycor()
head.sety(y - 20)

if head.direction == "right":
x = head.xcor()
head.setx(x + 20)

if head.direction == "left":
x = head.xcor()
head.setx(x - 20)

# Keyboard
wn.listen()
wn.onkeypress(go_up, "w")
wn.onkeypress(go_right, "d")
wn.onkeypress(go_down, "s")
wn.onkeypress(go_left, "a")

# Main Game Loop
while True:
wn.update()

#Start Menu

# Check for a collision with the border
if head.xcor() > 240 or head.xcor() < -240 or head.ycor() > 240 or head.ycor() < -240:
time.sleep(0.7)
head.goto(0, 0)
head.direction = "stop"

# Hide the segments
for segment in segments:
segment.goto(10000, 10000)

# Clear existing segments
segments.clear()

# Reset the score
score = 0
pen.clear()

pen.write("Score: {} High Score: {}".format(score, high_score), align="center",
font=("Impact", 24, "normal"))

#Game Over
pen2.write("GAME OVER", align="center", font=("Elephant", 45, "normal"))

time.sleep(1)

pen2.clear()


# Check for a collision with food
if head.distance(food) < 20:
# Move the food to a random spot
x = random.randrange(-240, 240, 20)
y = random.randrange(-240, 240, 20)
food.goto(x, y)

# Add a segment
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("white")
new_segment.penup()
segments.append(new_segment)

# Increase the score
score += 1

if score > high_score:
high_score = score

pen.clear()

pen.write("Score: {} High Score: {}".format(score, high_score), align="center",
font=("Impact", 24, "normal"))
# Check for a collision with super food
if head.distance(super_food) < 20:
# Move the super food to a random spot
x = random.randrange(-240, 240, 20)
y = random.randrange(-240, 240, 20)
super_food.goto(x, y)

# Add 2 segment
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("white")
new_segment.penup()
segments.append(new_segment)
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("white")
new_segment.penup()
segments.append(new_segment)
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("white")
new_segment.penup()
segments.append(new_segment)


# Increase the score
score += 3

if score > high_score:
high_score = score

pen.clear()

pen.write("Score: {} High Score: {}".format(score, high_score), align="center",
font=("Impact", 24, "normal"))

#Check for collision with danger particle
# Move the danger to a random spot
if head.distance(danger) < 20:
x = random.randrange(-240, 240, 20)
y = random.randrange(-240, 240, 20)
danger.goto(x, y)

score -= 5
if score > high_score:
high_score = score


time.sleep(0.3)


pen.clear()


pen.write("Score: {} High Score: {}".format(score, high_score), align="center",
font=("Impact", 24, "normal"))

# Game Over
pen3.write("OOPS!", align="center", font=("Elephant", 25, "normal"))

time.sleep(1)

pen3.clear()



# Move the end segments (reverse movement)
for index in range(len(segments) - 1, 0, -1):
x = segments[index - 1].xcor()
y = segments[index - 1].ycor()
segments[index].goto(x, y)

# Move segment 0 to where the head is
if len(segments) > 0:
x = head.xcor()
y = head.ycor()
segments[0].goto(x, y)

move()

# Check for collision with the segments
for segment in segments:
if segment.distance(head) < 20:
time.sleep(0.7)
head.goto(0, 0)
head.direction = "stop"

# Hide the segments
for segment in segments:
segment.goto(10000, 10000)

# Clear the segments list
segments.clear()

# Game Over
pen2.write("GAME OVER", align="center", font=("Elephant", 45, "normal"))

time.sleep(2)

pen2.clear()


time.sleep(delay)

wn.mainloop


EDIT: I am a beginner, so sorry if this question was lame.

gautamkappagal
Автор

I did the pong game and now I'm trying to put a Start Screen in it, but I can't figure out how to make it. I added a gif to the screen and set "i" to start the game, when a click "i" it starts the game but the gif stays there. Is there a function to remove the gif?

Also, is there a way to put an animated gif in the background?

Your channel is amazing!

alexandrem.stratico
Автор

When you will start the video of your latest game that you had shown before?

technoinfoworldwide
Автор

hey I really hope your active, I put this first and its working fine but when I put my code for my game it doesn't show up? why is that? a fast reply would help

playyuhh
Автор

For example if i want to change my turtle image ranomly how can i do that plzz explain

riteshsamurai
Автор

But what about the game sound for Game Over Screen?...
😏

SkyFly
Автор

I need help. How do you convert a .png file to a .gif file?

notcolinc
Автор

Can you tell me how to get rid of that flickering "GAME OVER" text please?

swastiksarkar
Автор

Can u do some platforer games with turtle module

ashwins