Random Shape Arcade Game Creation

  • Share this:

Code introduction


This function creates an Arcade window and randomly draws a shape (circle, square, triangle, or rectangle) inside it.


Technology Stack : Arcade, Random number generation

Code Type : Game development

Code Difficulty : Intermediate


                
                    
def random_arcade_game_shape(arg1, arg2, arg3):
    import arcade
    from random import randint

    # Create a window with a title and a size
    arcade.open_window(arg1, arg2, "Random Shape Game")
    
    # Set the background color
    arcade.set_background_color(arcade.color.WHITE)
    
    # Create a list of shapes
    shapes = ["circle", "square", "triangle", "rectangle"]
    
    # Choose a random shape
    shape = shapes[randint(0, 3)]
    
    # Draw the shape on the screen
    if shape == "circle":
        arcade.draw_circle_filled(150, 150, 50, arcade.color.RED)
    elif shape == "square":
        arcade.draw_rectangle_filled(150, 150, 100, 100, arcade.color.GREEN)
    elif shape == "triangle":
        arcade.draw_polygon_filled([100, 200, 200, 100, 100, 200], arcade.color.BLUE)
    elif shape == "rectangle":
        arcade.draw_rectangle_filled(150, 150, 100, 50, arcade.color.YELLOW)

    # Start the game loop
    arcade.run()