Lab 7: User Control¶
This lab gives you a chance to practice drawing an object with a function and allow the user to control it.
This lab does NOT use sprites. Look at User Control for examples relevant to this lab.
Write one program, following these steps:
Lab 07 - User Controlfolder for this lab, or use one that is already set up in your project.
Begin your code with the template below:
1""" Lab 7 - User Control """ 2 3import arcade 4 5# --- Constants --- 6SCREEN_WIDTH = 800 7SCREEN_HEIGHT = 600 8 9 10class MyGame(arcade.Window): 11 """ Our Custom Window Class""" 12 13 def __init__(self): 14 """ Initializer """ 15 16 # Call the parent class initializer 17 super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, "Lab 7 - User Control") 18 19 def on_draw(self): 20 arcade.start_render() 21 22 23def main(): 24 window = MyGame() 25 arcade.run() 26 27 28main()
Create a background image of some sort in the
on_drawmethod. Feel free to use any of your code that you have written from prior labs that you have. To do this, put your code in the
on_drawmethod. If your code used functions, move those functions as well to this program. Paste them above the
MyGameclass. Don’t turn this in with just a solid color for the background, or you’ll lose a couple points.
In User Control, we talked about moving graphics with the keyboard, a game controller, and the mouse. To start, pick one of these methods, and get that ball moving around in your program.
In the examples, we just moved a ball. Adjust the code so that it draws something more interesting than a ball. You can pull from the code you used in prior labs where you drew with a function, and move it to the
on_drawmethod of your class. But don’t have your object be a simple one line of code shape.
Rename your class from
Ballto a name that represents what you are really drawing.
After you get that object moving, pick a different method of control (keyboard, mouse, gamepad.) Create a new class, draw something different, and move it around the screen.
In the case of the game controller and the keyboard, make sure to add checks so that your object does not move off-screen and get lost.
Add a sound effect for when the user clicks the mouse button.
Add a different sound effect for when the user bumps into the edge of the screen. Make sure the sound only plays when you are trying to go beyond the edge of the screen, and not when you just sit at the edge of the screen. This part isn’t needed for anything controlled by the mouse.
When you are done, make sure you commit your sound effects in what you turn in! Otherwise your program can’t be graded.