Question: Python 3/Assignment Answer each question in a file called qXX.py where XX is the question number. Modify the sample code so that the background color
Python 3/Assignment
Answer each question in a file called qXX.py where XX is the question number.
- Modify the sample code so that the background color is red.
- Modify the sample code so that the background color transitions through the sequence black, red, green, blue, orange, yellow, brown. The background color should change once per second (every 30 frames). You can use this list of colors to figure out the RGB color codes.
- Use Google's advanced image search to find a reasonably-sized image that is free to reuse and that includes transparency. Modify the sample code so that it draws your image centered in the middle of the screen
- Modify the sample code so that your image sits in the middle of the screen and rotates at a rate of 1 revolution every 2 seconds. (See pygame.transform.rotate() documentation)
- Use Google's advanced image search to find a reasonably-sized image of a ball that is free to reuse and that includes transparency. Modify the sample code so that your ball slides back and forth across the bottom of the screen. It should take 2 seconds for the ball to go from the left side to the right.
- Improve your animation for question 5 so that the ball rotates, accurately, as if it were rolling back and forth.
- Modify your animation for question 6 so that the ball travels counterclockwise around the edge of the screen
- Using the system default font, with a size of 100, draw your name centered in the middle of the screen. (See pygame.font.Sysfont() and Font.render()).
- Download a free TrueType font (this is a file that ends in .ttf) from somewhere like this site. Using this font, draw your name centered on the screen. (See Font() for information on how to create a font from a file.)
- Download four .wav sound files from some site like this. Make an application that plays a different one of these four sounds when the user presses one of the 'a', 's', 'd', or 'f' keys.
- Make a simple application in which the image of a ball repeatedly moves to some location on-screen that the user has clicked. Each click should play a sound. Each time the ball reaches it's target play a different sound.
- (Bonus question.) Write a simulation that simulates balls being fired from the bottom center of the screen at some angle that ranges between 70 and 110 degrees. Some force like Earth's Gravity should act on these balls so that they eventually fall down. Each time the user hits the space bar a new ball is fired.
Skeleton Code
"""Some simple skeleton code for a pygame game/animation This skeleton sets up a basic 800x600 window, an event loop, and a redraw timer to redraw at 30 frames per second. """ from __future__ import division import math import sys import pygame class MyGame(object): def __init__(self): """Initialize a new game""" pygame.mixer.init() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() # set up a 640 x 480 window self.width = 800 self.height = 600 self.screen = pygame.display.set_mode((self.width, self.height)) # use a black background self.bg_color = 0, 0, 0 # Setup a timer to refresh the display FPS times per second self.FPS = 30 self.REFRESH = pygame.USEREVENT+1 pygame.time.set_timer(self.REFRESH, 1000//self.FPS) def run(self): """Loop forever processing events""" running = True while running: event = pygame.event.wait() # player is asking to quit if event.type == pygame.QUIT: running = False # time to draw a new frame elif event.type == self.REFRESH: self.draw() else: pass # an event type we don't handle def draw(self): """Update the display""" # everything we draw now is to a buffer that is not displayed self.screen.fill(self.bg_color) # flip buffers so that everything we have drawn gets displayed pygame.display.flip() MyGame().run() pygame.quit() sys.exit()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
