Arcade Documentation Release 1.1.0
Total Page:16
File Type:pdf, Size:1020Kb
Arcade Documentation Release 1.1.0 Paul Vincent Craven Jul 05, 2017 Contents 1 Learn about it: 3 2 Give feedback: 5 3 Contribute to the development:7 3.1 Examples.................................................7 3.1.1 Example Code.........................................7 3.1.1.1 Drawing........................................7 3.1.1.2 Animation.......................................8 3.1.1.3 Drawing with Loops..................................8 3.1.1.4 User Control......................................8 3.1.1.5 Sprites......................................... 21 3.1.1.6 Other.......................................... 27 3.2 Installation................................................ 32 3.2.1 Installation Instructions..................................... 32 3.2.1.1 Installation on Windows................................ 33 3.2.1.2 Installation on the Mac................................ 35 3.2.1.3 Installation on Linux.................................. 36 3.3 API Documentation........................................... 37 3.3.1 Arcade Package API...................................... 37 3.3.1.1 Submodules...................................... 37 3.3.1.2 Arcade Subpackages.................................. 37 3.4 How to Contribute............................................ 58 3.4.1 How to Contribute....................................... 58 3.4.1.1 How to contribute without coding........................... 58 3.4.1.2 How to contribute code................................ 58 3.4.2 Directory Structure....................................... 59 3.4.3 How to Compile......................................... 59 3.4.3.1 Windows........................................ 59 3.4.3.2 Linux.......................................... 59 3.4.4 How to Submit Changes.................................... 60 3.5 More Information............................................ 60 3.5.1 Pygame Comparison...................................... 60 3.5.2 Suggested Curriculum..................................... 61 3.5.2.1 Stage 1:........................................ 61 3.5.2.2 Stage 2:........................................ 61 3.5.2.3 Stage 3:........................................ 61 i 3.5.2.4 Stage 4:........................................ 62 3.5.2.5 Stage 5:........................................ 62 3.5.2.6 Stage 6:........................................ 62 4 License 63 ii Arcade Documentation, Release 1.1.0 Arcade is an easy-to-learn Python library for creating 2D video games. It is ideal for people learning to program, or developers that want to code a 2D game without learning a complex framework. Contents 1 Arcade Documentation, Release 1.1.0 2 Contents CHAPTER 1 Learn about it: • Installation Instructions • Example Code • Arcade Package API • quick-index • Arcade on PyPi • Pygame Comparison 3 Arcade Documentation, Release 1.1.0 4 Chapter 1. Learn about it: CHAPTER 2 Give feedback: • GitHub Arcade Issue List • Reddit Discussion Group • Email: [email protected] 5 Arcade Documentation, Release 1.1.0 6 Chapter 2. Give feedback: CHAPTER 3 Contribute to the development: • How to Contribute • GitHub Source Code for Arcade The status of the build is here: Examples Example Code Drawing examples/thumbs/drawing_primitives.png Fig. 3.1: drawing_primitives examples/thumbs/drawing_with_functions.png Fig. 3.2: drawing_with_functions 7 Arcade Documentation, Release 1.1.0 examples/thumbs/drawing_text.png Fig. 3.3: drawing_text examples/thumbs/array_backed_grid.png Fig. 3.4: array_backed_grid Animation examples/thumbs/bouncing_rectangle.png Fig. 3.5: bouncing_rectangle Drawing with Loops User Control 8 Chapter 3. Contribute to the development: Arcade Documentation, Release 1.1.0 examples/thumbs/bouncing_ball.png Fig. 3.6: bouncing_ball examples/thumbs/bouncing_balls.png Fig. 3.7: bouncing_balls examples/thumbs/radar_sweep.png Fig. 3.8: radar_sweep examples/thumbs/drawing_with_loops.png Fig. 3.9: drawing_with_loops examples/thumbs/nested_loops_box.png Fig. 3.10: nested_loops_box examples/thumbs/nested_loops_bottom_left_triangle.png Fig. 3.11: nested_loops_bottom_left_triangle 3.1. Examples 9 Arcade Documentation, Release 1.1.0 examples/thumbs/nested_loops_top_right_triangle.png Fig. 3.12: nested_loops_top_right_triangle examples/thumbs/nested_loops_top_left_triangle.png Fig. 3.13: nested_loops_bottom_left_triangle examples/thumbs/nested_loops_top_right_triangle.png Fig. 3.14: nested_loops_top_right_triangle examples/thumbs/shapes.png Fig. 3.15: shapes examples/thumbs/snow.png Fig. 3.16: snow 10 Chapter 3. Contribute to the development: Arcade Documentation, Release 1.1.0 User control: Mouse Listing 3.1: move_mouse.py 1 """ 2 This simple animation example shows how to move an item with the mouse, and 3 handle mouse clicks. 4 """ 5 6 import arcade 7 8 # Set up the constants 9 SCREEN_WIDTH= 800 10 SCREEN_HEIGHT= 600 11 12 RECT_WIDTH= 50 3.1. Examples 11 Arcade Documentation, Release 1.1.0 13 RECT_HEIGHT= 50 14 15 16 class Rectangle: 17 """ Class to represent a rectangle on the screen """ 18 19 def __init__(self, x, y, width, height, angle, color): 20 """ Initialize our rectangle variables """ 21 22 # Position 23 self.x=x 24 self.y=y 25 26 # Size and rotation 27 self.width= width 28 self.height= height 29 self.angle= angle 30 31 # Color 32 self.color= color 33 34 def draw(self): 35 """ Draw our rectangle """ 36 arcade.draw_rectangle_filled(self.x, self.y, self.width, self.height, 37 self.color, self.angle) 38 39 40 class MyApplication(arcade.Window): 41 """ Main application class. """ 42 def __init__(self, width, height): 43 super().__init__(width, height, title="Keyboard control") 44 self.player= None 45 self.left_down= False 46 47 def setup(self): 48 """ Set up the game and initialize the variables. """ 49 width= RECT_WIDTH 50 height= RECT_HEIGHT 51 x=0 52 y= RECT_HEIGHT 53 angle=0 54 color= arcade.color.WHITE 55 self.player= Rectangle(x, y, width, height, angle, color) 56 self.left_down= False 57 58 def update(self, dt): 59 """ Move everything """ 60 if self.left_down: 61 self.player.angle+=2 62 63 def on_draw(self): 64 """ 65 Render the screen. 66 """ 67 arcade.start_render() 68 69 self.player.draw() 70 12 Chapter 3. Contribute to the development: Arcade Documentation, Release 1.1.0 71 def on_mouse_motion(self, x, y, dx, dy): 72 """ 73 Called whenever the mouse moves. 74 """ 75 self.player.x=x 76 self.player.y=y 77 78 def on_mouse_press(self, x, y, button, modifiers): 79 """ 80 Called when the user presses a mouse button. 81 """ 82 print(button) 83 if button == arcade.MOUSE_BUTTON_LEFT: 84 self.left_down= True 85 86 def on_mouse_release(self, x, y, button, modifiers): 87 """ 88 Called when a user releases a mouse button. 89 """ 90 if button == arcade.MOUSE_BUTTON_LEFT: 91 self.left_down= False 92 93 94 def main(): 95 window= MyApplication(SCREEN_WIDTH, SCREEN_HEIGHT) 96 window.setup() 97 arcade.run() 98 99 main() 3.1. Examples 13 Arcade Documentation, Release 1.1.0 User control: Keyboard Listing 3.2: move_keyboard.py 1 """ 2 This simple animation example shows how to move an item with the keyboard. 3 """ 4 5 import arcade 6 7 # Set up the constants 8 SCREEN_WIDTH= 800 9 SCREEN_HEIGHT= 600 10 11 RECT_WIDTH= 50 12 RECT_HEIGHT= 50 14 Chapter 3. Contribute to the development: Arcade Documentation, Release 1.1.0 13 14 MOVEMENT_SPEED=5 15 16 17 class Rectangle: 18 """ Class to represent a rectangle on the screen """ 19 20 def __init__(self, x, y, width, height, angle, color): 21 """ Initialize our rectangle variables """ 22 23 # Position 24 self.x=x 25 self.y=y 26 27 # Vector 28 self.delta_x=0 29 self.delta_y=0 30 31 # Size and rotation 32 self.width= width 33 self.height= height 34 self.angle= angle 35 36 # Color 37 self.color= color 38 39 def draw(self): 40 """ Draw our rectangle """ 41 arcade.draw_rectangle_filled(self.x, self.y, self.width, self.height, 42 self.color, self.angle) 43 44 def move(self): 45 """ Move our rectangle """ 46 47 # Move left/right 48 self.x+= self.delta_x 49 50 # See if we've gone beyond the border. If so, reset our position 51 # back to the border. 52 if self.x< RECT_WIDTH//2: 53 self.x= RECT_WIDTH//2 54 if self.x> SCREEN_WIDTH- (RECT_WIDTH//2): 55 self.x= SCREEN_WIDTH- (RECT_WIDTH//2) 56 57 # Move up/down 58 self.y+= self.delta_y 59 60 # Check top and bottom boundaries 61 if self.y< RECT_HEIGHT//2: 62 self.y= RECT_HEIGHT//2 63 if self.y> SCREEN_HEIGHT- (RECT_HEIGHT//2): 64 self.y= SCREEN_HEIGHT- (RECT_HEIGHT//2) 65 66 67 class MyApplication(arcade.Window): 68 """ 69 Main application class. 70 """ 3.1. Examples 15 Arcade Documentation, Release 1.1.0 71 def __init__(self, width, height): 72 super().__init__(width, height, title="Keyboard control") 73 self.player= None 74 self.left_down= False 75 76 def setup(self): 77 """ Set up the game and initialize the variables. """ 78 width= RECT_WIDTH 79 height= RECT_HEIGHT 80 x= SCREEN_WIDTH//2 81 y= SCREEN_HEIGHT//2 82 angle=0 83 color= arcade.color.WHITE 84 self.player= Rectangle(x, y, width, height, angle, color) 85 self.left_down= False 86 87 def update(self, dt): 88 """ Move everything """ 89 self.player.move() 90 91 def on_draw(self): 92 """ 93 Render the screen. 94 """ 95 arcade.start_render() 96 97 self.player.draw() 98 99 def on_key_press(self, key, modifiers): 100 """ 101 Called whenever the mouse moves. 102 """ 103 if key == arcade.key.UP: 104 self.player.delta_y= MOVEMENT_SPEED 105 elif key == arcade.key.DOWN: 106 self.player.delta_y=-MOVEMENT_SPEED 107 elif key == arcade.key.LEFT: 108 self.player.delta_x=-MOVEMENT_SPEED 109 elif key == arcade.key.RIGHT: 110 self.player.delta_x=