### Run Arcade Example to Verify Installation Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst This command executes a built-in Arcade example directly from the installed Python module. It serves to confirm that the Arcade library is correctly installed and capable of opening a graphical window, indicating a successful environment setup. ```bash python -m arcade.examples.platform_tutorial.01_open_window ``` -------------------------------- ### Run an Arcade Example from Command Line Source: https://github.com/pythonarcade/arcade/blob/development/doc/get_started/install.rst Executes a specific example script provided with the Arcade library using the Python module runner. This command verifies the installation and demonstrates basic library functionality. ```bash python -m arcade.examples.sprite_explosion_bitmapped ``` -------------------------------- ### Define Main Program Entry Point (Python) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst Defines the primary entry point for the application. This function orchestrates the creation of the game window, calls its setup method, and starts the `arcade` event loop, which keeps the program running until the window is closed. ```Python def main(): window = GameView() window.setup() arcade.run() ``` -------------------------------- ### Arcade Library Installation Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Instructions for installing the Arcade Python game library using pip. ```bash pip install arcade ``` -------------------------------- ### Run Arcade Platformer Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_02.rst This command executes a pre-built example from the Arcade library, demonstrating the initial setup of drawing sprites on the screen. It allows users to see the expected outcome of the tutorial step before implementing the code themselves. ```python python -m arcade.examples.platform_tutorial.02_draw_sprites ``` -------------------------------- ### Arcade Library Documentation References (APIDOC) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst References to key `arcade` library documentation for customizing game properties and understanding class capabilities. These links guide users to detailed information on colors and the `arcade.Window` class. ```APIDOC Arcade Library Documentation: - Color Module: Reference: :ref:`color` Description: Documentation for color definitions and usage within Arcade. - CSS Color Module: Reference: :ref:`csscolor` Description: Documentation for CSS-like color definitions in Arcade. - arcade.Window Class: Reference: :class:`arcade.Window` Description: Comprehensive documentation for the main game window class, detailing its methods, properties, and capabilities. ``` -------------------------------- ### Install Arcade Development Version from Git Source: https://github.com/pythonarcade/arcade/blob/development/doc/get_started/install.rst Clones the Arcade library's development repository from GitHub and installs it in editable mode. This allows developers to make changes to the source code and see immediate effects without reinstallation. ```bash git clone https://github.com/pythonarcade/arcade cd arcade pip install -e . ``` -------------------------------- ### Setup Game Logic (Python) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst A placeholder method intended for one-time game setup logic, such as loading assets or initializing game state. The `pass` statement indicates that the function currently does nothing, serving as a future expansion point. ```Python def setup(self): pass ``` -------------------------------- ### Install Arcade via pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/get_started/install.rst Installs the latest stable version of the Arcade library from PyPI using the pip package manager. This is the most common and recommended installation method. ```bash pip install arcade ``` -------------------------------- ### Initialize GameView Object (Python) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst Initializes the `GameView` object. This special method is automatically called when a new instance of `GameView` is created, allowing for initial setup of class attributes and state. ```Python def __init__(self): ``` -------------------------------- ### Run Arcade Platformer Camera Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_07.rst Execute the provided Python example script from the command line. This command launches the game demonstrating the implemented camera functionality. ```bash python -m arcade.examples.platform_tutorial.07_camera ``` -------------------------------- ### Upgrade or Reinstall Arcade from Development Zip Source: https://github.com/pythonarcade/arcade/blob/development/doc/get_started/install.rst Forces a complete reinstallation or upgrade of Arcade from a specific development version hosted on GitHub. The -I flag ensures that any existing installation is ignored and replaced. ```bash pip install -I https://github.com/pythonarcade/arcade/archive/refs/heads/development.zip ``` -------------------------------- ### Initialize Arcade Window Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/card_game/index.rst This snippet sets up a basic Arcade window with a specified size and title, and defines placeholder methods for game setup, drawing, and updates. It serves as the starting point for the Solitaire game. ```Python import arcade SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Solitaire" class MyGame(arcade.Window): def __init__(self): super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcade.set_background_color(arcade.color.AMAZON) def setup(self): # Set up your game here pass def on_draw(self): arcade.start_render() # Your drawing code goes here def update(self, delta_time): # Game logic goes here pass def main(): game = MyGame() game.setup() arcade.run() if __name__ == "__main__": main() ``` -------------------------------- ### Install Arcade Library using pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/windows.rst This command installs the Arcade game development library directly into your Python environment using the pip package manager. It's a straightforward method for quick setup, but it's recommended to use a virtual environment to avoid dependency conflicts. ```Shell pip3 install arcade ``` -------------------------------- ### Shortcut for Running `arcade.Window` Instances Source: https://github.com/pythonarcade/arcade/blob/development/CHANGELOG_HISTORY.rst A convenient `run()` method has been added to the `arcade.Window` class, allowing for a more concise way to start the application loop. Instead of manually calling `setup()` and `run()`, users can now simply call `run()` on their window instance. ```Python import arcade class MyWindow(arcade.Window): def __init__(self): super().__init__(800, 600, "My Game") def on_draw(self): arcade.start_render() arcade.draw_text("Hello, Arcade!", 10, 10, arcade.color.WHITE, 24) if __name__ == "__main__": MyWindow().run() ``` -------------------------------- ### Example Output of Arcade Environment Command Source: https://github.com/pythonarcade/arcade/blob/development/doc/community/how_to_get_help.rst This snippet shows a typical output when running the 'arcade' command. It provides details on the Arcade version, hardware, Python version, and operating system. The specific values will vary based on the user's system. ```console Arcade 2.7.0 ------------ vendor: Intel renderer: Mesa Intel(R) UHD Graphics 620 (KBL GT2) version: (4, 6) python: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] platform: linux ``` -------------------------------- ### Install Arcade for current user via pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/get_started/install.rst Installs the Arcade library specifically for the current user. This method is useful when system-wide installation is not desired or permissions are limited, especially outside of virtual environments. ```bash pip install arcade --user ``` -------------------------------- ### Documentation Example Update: Rendering Source: https://github.com/pythonarcade/arcade/blob/development/CHANGELOG_HISTORY.rst Documentation examples have been updated to replace the `arcade.start_render()` call with `self.clear()` for clarity and consistency within `View` classes. ```Python # Old way of starting render in Arcade examples arcade.start_render() # New recommended way within a View class self.clear() ``` -------------------------------- ### Run Arcade Platformer Tutorial Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_11.rst This command-line instruction shows how to execute the specific Python example file `11_scene.py` from the Arcade platformer tutorial. It allows users to run and observe the changes discussed in the documentation directly. ```Shell python -m arcade.examples.platform_tutorial.11_scene ``` -------------------------------- ### Instantiate Arcade Scene in setup Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_11.rst Initializes the `arcade.Scene` object at the beginning of the `setup` function, which will serve as the central manager for all game sprites and layers. ```Python self.scene = arcade.Scene() ``` -------------------------------- ### Install FFmpeg for Ogg/MP3 Sound Support on Mac Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/mac.rst This command uses Homebrew to install FFmpeg, which provides support for Ogg Vorbis (.ogg) and MP3 (.mp3) audio files in Arcade on macOS. Ensure Homebrew is installed before running this command. ```shell brew install ffmpeg ``` -------------------------------- ### Verify Arcade Installation and Environment Details Source: https://github.com/pythonarcade/arcade/blob/development/doc/programming_guide/headless.rst Use the python -m arcade command to quickly display information about your Arcade installation, including the version, graphics vendor, renderer, OpenGL version, Python version, and platform. This helps in debugging and verifying your setup. ```bash python -m arcade ``` -------------------------------- ### Run Arcade Platformer User Control Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_04.rst This command line snippet shows how to execute the `04_user_control.py` example directly from the installed Arcade library, allowing users to run and test the platformer's user control features. ```Shell python -m arcade.examples.platform_tutorial.04_user_control ``` -------------------------------- ### Run Platformer Tutorial Chapter 10 Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_10.rst This command-line instruction demonstrates how to execute the Python example for the tenth chapter of the platformer tutorial. Running this command will launch the game, allowing users to observe the implemented score system and camera behavior. ```Shell python -m arcade.examples.platform_tutorial.10_score ``` -------------------------------- ### Run Arcade Platformer Tutorial Chapter 9 Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_09.rst Command to execute the Python script for the ninth chapter of the Arcade platformer tutorial. This allows users to run and observe the sound integration examples discussed in the documentation. ```Shell python -m arcade.examples.platform_tutorial.09_sound ``` -------------------------------- ### Install Arcade Library using pipenv Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/windows.rst This command installs the Arcade library within a pipenv-managed virtual environment. Pipenv is a dependency manager that creates isolated environments for your projects, ensuring that project dependencies do not conflict with other projects or the global Python installation. ```Shell python3 -m pipenv install arcade ``` -------------------------------- ### Run Arcade Platformer Example (Bash) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_05.rst Provides the command-line instruction to execute the complete `arcade` platformer example script. This allows users to run and observe the implemented gravity and jumping mechanics directly from their terminal. ```bash python -m arcade.examples.platform_tutorial.05_add_gravity ``` -------------------------------- ### Install TeX Live Extra for PDF Documentation Build (Debian/Ubuntu) Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command installs `texlive-latex-extra`, a large package providing additional LaTeX components necessary for building Arcade's PDF documentation on Debian and Ubuntu. The `--no-install-recommends` flag can be used to reduce installation size. ```console sudo apt install texlive-latex-extra ``` -------------------------------- ### Install Arcade and PyInstaller Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/bundling_with_pyinstaller/index.rst This command installs the necessary Python libraries, `arcade` for game development and `pyinstaller` for bundling, into your current Python environment. It's the first step before creating or bundling an Arcade game. ```bash pip install arcade pyinstaller ``` -------------------------------- ### Arcade Physics Engines Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Documentation on the various physics engines available in Arcade, including `PhysicsEngineSimple`, `PhysicsEnginePlatformer`, and integration with Pymunk. ```APIDOC Physics Engines: PhysicsEngineSimple: Description: A basic physics engine, suitable for simple platformers. Usage: See platformer tutorial :ref:`platformer_part_three`, Learn Arcade Book `Simple Physics Engine`, Example :ref:`sprite_move_walls`. PhysicsEnginePlatformer: Description: An advanced physics engine specifically for platformer games. Usage: From platformer tutorial :ref:`platformer_part_four`. Features: Supports moving platforms (:ref:`sprite_moving_platforms`) and ladders (:ref:`platformer_part_ten`). Pymunk Integration: Top-down physics: Supported, documentation needed. Platformer physics: See :ref:`pymunk_platformer_tutorial`. ``` -------------------------------- ### Code Quality Checks and Example Testing Source: https://github.com/pythonarcade/arcade/blob/development/RELEASE_CHECKLIST.md This snippet outlines the shell commands for running code quality checks using Ruff and MyPy, and for executing all project examples to ensure functionality. ```Shell ruff arcade mypy arcade ``` ```Shell python tests/test_examples/run_all_examples.py ``` -------------------------------- ### Install Arcade in Editable Development Mode Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command installs the Arcade library in editable mode, including all development dependencies. This setup is essential for contributors as it allows for real-time testing of code changes without requiring reinstallation, streamlining the development workflow. ```bash pip install -e '.[dev]' ``` -------------------------------- ### Arcade Basic Drawing and ShapeElementLists Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Overview of basic drawing commands in Arcade, highlighting the use of `arcade.ShapeElementList` for efficient batch drawing. ```APIDOC arcade.ShapeElementList: Description: Batches thousands of drawing commands into one for performance optimization. Usage: See examples in :ref:`shape-element-lists`. ``` -------------------------------- ### Instantiate `arcade.Camera2D` in Python Setup Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_07.rst Initialize the `self.camera` variable with a new `arcade.Camera2D()` instance in the game's setup function. This sets up the camera with default full-screen viewport settings. ```python self.camera = arcade.Camera2D() ``` -------------------------------- ### Setup Game Cards and Piles Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/card_game/index.rst This snippet updates the `MyGame.setup` method to create and populate the `card_list` with all standard playing cards. Separating setup allows for easy game restarts. ```Python class MyGame(arcade.Window): # ... __init__ ... def setup(self): self.card_list = arcade.SpriteList() # EMPHASIZED LINE self.pile_mat_list = arcade.SpriteList() # EMPHASIZED LINE # Create all the cards for suit in CARD_SUITS: # EMPHASIZED LINE for value in CARD_VALUES: # EMPHASIZED LINE card = Card(suit, value) # EMPHASIZED LINE card.position = 100, 100 # EMPHASIZED LINE (arbitrary start) self.card_list.append(card) # EMPHASIZED LINE # random.shuffle(self.card_list) # EMPHASIZED LINE (if it were there) ``` -------------------------------- ### Implement on_show_view for Instruction Screen Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/views/index.rst Define the `on_show_view` method within `InstructionView` to handle setup tasks when the view becomes active, such as setting the background color and resetting the viewport for scrolling games. ```python def on_show_view(self): """ This is called once when the view is activated. """ arcade.set_background_color(arcade.color.ORANGE_PEEL) # Reset the viewport, necessary if we have a scrolling game and we need # to reset the viewport back to the start so we can see what we draw. arcade.set_viewport(0, self.window.width, 0, self.window.height) ``` -------------------------------- ### Arcade Sprite Class and Operations Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Documentation for the core `arcade.Sprite` class, including basic usage, collision detection, and hit box manipulation. ```APIDOC arcade.Sprite: Description: The fundamental class for representing game objects with position, texture, and collision properties. Properties: hit_box: A property to define or change the sprite's collision bounding box. Methods: draw_hit_box(): A method to visualize the sprite's collision box, useful for debugging. ``` -------------------------------- ### Arcade View Management and Screens Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Explains how to manage different views or screens within an Arcade application, such as pause screens, instruction screens, and game over screens. ```APIDOC View Management: Minimal example: :ref:`view_screens_minimal` Pause screen: :ref:`view_pause_screen` Instruction and Game Over screen: :ref:`view_instructions_and_game_over` ``` -------------------------------- ### Install Arcade Development Build via pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/index.rst This command installs the latest pre-release development build of the Arcade library directly from its GitHub repository. This version provides access to the newest features but might be unstable compared to stable releases. ```bash pip install -I https://github.com/pythonarcade/arcade/archive/refs/heads/development.zip ``` -------------------------------- ### Run Arcade Platformer Tutorial Chapter 8 Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_08.rst This command line instruction allows you to execute the complete Python example for Chapter 8 of the Arcade platformer tutorial. It demonstrates the coin collection mechanics implemented in this chapter. ```Shell python -m arcade.examples.platform_tutorial.08_coins ``` -------------------------------- ### Install LaTeXmk for PDF Documentation Build (Debian/Ubuntu) Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command installs `latexmk`, a prerequisite package for building PDF documentation on Debian and Ubuntu-based Linux distributions. It is required for the LaTeX-based PDF generation process. ```console sudo apt install latexmk ``` -------------------------------- ### Install Pre-commit Hooks for Code Quality Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md Commands to install the 'pre-commit' tool using pip or Homebrew. Pre-commit helps automate linting, formatting, and type checks against your changes before they are committed to the repository. ```bash pip install pre-commit ``` ```bash brew install pre-commit ``` -------------------------------- ### Install Arcade from Development Source via pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/source.rst Installs the latest development version of the Arcade library directly from its GitHub repository using pip. This command will replace any existing Arcade installation. ```Shell pip install -I https://github.com/pythonarcade/arcade/archive/refs/heads/development.zip ``` -------------------------------- ### Example Output of OpenGL Performance Query Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/logging.rst An example of the output generated when querying OpenGL performance statistics using `arcade.Window.ctx`. It shows the time taken for drawing operations, the number of samples rendered, and the count of primitives created. ```text Time elapsed : 7,136 ns Samples passed : 390,142 Primitives created : 232 ``` -------------------------------- ### Define GameView Class (Python) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst Defines the main game window class, inheriting from `arcade.Window`. This class serves as the foundation for encapsulating game logic and data, providing a structured approach to game development. ```Python class GameView(arcade.Window): ``` -------------------------------- ### Google Style Docstring Args Block Example Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md Example of an 'Args:' block in a Google Style docstring, detailing parameters for a function. This is the minimum requirement for documenting function parameters in Arcade. ```python Args: width: The width of something height: The height of something title: The title of something ``` -------------------------------- ### Example Output of Basic Arcade Logging Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/logging.rst An example of the debugging information output by the Arcade library when basic logging is enabled. This output includes details about internal operations, system configuration, and performance metrics. ```text 2409.0003967285156 arcade.sprite_list DEBUG - [386411600] Creating SpriteList use_spatial_hash=True capacity=100 2413.9978885650635 arcade.gl.context INFO - Arcade version : 2.4a5 2413.9978885650635 arcade.gl.context INFO - OpenGL version : 3.3 2413.9978885650635 arcade.gl.context INFO - Vendor : NVIDIA Corporation 2413.9978885650635 arcade.gl.context INFO - Renderer : GeForce GTX 980 Ti/PCIe/SSE2 2413.9978885650635 arcade.gl.context INFO - Python : 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] 2413.9978885650635 arcade.gl.context INFO - Platform : win32 3193.9964294433594 arcade.sprite_list DEBUG - [386411600] _calculate_sprite_buffer: 0.013532099999999936 sec ``` -------------------------------- ### Install Nuitka via pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/compiling_with_nuitka/index.rst This command installs the Nuitka compiler tool using pip, making it available for compiling Python projects on your system. ```bash pip install nuitka ``` -------------------------------- ### Shell: Run Arcade Platformer Tutorial Chapter 6 Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_06.rst Execute the Python Arcade platformer tutorial's sixth chapter from the command line. This command launches the example demonstrating the game reset functionality discussed in the chapter. ```Shell python -m arcade.examples.platform_tutorial.06_reset ``` -------------------------------- ### Arcade Window Management Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Covers aspects of managing the game window, including scrolling and full-screen support. ```APIDOC Window Management: Scrolling: :ref:`sprite_move_scrolling` Full screen support: :ref:`full_screen_example` ``` -------------------------------- ### Preparing a Sound for Playback Source: https://github.com/pythonarcade/arcade/blob/development/doc/programming_guide/sound.rst Loads a built-in sound file (`coin1.wav`) into a `Sound` object. This prepared `Sound` object is then used in subsequent examples to demonstrate different playback methods. ```python COIN_SOUND = arcade.load_sound(":resources:sounds/coin1.wav") ``` -------------------------------- ### Arcade View Fade Transition Example Source: https://github.com/pythonarcade/arcade/blob/development/doc/example_code/transitions.rst This Python example demonstrates how to create and manage fade in/out transitions between different `arcade.View` instances. It illustrates the basic structure for switching views and where custom transition logic would be integrated. ```Python import arcade class MyGame(arcade.Window): def __init__(self): super().__init__(800, 600, "Transition Example") self.current_view = None def show_view(self, new_view): # This method would handle the fade in/out logic # For example, by drawing a semi-transparent rectangle # over the screen and gradually changing its alpha. print(f"Transitioning from {type(self.current_view).__name__} to {type(new_view).__name__}") self.current_view = new_view super().show_view(new_view) # Call the base method class ViewA(arcade.View): def on_show_view(self): arcade.set_background_color(arcade.color.BLUE) def on_draw(self): self.clear() arcade.draw_text("View A", 400, 300, arcade.color.WHITE, 50, anchor_x="center") def on_mouse_press(self, x, y, button, modifiers): self.window.show_view(ViewB()) class ViewB(arcade.View): def on_show_view(self): arcade.set_background_color(arcade.color.RED) def on_draw(self): self.clear() arcade.draw_text("View B", 400, 300, arcade.color.WHITE, 50, anchor_x="center") def on_mouse_press(self, x, y, button, modifiers): self.window.show_view(ViewA()) def main(): window = MyGame() window.show_view(ViewA()) arcade.run() if __name__ == "__main__": main() ``` -------------------------------- ### Update Main Function to Show Instruction View First Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/views/index.rst Modify the main function to initially create and display the `InstructionView`, allowing the game to start with an instruction screen before transitioning to the main game. ```python def main(): """ Main function """ window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) start_view = InstructionView() window.show_view(start_view) arcade.run() ``` -------------------------------- ### Example: Configuring Arcade Sections for Game UI Components Source: https://github.com/pythonarcade/arcade/blob/development/doc/programming_guide/sections.rst This Python example demonstrates how to define custom `arcade.Section` subclasses (Map, Menu, Panel, PopUp) and integrate them into an `arcade.View` using `arcade.SectionManager`. It showcases how to set up section dimensions, names, drawing order, and specific event handling preferences (e.g., `accept_keyboard_keys`, `accept_mouse_events`) for different UI elements within a game. ```python import arcade class Map(arcade.Section): #... define all the section logic class Menu(arcade.Section): #... define all the section logic class Panel(arcade.Section): #... define all the section logic class PopUp(arcade.Section): def __init__(message, *args, **kwargs): super().__init(*args, **kwargs) self.message = message # define draw logic, etc... class MyView(arcade.View): def __init__(self, *args, **kwargs): self.map = Map(left=0, bottom=0, width=600, height=550, name='Map', draw_order=2) self.menu = Menu(left=0, bottom=550, width=800, height=50, name='Menu', accept_keyboard_keys=False, accept_mouse_events={'on_mouse_press'}) self.panel = Panel(left=600, bottom=0, width=200, height=550, name='Panel', accept_keyboard_keys=False, accept_mouse_events=False) popup_left = (self.view.window.width // 2) - 200 popup_bottom = (self.view.window.height // 2) - 100 popup_width = 400 popup_height = 200 self.popup = PopUp(message='', popup_left, popup_bottom, popup_width, popup_height, enabled=False, modal=True) self.sm = arcade.SectionManager() self.sm.add_section(self.map) self.sm.add_section(self.menu) self.sm.add_section(self.panel) self.sm.add_section(self.popup) def on_show_view(self) -> None: self.sm.section_manager.enable() def on_hide_view(self) -> None: self.sm.section_manager.disable() def close(): self.popup.message = 'Are you sure you want to close the view?' self.popup.enabled = True ``` -------------------------------- ### Create Simple Arcade Window Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/framebuffer/index.rst This snippet initializes a basic Arcade window, serving as the starting point for graphics applications. It sets up the window dimensions and title, preparing the environment for rendering operations. ```Python import arcade SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Simple Arcade Window" class MyGame(arcade.Window): def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.AMAZON) def on_draw(self): self.clear() def main(): game = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcade.run() if __name__ == "__main__": main() ``` -------------------------------- ### Arcade Sprite Movement Techniques Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Describes various methods for moving player sprites in Arcade, including mouse, keyboard (with different handling complexities), and game controller inputs. ```APIDOC Sprite Movement: Mouse-based movement: Refer to :ref:`sprite_collect_coins`. Keyboard-based movement: Basic: :ref:`sprite_move_keyboard` Advanced (multiple key presses): :ref:`sprite_move_keyboard_better` With acceleration/deceleration: :ref:`sprite_move_keyboard_accel` Rotate and move (spaceship style): :ref:`sprite_move_angle` Game Controller-based movement: Refer to :ref:`sprite_move_controller`. ``` -------------------------------- ### Example of Python make.py Command Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command demonstrates the standard way to run a `make.py` script using the Python interpreter. It executes the 'lint' target, typically used for code style checking. ```bash python make.py lint ``` -------------------------------- ### Example of Shorthand make.py Command (Mac/Linux) Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command demonstrates the more ergonomic shorthand for running `make.py` scripts on Mac and Linux systems. It directly executes the script as an executable, achieving the same result as running it with `python`. ```bash ./make.py lint ``` -------------------------------- ### Build Arcade Documentation to PDF Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command initiates the build process for Arcade's documentation into a PDF file. It requires LaTeX and its extra configurations to be installed on the system. ```console ./make.py latexpdf ``` -------------------------------- ### Open a Basic Arcade Window Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/shader_toy_glow/index.rst This Python program initializes a standard Arcade window with predefined dimensions and title. It serves as the foundational setup before integrating any custom shaders. ```Python import arcade # Set constants for the screen size SCREEN_WIDTH = 1000 SCREEN_HEIGHT = 600 SCREEN_TITLE = "ShaderToy Demo 1" class MyGame(arcade.Window): def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.AMAZON) def on_draw(self): self.clear() def main(): MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcade.run() if __name__ == "__main__": main() ``` -------------------------------- ### Arcade Sprite Shooting Mechanics Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Details different shooting mechanics for player and enemy sprites, including various aiming and firing patterns. ```APIDOC Shooting Mechanics: Player shoots straight up: :ref:`sprite_bullets` Enemy shoots periodically: :ref:`sprite_bullets_periodic` Enemy shoots randomly: :ref:`sprite_bullets_random` Player aims: :ref:`sprite_bullets_aimed` Enemy aims: :ref:`sprite_bullets_enemy_aims` ``` -------------------------------- ### Create and Run a Basic Arcade Window Locally Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst This snippet provides the Python code required to open a simple, fixed-size window using the Arcade library. Users are instructed to copy this code into a `main.py` file. The accompanying terminal command demonstrates how to execute this local Python script to run the window application. ```python """ Simple program to open a window. This is a fixed-size window. """ import arcade SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Welcome to Arcade" def main(): # Open the window. Set the window title and dimensions arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Run the main loop arcade.run() if __name__ == "__main__": main() ``` ```bash python main.py ``` -------------------------------- ### Import Arcade Library Source: https://github.com/pythonarcade/arcade/blob/development/doc/example_code/controller.rst This snippet shows the standard way to import the Arcade library, which is necessary for game development using the framework. ```python import arcade ``` -------------------------------- ### Example .pot File Structure (Gettext) Source: https://github.com/pythonarcade/arcade/blob/development/doc/example_code/text_loc_example.rst Illustrates the structure of a `.pot` file generated by `pygettext.py`. It contains metadata and `msgid` entries for translatable strings, with empty `msgstr` fields. ```APIDOC # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2019-05-06 12:19-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: pygettext.py 1.5\n" #: text_loc_example.py:46 msgid "Simple line of text in 12 point" msgstr "" ``` -------------------------------- ### Run Arcade Console Command for Environment Info Source: https://github.com/pythonarcade/arcade/blob/development/doc/community/how_to_get_help.rst This command is used to retrieve basic information about the current Arcade version and development environment. It is cross-platform and should be run from within an activated virtual environment. ```console arcade ``` -------------------------------- ### Arcade Non-Player Sprite Movement and AI Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/get_started.rst Explores various movement patterns and AI behaviors for non-player sprites, including bouncing, following, line of sight, and pathfinding. ```APIDOC Non-Player Sprite Movement: Bouncing: :ref:`sprite_bouncing_coins` Moving towards player: Simple: :ref:`sprite_follow_simple` With delay: :ref:`sprite_follow_simple_2` Space-invaders style: :ref:`slime_invaders` Line of Sight (Can a sprite see the player?): :ref:`line_of_sight` A-star pathfinding: :ref:`astar_pathfinding` ``` -------------------------------- ### Serve Local Arcade Documentation Website Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command starts a simple HTTP server to preview the locally built Arcade documentation. It serves files from the `doc/build/html` directory, allowing access via a web browser at `http://localhost:8000`. ```bash python -m http.server -d doc/build/html ``` -------------------------------- ### Translated .po File Example (Gettext) Source: https://github.com/pythonarcade/arcade/blob/development/doc/example_code/text_loc_example.rst Shows a `.po` (Portable Object) file with a translated `msgstr` entry. This file is created by manually translating the `msgid` from the `.pot` file. ```APIDOC msgid "Simple line of text in 12 point" msgstr "LĂ­nea simple de texto en 12 puntos." ``` -------------------------------- ### Install Shell Tab Completion for make.py Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command installs tab completion for `make.py` in the user's default shell. It uses `basename "$SHELL"` to dynamically get the current shell, ensuring the completion is set up correctly for supported shells. ```bash ./make.py --install-completion $(basename "$SHELL") ``` -------------------------------- ### Error: Arcade Command Not Found Source: https://github.com/pythonarcade/arcade/blob/development/doc/community/how_to_get_help.rst This snippet illustrates an error message indicating that the 'arcade' command was not found. This typically occurs if the virtual environment is not activated or Arcade is not successfully installed. ```console bash: arcade: command not found ``` -------------------------------- ### Create a GUI with a Hidden Password Input (Python) Source: https://github.com/pythonarcade/arcade/blob/development/doc/example_code/gui_exp_hidden_password.rst This example demonstrates how to create a simple graphical user interface (GUI) using Arcade, featuring an experimental widget for a hidden password input field. It shows the basic setup of an Arcade window and the integration of GUI elements. ```Python import arcade.gui class MyWindow(arcade.Window): def __init__(self): super().__init__(800, 600, "GUI Hidden Password Example") self.manager = arcade.gui.UIManager() self.manager.enable() # Create a vertical box layout for widgets self.v_box = arcade.gui.UIBoxLayout() # Create a hidden password input field (experimental) self.password_input = arcade.gui.UIInputText( x=0, y=0, width=200, height=30, text="", multiline=False, password=True # This is the key part for hidden password ) self.v_box.add(self.password_input.with_space_around(bottom=20)) # Create a label to show input (for demonstration, normally not shown) self.output_label = arcade.gui.UILabel(text="Password: ") self.v_box.add(self.output_label.with_space_around(bottom=20)) # Create a button to submit/show password (for demonstration) self.submit_button = arcade.gui.UIFlatButton(text="Show Password", width=150) self.v_box.add(self.submit_button) @self.submit_button.event("on_click") def on_click_submit(event): self.output_label.text = f"Password: {self.password_input.text}" # Add the VBox to the UIManager, centered self.manager.add( arcade.gui.UIAnchorLayout().add( anchor_x="center_x", anchor_y="center_y", child=self.v_box ) ) def on_draw(self): self.clear() self.manager.draw() if __name__ == "__main__": window = MyWindow() arcade.run() ``` -------------------------------- ### Update Main Function to Initialize Window and View Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/views/index.rst Modify the main function to create an `arcade.Window` instance, then instantiate a view (e.g., `GameView`), and finally show that view using `window.show_view()`. ```python def main(): """ Main function """ window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) game_view = GameView() window.show_view(game_view) arcade.run() ``` -------------------------------- ### Install Python 3 and Dependencies on Ubuntu/Debian Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/linux.rst Installs Python 3, pip, and necessary development libraries (libjpeg-dev, zlib1g-dev) required by Arcade on Ubuntu or Debian-based systems. This step can be skipped if Python 3.7+ is already installed. ```bash sudo apt install python3 python3-pip libjpeg-dev zlib1g-dev ``` -------------------------------- ### Calculate Map Right Edge in Pixels for Arcade Game Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_14.rst This code calculates the pixel coordinate of the right edge of the loaded tilemap within the `setup` function. It multiplies the map's width (in tiles) by the tile width and then by the map's scaling factor to get the accurate pixel dimension, storing it in `self.end_of_map` for level progression checks. ```Python # Calculate the right edge of the map in pixels self.end_of_map = (self.tile_map.width * self.tile_map.tile_width) * self.tile_map.scaling ``` -------------------------------- ### Install Arcade Library via Pip Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/linux.rst Installs the Arcade library using pip. This command should be executed only after the virtual environment has been successfully activated. ```bash pip install arcade ``` -------------------------------- ### Create a Simple Arcade Game (main.py) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/bundling_with_pyinstaller/index.rst This Python script creates a basic Arcade game window and draws a blue circle. It serves as a minimal example to demonstrate the PyInstaller bundling process without requiring any external data files initially. ```python import arcade window = arcade.open_window(400, 400, "My Game") window.clear() arcade.draw_circle_filled(200, 200, 100, arcade.color.BLUE) arcade.finish_render() arcade.run() ``` -------------------------------- ### Execute Main Function on Script Run (Python) Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_01.rst A standard Python idiom that ensures the `main()` function is called only when the script is executed directly (e.g., `python your_script.py`), and not when it's imported as a module into another script. ```Python if __name__ == "__main__": main() ``` -------------------------------- ### Define Instruction Screen View Class Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/views/index.rst Create a new class, `InstructionView`, inheriting from `arcade.View` to manage the instruction screen's logic and rendering. ```python class InstructionView(arcade.View): ``` -------------------------------- ### Arcade Projector Class Methods Source: https://github.com/pythonarcade/arcade/blob/development/doc/programming_guide/camera.rst Documentation for key methods of the `arcade.camera.Projector` class, including functions for setting projection/view matrices, context management, and converting between world and screen coordinates. ```APIDOC arcade.camera.Projector: use(): Sets the internal projection and view matrices used by Arcade and Pyglet. activate(): Same as use(), but works within a context manager using the 'with' syntax. unproject(): Provides a way to find the world position of any pixel position on screen. project(): Provides a way to find the screen position of any position in the world. ``` -------------------------------- ### Load Tile Map and Create Scene from Map in Setup Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/platform_tutorial/step_12.rst This code loads a Tiled map using `arcade.load_tilemap` and then creates an `arcade.Scene` from it using `arcade.Scene.from_tilemap`. It includes `layer_options` to enable spatial hashing for the 'Platforms' layer, replacing previous manual sprite list creation. ```Python layer_options = { "Platforms": { "use_spatial_hash": True } } self.tile_map = arcade.load_tilemap( ":resources:tiled_maps/map.json", scaling=TILE_SCALING, layer_options=layer_options ) self.scene = arcade.Scene.from_tilemap(self.tile_map) ``` -------------------------------- ### Python Attribute Docstring Example Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md Example of how to document an attribute directly in a class or module using a docstring immediately after its definition. This method is preferred over using an 'Attributes:' block within a class docstring. ```python my_attribute_in_class_or_module: type = value """This is a docstring for the attribute.""" ``` -------------------------------- ### Manual PyPI Deployment Steps Source: https://github.com/pythonarcade/arcade/blob/development/RELEASE_CHECKLIST.md This snippet details the sequence of `make` commands required for a manual deployment of the Python Arcade project to PyPI, including cleaning, distribution, and final deployment. ```Shell make clean make dist make deploy_pypi ``` -------------------------------- ### Implement on_mouse_press for Instruction Screen Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/views/index.rst Define the `on_mouse_press` method within `InstructionView` to handle user input, such as a mouse click, which transitions to the main game view after setting it up. ```python def on_mouse_press(self, _x, _y, _button, _modifiers): """ If the user presses the mouse button, start the game. """ game_view = GameView() game_view.setup() self.window.show_view(game_view) ``` -------------------------------- ### Opening an Arcade Window Source: https://github.com/pythonarcade/arcade/blob/development/doc/tutorials/menu/index.rst This snippet initializes a basic Arcade window and sets up a starting view. It's the foundational step for any Arcade application, providing the canvas for all subsequent UI elements and game logic. ```Python import arcade SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Arcade Menu Tutorial" class MainView(arcade.View): def __init__(self): super().__init__() def on_show_view(self): arcade.set_background_color(arcade.color.AMAZON) def on_draw(self): self.clear() def main(): window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.show_view(MainView()) arcade.run() if __name__ == "__main__": main() ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/linux.rst Creates a new isolated Python virtual environment named 'my_venv'. It is strongly recommended to install Arcade within a virtual environment to prevent conflicts with system-wide Python packages. ```bash python -m venv my_venv ``` -------------------------------- ### Get Connected Controllers in Arcade Python Source: https://github.com/pythonarcade/arcade/blob/development/doc/example_code/controller.rst Demonstrates how to retrieve a list of connected game controllers using `arcade.get_controllers()`. It checks for available controllers and attempts to open the first one found, providing a fallback if no controllers are detected. ```python controllers = arcade.get_controllers() if controllers: self.controller = controllers[0] self.controller.open() else: print("There are no controllers.") self.controller = None ``` -------------------------------- ### Check Python 3 Version Source: https://github.com/pythonarcade/arcade/blob/development/doc/_archive/install/linux.rst Checks the specific version of Python 3 installed. If this command shows Python 3.7+ and 'python -V' showed Python 2.x, use 'python3' instead of 'python' for all subsequent commands. ```bash python3 -V ``` -------------------------------- ### Upgrade Pip for Development Environment Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md This command upgrades the pip package installer to its latest version. It is recommended to run this if you encounter installation errors, particularly those related to `setup.py` or `pyproject.toml` not being found, ensuring compatibility with modern Python packaging standards. ```bash pip install --upgrade pip ``` -------------------------------- ### Serve Arcade Documentation with Live Reload Source: https://github.com/pythonarcade/arcade/blob/development/CONTRIBUTING.md Command to build and serve the Arcade project's documentation locally. It hosts a web server at http://localhost:8000 and automatically rebuilds the documentation and refreshes the browser upon detecting changes in source files. ```bash python make.py serve ```