How to use arcade - 10 common examples

To help you get started, we’ve selected a few arcade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pvcraven / arcade / tests / unit2 / test_text.py View on Github external
def on_draw(self):
        arcade.start_render()
        current_x = 20

        # First line
        current_y = SCREEN_HEIGHT - LINE_HEIGHT
        arcade.draw_text("Test Text", current_x, current_y, arcade.color.BLACK, 12)

        # Again to test caching
        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text", current_x, current_y, arcade.color.BLACK, 12)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Left", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_x="left")
        arcade.draw_point(SCREEN_WIDTH // 2, current_y, arcade.color.RED, 5)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Center", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_x="center")
        arcade.draw_point(SCREEN_WIDTH // 2, current_y, arcade.color.RED, 5)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Right", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_x="right")
        arcade.draw_point(SCREEN_WIDTH // 2, current_y, arcade.color.RED, 5)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Top", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_y="top")
github pvcraven / arcade / arcade / examples / bouncing_rectangle.py View on Github external
def on_draw(delta_time):
    """
    Use this function to draw everything to the screen.
    """

    # Start the render. This must happen before any drawing
    # commands. We do NOT need a stop render command.
    arcade.start_render()

    # Draw a rectangle.
    # For a full list of colors see:
    # http://arcade.academy/arcade.color.html
    arcade.draw_rectangle_filled(on_draw.center_x, on_draw.center_y,
                                 RECT_WIDTH, RECT_HEIGHT,
                                 arcade.color.ALIZARIN_CRIMSON)

    # Modify rectangles position based on the delta
    # vector. (Delta means change. You can also think
    # of this as our speed and direction.)
    on_draw.center_x += on_draw.delta_x * delta_time
    on_draw.center_y += on_draw.delta_y * delta_time

    # Figure out if we hit the edge and need to reverse.
    if on_draw.center_x < RECT_WIDTH // 2 \
github pvcraven / arcade / arcade / examples / tetris.py View on Github external
"""
        Draw the grid. Used to draw the falling stones. The board is drawn
        by the sprite list.
        """
        # Draw the grid
        for row in range(len(grid)):
            for column in range(len(grid[0])):
                # Figure out what color to draw the box
                if grid[row][column]:
                    color = colors[grid[row][column]]
                    # Do the math to figure out where the box is
                    x = (MARGIN + WIDTH) * (column + offset_x) + MARGIN + WIDTH // 2
                    y = SCREEN_HEIGHT - (MARGIN + HEIGHT) * (row + offset_y) + MARGIN + HEIGHT // 2

                    # Draw the box
                    arcade.draw_rectangle_filled(x, y, WIDTH, HEIGHT, color)
github pvcraven / arcade / tests / unit2 / test_text.py View on Github external
def __init__(self, width, height, title):
        super().__init__(width, height, title)
        arcade.set_background_color(arcade.color.AMAZON)
github pvcraven / arcade / tests / unit2 / test_physics_engine_platformer.py View on Github external
def __init__(self, width, height, title):
        super().__init__(width, height, title)

        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        arcade.set_background_color(arcade.color.AMAZON)

        self.character_list = arcade.SpriteList()
        self.character_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", CHARACTER_SCALING)
        self.character_sprite.center_x = 150
        self.character_sprite.center_y = 110
        self.character_list.append(self.character_sprite)

        self.wall_list = arcade.SpriteList()
        for x in range(0, 1200, 64):
            sprite = arcade.Sprite(":resources:images/tiles/boxCrate_double.png", CHARACTER_SCALING)
            sprite.center_x = x
            sprite.center_y = 32
            self.wall_list.append(sprite)

        self.physics_engine = arcade.PhysicsEnginePlatformer(self.character_sprite,
                                                             self.wall_list,
github pvcraven / arcade / tests / unit2 / run_tile.py View on Github external
# -- Background
        self.background_list = arcade.tilemap.process_layer(my_map,
                                                            "Background",
                                                            TILE_SCALING,
                                                            base_directory="test_data")

        # -- Coins
        self.coin_list = arcade.tilemap.process_layer(my_map,
                                                      coins_layer_name,
                                                      TILE_SCALING,
                                                      base_directory="test_data")

        # --- Other stuff
        # Set the background color
        if my_map.background_color:
            arcade.set_background_color(my_map.background_color)

        # Create the 'physics engine'
        self.physics_engine = arcade.PhysicsEnginePlatformer(self.player_sprite,
                                                             self.wall_list,
                                                             GRAVITY)
github pvcraven / arcade / tests / unit2 / test_drawing_dimensions.py View on Github external
def on_draw(self):
        """
        Render the screen.
        """

        # Start the render process. This must be done before any drawing commands.
        arcade.start_render()

        radius = 50
        width = radius * 2
        x = 200
        y = 100
        arcade.draw_rectangle_outline(x, y, width, width, arcade.color.BLACK, 2)
        arcade.draw_circle_outline(x, y, radius, arcade.color.BLACK, 2)
        arcade.draw_line(x - radius, y, x + radius, y, arcade.color.BLACK, 2)

        x = 200
        y = 300
        width = 150
        half_width = width / 2
        arcade.draw_rectangle_outline(x, y, width, 50, arcade.color.BLACK, 2)
        arcade.draw_ellipse_outline(x, y, width, 50, arcade.color.AFRICAN_VIOLET, 2)
        arcade.draw_line(x - half_width, y, x + half_width, y, arcade.color.RED, 2)
github pvcraven / arcade / tests / unit2 / run_map.py View on Github external
def on_draw(self):
        """ Render the screen. """

        # Clear the screen to the background color
        arcade.start_render()

        # Draw our sprites
        self.wall_list.draw()
        self.coin_list.draw()
        self.player_list.draw()

        # Draw our score on the screen, scrolling it with the viewport
        score_text = f"Score: {self.score}"
        arcade.draw_text(score_text, 10 + self.view_left, 10 + self.view_bottom,
                         arcade.csscolor.WHITE, 18)
github pvcraven / arcade / arcade / examples / perf_test / stress_test_collision_arcade.py View on Github external
def on_draw(self):
        """ Draw everything """

        # Start timing how long this takes
        draw_start_time = timeit.default_timer()

        arcade.start_render()
        self.coin_list.draw()
        self.player_list.draw()

        # Display info on sprites
        output = f"Sprite count: {len(self.coin_list):,}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 20, arcade.color.BLACK, 16)

        # Display timings
        output = f"Processing time: {self.processing_time:.3f}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 40, arcade.color.BLACK, 16)

        output = f"Drawing time: {self.draw_time:.3f}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 60, arcade.color.BLACK, 16)

        fps = self.fps.get_fps()
        output = f"FPS: {fps:3.0f}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 80, arcade.color.BLACK, 16)

        self.draw_time = timeit.default_timer() - draw_start_time
        self.fps.tick()
github pvcraven / arcade / tests / unit2 / test_sprite_scale.py View on Github external
import os
import arcade

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
LINE_HEIGHT = 20
CHARACTER_SCALING = 0.5


class MyTestWindow(arcade.Window):

    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        arcade.set_background_color(arcade.color.AMAZON)

        self.character_list = arcade.SpriteList()
        self.character_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", CHARACTER_SCALING)
        self.character_sprite.center_x = 150
        self.character_sprite.center_y = 150
        self.character_list.append(self.character_sprite)

    def on_draw(self):