"""
Scroll around a large screen.
Artwork from https://kenney.nl
If Python and Arcade are installed, this example can be run from the command line with:
python -m arcade.examples.sprite_move_scrolling
"""import random
import arcade
SPRITE_SCALING =0.5
DEFAULT_SCREEN_WIDTH =800
DEFAULT_SCREEN_HEIGHT =600
SCREEN_TITLE ="Sprite Move with Scrolling Screen Example"# How many pixels to keep as a minimum margin between the character# and the edge of the screen.
VIEWPORT_MARGIN =200# How fast the camera pans to the player. 1.0 is instant.
CAMERA_SPEED =0.1# How fast the character moves
PLAYER_MOVEMENT_SPEED =7classMyGame(arcade.Window):""" Main application class. """def__init__(self, width, height, title):"""
Initializer
"""super().__init__(width, height, title, resizable=True)# Sprite lists
self.player_list =None
self.wall_list =None# Set up the player
self.player_sprite =None
self.physics_engine =None# Used in scrolling
self.view_bottom =0
self.view_left =0# Track the current state of what key is pressed
self.left_pressed =False
self.right_pressed =False
self.up_pressed =False
self.down_pressed =False
self.camera_sprites = arcade.Camera(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT)
self.camera_gui = arcade.Camera(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT)defsetup(self):""" Set up the game and initialize the variables. """# Sprite lists
self.player_list = arcade.SpriteList()
self.wall_list = arcade.SpriteList()# Set up the player
self.player_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png",
scale=0.4)
self.player_sprite.center_x =256
self.player_sprite.center_y =512
self.player_list.append(self.player_sprite)# -- Set up several columns of wallsfor x inrange(200,1650,210):for y inrange(0,1600,64):# Randomly skip a box so the player can find a way throughif random.randrange(5)>0:
wall = arcade.Sprite(":resources:images/tiles/grassCenter.png", SPRITE_SCALING)
wall.center_x = x
wall.center_y = y
self.wall_list.append(wall)
self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list)# Set the background color
arcade.set_background_color(arcade.color.AMAZON)# Set the viewport boundaries# These numbers set where we have 'scrolled' to.
self.view_left =0
self.view_bottom =0defon_draw(self):"""
Render the screen.
"""# This command has to happen before we start drawing
self.clear()# Select the camera we'll use to draw all our sprites
self.camera_sprites.use()# Draw all the sprites.
sel