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 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 scenes and have all my graphics and text.
Here is my code
import time
import random
# Scene : PacMan Walking in a Colorful World
def drawbackground:
# Set background to blue sky and green ground
setbackgroundcolorlightblue
drawrect getheight getwidth getheight "green"
def drawpacmanx y:
# Draw PacMan using a yellow circle
pacman Circle
pacman.setpositionx y
pacman.setcoloryellow
addpacman
def animatepacman:
# Animate PacMan walking from left to right
x
y getheight
while x getwidth:
clear
drawbackground
drawpacmanx y
x
time.sleep
return x y
# Scene : PacMan Meets a Blue Ghost
def drawghostx y:
# Draw the ghost as a blue circle
ghost Circle
ghost.setpositionx y
ghost.setcolorblue
addghost
def interaction:
pacmanx pacmany animatepacman
clear
drawbackground
drawpacmanpacmanx pacmany
ghostx ghosty pacmanx pacmany
drawghostghostx ghosty
displaymessagePacMan: Wanna be friends?", pacmanx pacmany
# Scene : Ghost's Doubt about Differences
def ghostdoubt:
ghostx ghosty getheight
clear
drawbackground
drawghostghostx ghosty
displaymessageGhost: But we are so different...", ghostx ghosty
# Scene : PacMan's Reassurance
def pacmanresponse:
pacmanx pacmany getheight
clear
drawbackground
drawpacmanpacmanx pacmany
displaymessagePacMan: Differences make friendships special!", pacmanx pacmany
time.sleep
ghosthappy
# Ghost's Change of Expression
def ghosthappy:
ghostx ghosty getheight
clear
drawbackground
drawghostghostx ghosty
displaymessageGhost: You're right, let's be friends!", ghostx ghosty
# Display message
def displaymessagetext x y:
label Texttext
label.setpositionx y
addlabel
# Scene management functions
def drawscene:
drawbackground
animatepacman
interaction
def drawscene:
ghostdoubt
def drawscene:
pacmanresponse
def drawscene:
ghosthappy
# Set up code for advancing scenes
scenecounter
def drawnextscreenx y:
global scenecounter
scenecounter
if scenecounter :
drawscene
elif scenecounter :
drawscene
elif scenecounter :
drawscene
else:
drawscene
welcome TextClick to Begin!"
welcome.setpositiongetwidth welcome.getwidth getheight
addwelcome
addmouseclickhandlerdrawnextscreen
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 drawscene:
printThis is scene
Draws the second scene on the canvas and outputs the second
section of text for the story.
def drawscene:
printThis is scene
Draws the third scene on the canvas and outputs the second
section of text for the story.
def drawscene:
printThis is scene
Draws the fourth scene on the canvas and outputs the second
section of text for the story.
def drawscene:
printThis is scene
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.
scenecounter
# When this function is called the next scene is drawn.
def drawnextscreenx y:
global scenecounter
scenecounter
if scenecounter :
drawscene
elif scenecounter :
drawscene
elif scenecounter :
drawscene
else:
drawscene
welcome TextClick to Begin!"
welcome.setpositiongetwidth welcome.getwidth getheight
addwelcome
addmouseclickhandlerdrawnextscreen
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
