Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab 9 : Implement the program in the picture to the right. A video has also been provided showing how this program is supposed to
Lab: Implement the program in the picture to the right. A video has also been provided showing how this program is supposed to work while in action. Note the following:
General Info:
o The screens size is x
Files:
o The images needed are provided.
o The sound files needed are provided.
Images:
o All images files are either x or x
o You must scale the images down to x before using them as buttons.
o The laser images center is at the exact center of the
screen.
o Both the on and the off button are aligned horizontally with the laser button.
o The on buttons right border is pixels away from the laser buttons left border.
o The off buttons left border is pixels away from the laser buttons right border.
Button Font:
o This refers to all the Font objects rendered under the buttons.
o All of these Font objects use the default Pygame font, and are size
o All of these font Surfaces are vertically aligned with their respective buttons.
o All of these font Surfaces top border are pixels down from their respective buttons bottom border.
Status Font
o This refers to the Font object right above the laser button.
o This Font object uses the default Pygame font, and is size
o This fonts Surface is vertically aligned with the center of the screen.
o This fonts Surface center is pixels above the center of the screen.
Sounds:
o Only one sound can be playing at a time.
Functionality:
o While the laser is Off the Shoot and Power Down button do nothing.
o Upon pressing the Power Up button, play the power up sound and change the status to Charging
o When the power up sound finishes playing, change the status to Ready
o While the laser is Ready the Power Up button does nothing.
o While the laser is Ready pressing the Shoot button plays the shoot sound and changes the status to Shooting
o When the shooting sound is done playing, change the status back to Ready
o While the laser is Ready pressing the Power Down button plays the power down sound and changes the status to Discharging
o When the power down sound finishes playing, change the status to Off
o While the laser is ChargingDischarging or Shooting none of the buttons do anything.
Hint: You should use a couple of extra Boolean variables to keep track of when the laser is charged and when the laser is busy doing something.
extra info:
Transform Module: This module contains several different functions to apply transformations to your image, such as rotation, flipping, and scaling. Notice that most of these methods are destructive, meaning that information on the original image will be lost. When applying a transformation, always save the result onto a different variable; never save it back into the original variable.
original pygame.image.loadfilenamepngconvert
fliphorizontally True
flipvertically True
flippedimage pygame.transform.fliporiginal fliphorizontally, flipvertically
newwidth
newheight
scaledimage pygame.transform.scaleoriginalnewwidth, newheight
newangle
rotatedimage pygame.transform.rotateoriginal newangle
Flip: Flips the image, either horizontally, vertically, or both. Takes in parameters: the Surface to be flipped, and two Booleans. Returns a Surface.
Scale: Resizes the image. Takes in parameters: the Surface to be scaled, and the dimensions of the scaled Surface. Returns a Surface.
Rotate: Rotates a Surface. Takes in paramters: the Surface being rotated, and the angle of rotation. Positive numbers rotate counterclockwise, while negative numbers rotate clockwise. Returns a Surface.
Mixer Module: This module allows for the creation of Sound objects, which can then be played. You can create a Sound object as follows:
sound pygame.mixer.Soundfilename
Once you have a sound object, you can use the following methods:
sound.play # plays the sound
sound.stop # stops playing the sound
sound.setvolumevolume # sets the volume of the sound
sound.getvolume # returns the current volume of the sound
Notice that the sound volume must be a number between and inclusive, with being not making any sound, being the sound at its loudest, and being midway between the two.
Its worth noticing that you can check if the Mixer is currently playing a Sound using the method below, which returns a Boolean:
pygame.mixer.getbusy
Font Module: This module allows the creation of Font objects, which can be used to write things to the Display Surface. First, you must create a Font object:
fontobject pygame.font.Fontfontfile",
The Font constructor takes in parameters: The name of the file holding the font, and the size you want the font to be Notice that you can pass a None as your first parameter, making Pygame use its default font. Once the Font object has been created
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started