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:
- Create a
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
""" Lab 7 - User Control """ import arcade # --- Constants --- SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 class MyGame(arcade.Window): """ Our Custom Window Class""" def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, "Lab 7 - User Control") def on_draw(self): arcade.start_render() def main(): window = MyGame() arcade.run() main()
- 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.
When you are done, make sure you commit your sound effects in what you turn in! Otherwise your program can’t be graded.