Question: Hey so I have a code that I need to be able to work and print out the 4 scenes I have coded but I

Hey so I have a code that I need to be able to work and print out the 4 scenes I have coded but I unfortunately cant get it to work. I need my code to be able to work in CodeHS library for python. I will provide you with my code and then what needs to be added to the code. The added code is what I have to include in my code which might have some mistakes. I want it to be able to print out my 4 scenes and have all my graphics and text.
Here is my code -
import time
import random
# Scene 1: Pac-Man Walking in a Colorful World
def draw_background():
# Set background to blue sky and green ground
set_background_color("lightblue")
draw_rect(0, get_height()//2, get_width(), get_height()//2, "green")
def draw_pacman(x, y):
# Draw Pac-Man using a yellow circle
pacman = Circle(30)
pacman.set_position(x, y)
pacman.set_color("yellow")
add(pacman)
def animate_pacman():
# Animate Pac-Man walking from left to right
x =30
y = get_height()//2+20
while x < get_width()-30:
clear()
draw_background()
draw_pacman(x, y)
x +=5
time.sleep(0.1)
return x, y
# Scene 2: Pac-Man Meets a Blue Ghost
def draw_ghost(x, y):
# Draw the ghost as a blue circle
ghost = Circle(30)
ghost.set_position(x, y)
ghost.set_color("blue")
add(ghost)
def interaction():
pacman_x, pacman_y = animate_pacman()
clear()
draw_background()
draw_pacman(pacman_x, pacman_y)
ghost_x, ghost_y = pacman_x +100, pacman_y
draw_ghost(ghost_x, ghost_y)
display_message("Pac-Man: Wanna be friends?", pacman_x, pacman_y -50)
# Scene 3: Ghost's Doubt about Differences
def ghost_doubt():
ghost_x, ghost_y =300, get_height()//2+20
clear()
draw_background()
draw_ghost(ghost_x, ghost_y)
display_message("Ghost: But we are so different...", ghost_x, ghost_y -50)
# Scene 4: Pac-Man's Reassurance
def pacman_response():
pacman_x, pacman_y =200, get_height()//2+20
clear()
draw_background()
draw_pacman(pacman_x, pacman_y)
display_message("Pac-Man: Differences make friendships special!", pacman_x, pacman_y -50)
time.sleep(2)
ghost_happy()
# Ghost's Change of Expression
def ghost_happy():
ghost_x, ghost_y =300, get_height()//2+20
clear()
draw_background()
draw_ghost(ghost_x, ghost_y)
display_message("Ghost: You're right, let's be friends!", ghost_x, ghost_y -50)
# Display message
def display_message(text, x, y):
label = Text(text)
label.set_position(x, y)
add(label)
# Scene management functions
def draw_scene1():
draw_background()
animate_pacman()
interaction()
def draw_scene2():
ghost_doubt()
def draw_scene3():
pacman_response()
def draw_scene4():
ghost_happy()
# Set up code for advancing scenes
scene_counter =0
def draw_next_screen(x, y):
global scene_counter
scene_counter +=1
if scene_counter ==1:
draw_scene1()
elif scene_counter ==2:
draw_scene2()
elif scene_counter ==3:
draw_scene3()
else:
draw_scene4()
welcome = Text("Click to Begin!")
welcome.set_position(get_width()/2- welcome.get_width()/2, get_height()/2)
add(welcome)
add_mouse_click_handler(draw_next_screen)
HERE IS THE CODE THAT WILL HELP WITH MAKING THE SCENES/ TO BE INCLUDED (I HAVE SOME OF IT INCLUDED IN MY CODE ALREADY BUT NOT SURE IF ITS RIGHT ALSO NOT ALL OF IT IS USED)-
"""
Draws the first scene on the canvas and outputs the first
section of text for the story.
"""
def draw_scene1():
print("This is scene 1")
"""
Draws the second scene on the canvas and outputs the second
section of text for the story.
"""
def draw_scene2():
print("This is scene 2")
"""
Draws the third scene on the canvas and outputs the second
section of text for the story.
"""
def draw_scene3():
print("This is scene 3")
"""
Draws the fourth scene on the canvas and outputs the second
section of text for the story.
"""
def draw_scene4():
print("This is scene 4")
"""
This is set up code that makes the story advance from
scene to scene. Feel free to check out this code and
learn how it works!
But be careful! If you modify this code the story might
not work anymore.
"""
scene_counter =0
# When this function is called the next scene is drawn.
def draw_next_screen(x, y):
global scene_counter
scene_counter +=1
if scene_counter ==1:
draw_scene1()
elif scene_counter ==2:
draw_scene2()
elif scene_counter ==3:
draw_scene3()
else:
draw_scene4()
welcome = Text("Click to Begin!")
welcome.set_position(get_width()/2- welcome.get_width()/2, get_height()/2)
add(welcome)
add_mouse_click_handler(draw_next_screen)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!