Starting Template Using Window Class#
If you are starting a new program, this template is a set of code to get started with.
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"""
10from __future__ import annotations
11
12import arcade
13
14SCREEN_WIDTH = 800
15SCREEN_HEIGHT = 600
16SCREEN_TITLE = "Starting Template"
17
18
19class MyGame(arcade.Window):
20 """
21 Main application class.
22
23 NOTE: Go ahead and delete the methods you don't need.
24 If you do need a method, delete the 'pass' and replace it
25 with your own code. Don't leave 'pass' in this program.
26 """
27
28 def __init__(self, width, height, title):
29 super().__init__(width, height, title)
30
31 self.background_color = arcade.color.AMAZON
32
33 # If you have sprite lists, you should create them here,
34 # and set them to None
35
36 def setup(self):
37 """ Set up the game variables. Call to re-start the game. """
38 # Create your sprites and sprite lists here
39 pass
40
41 def on_draw(self):
42 """
43 Render the screen.
44 """
45
46 # This command should happen before we start drawing. It will clear
47 # the screen to the background color, and erase what we drew last frame.
48 self.clear()
49
50 # Call draw() on all your sprite lists below
51
52 def on_update(self, delta_time):
53 """
54 All the logic to move, and the game logic goes here.
55 Normally, you'll call update() on the sprite lists that
56 need it.
57 """
58 pass
59
60 def on_key_press(self, key, key_modifiers):
61 """
62 Called whenever a key on the keyboard is pressed.
63
64 For a full list of keys, see:
65 https://api.arcade.academy/en/latest/arcade.key.html
66 """
67 pass
68
69 def on_key_release(self, key, key_modifiers):
70 """
71 Called whenever the user lets off a previously pressed key.
72 """
73 pass
74
75 def on_mouse_motion(self, x, y, delta_x, delta_y):
76 """
77 Called whenever the mouse moves.
78 """
79 pass
80
81 def on_mouse_press(self, x, y, button, key_modifiers):
82 """
83 Called when the user presses a mouse button.
84 """
85 pass
86
87 def on_mouse_release(self, x, y, button, key_modifiers):
88 """
89 Called when a user releases a mouse button.
90 """
91 pass
92
93
94def main():
95 """ Main function """
96 game = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
97 game.setup()
98 arcade.run()
99
100
101if __name__ == "__main__":
102 main()