Starting Template Using Window Class

If you are starting a new program, this template is a set of code to get started with.

starting_template.py
  1"""
  2Starting Template
  3
  4Once you have learned how to use classes, you can begin your program with this
  5template.
  6
  7If Python and Arcade are installed, this example can be run from the command line with:
  8python -m arcade.examples.starting_template
  9"""
 10import arcade
 11
 12WINDOW_WIDTH = 1280
 13WINDOW_HEIGHT = 720
 14WINDOW_TITLE = "Starting Template"
 15
 16
 17class GameView(arcade.View):
 18    """
 19    Main application class.
 20
 21    NOTE: Go ahead and delete the methods you don't need.
 22    If you do need a method, delete the 'pass' and replace it
 23    with your own code. Don't leave 'pass' in this program.
 24    """
 25
 26    def __init__(self):
 27        super().__init__()
 28
 29        self.background_color = arcade.color.AMAZON
 30
 31        # If you have sprite lists, you should create them here,
 32        # and set them to None
 33
 34    def reset(self):
 35        """Reset the game to the initial state."""
 36        # Do changes needed to restart the game here if you want to support that
 37        pass
 38
 39    def on_draw(self):
 40        """
 41        Render the screen.
 42        """
 43
 44        # This command should happen before we start drawing. It will clear
 45        # the screen to the background color, and erase what we drew last frame.
 46        self.clear()
 47
 48        # Call draw() on all your sprite lists below
 49
 50    def on_update(self, delta_time):
 51        """
 52        All the logic to move, and the game logic goes here.
 53        Normally, you'll call update() on the sprite lists that
 54        need it.
 55        """
 56        pass
 57
 58    def on_key_press(self, key, key_modifiers):
 59        """
 60        Called whenever a key on the keyboard is pressed.
 61
 62        For a full list of keys, see:
 63        https://api.arcade.academy/en/latest/arcade.key.html
 64        """
 65        pass
 66
 67    def on_key_release(self, key, key_modifiers):
 68        """
 69        Called whenever the user lets off a previously pressed key.
 70        """
 71        pass
 72
 73    def on_mouse_motion(self, x, y, delta_x, delta_y):
 74        """
 75        Called whenever the mouse moves.
 76        """
 77        pass
 78
 79    def on_mouse_press(self, x, y, button, key_modifiers):
 80        """
 81        Called when the user presses a mouse button.
 82        """
 83        pass
 84
 85    def on_mouse_release(self, x, y, button, key_modifiers):
 86        """
 87        Called when a user releases a mouse button.
 88        """
 89        pass
 90
 91
 92def main():
 93    """ Main function """
 94    # Create a window class. This is what actually shows up on screen
 95    window = arcade.Window(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
 96
 97    # Create and setup the GameView
 98    game = GameView()
 99
100    # Show GameView on screen
101    window.show_view(game)
102
103    # Start the arcade game loop
104    arcade.run()
105
106
107
108if __name__ == "__main__":
109    main()