1

所以我在运行程序时收到此错误消息。

回溯(最后一次调用):文件“C:\Users\GUESS\OneDrive\Desktop\Computer Science\Game\Changable.py”,第 229 行,在 mainWindow.setup() 文件“C:\Users\GUESS\OneDrive \Desktop\Computer Science\Game\Changable.py",第 190 行,在 setup self.enemy_list.append() AttributeError: 'NoneType' object has no attribute 'append'

在输入敌人之前它工作得很好。任何反馈表示赞赏。我正在使用 python 街机/get-pip.py。我尝试使用http://arcade.academy/并从那里获得了一些我的代码,但它似乎仍然不起作用

这是我的代码:

### Samuel Ball ###

import arcade


SCALING = 0.5
SPRITE_NATIVE_SIZE = 128
SPRITE_SIZE = int(SPRITE_NATIVE_SIZE * SCALING)

SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768

# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
VIEWPORT_MARGIN = 40
RIGHT_MARGIN = 150

#Physics
MOVEMENT_SPEED = 5
JUMP_SPEED = 14
GRAVITY = 0.5

sceneTiles = [
    [  2,  2,  2, 00, 00, 00, 00, 00, 00, 00, 00,  5,  5,  5,  2 ], #Bottom Row
    [  2,  2,  2, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,  2,  2 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,  2,  2 ],
    [ 00, 00, 00,  1, 00, 00, 00, 00, 00, 00, 00, 00,  3,  2,  4 ],
    [ 00, 00, 00, 00, 00,  1, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00,  1, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00,  1, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,  3,  2,  4 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],  #Top Row
    ]

decorativeTiles = [
    [ 00, 00, 00,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3 ], #Bottom Row
    [ 00, 00,  7,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4 ],
    [  6, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [  1, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00,  2, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [  2, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00,  1, 00,  2, 00,  1, 00,  2, 00,  1,  0,  2, 00,  1 ],  #Top Row
    ]


class MyGameWindow(arcade.Window):
    allSpritesList = arcade.SpriteList()
    wallList = arcade.SpriteList()
    player = arcade.AnimatedWalkingSprite()

    def __init__(self, width, height):
        super().__init__(width, height)
        #arcade.set_background_color([101, 216, 255])
        arcade.set_background_color(arcade.color.AERO_BLUE)


        # set up player
        self.score = 0
        self.player_sprite = None
        self.physics_engine = None
        self.view_left = 0
        self.view_bottom = 0
        self.game_over = False

    def on_draw(self):
        arcade.start_render()
        self.allSpritesList.draw()
        self.wall_list = arcade.SpriteList()
        self.enemy_list = arcade.SpriteList()
        self.player_list = arcade.SpriteList()

    def setup(self):
         # sprite list
        self.wall_list = None
        self.enemy_list = None
        self.player_list = None


        leftPos = 0
        bottomPos = 0
        for row in sceneTiles:
            for counter in range(0, len(row)):
                if row[counter] > 0:
                    if row[counter] == 1:
                        wall = arcade.Sprite("images/tiles/box.png", SCALING)
                    elif row[counter] == 2:
                        wall = arcade.Sprite("images/tiles/grass.png", SCALING)
                    elif row[counter] == 3:
                        wall = arcade.Sprite("images/tiles/grassCliffLeft.png", SCALING)
                    elif row[counter] == 4:
                        wall = arcade.Sprite("images/tiles/grassCliffRight.png", SCALING)
                    wall.bottom = bottomPos
                    wall.left = leftPos
                    self.wallList.append(wall)
                    self.allSpritesList.append(wall)
                else:
                    wall = arcade.Sprite("images/tiles/grassCenter.png", SCALING)
                leftPos = leftPos + wall.width
            bottomPos = bottomPos + wall.height
            leftPos = 0

        leftPos = 0
        bottomPos = 0
        for row in decorativeTiles:
            for counter in range(0, len(row)):
                if row[counter] > 0:
                    if row[counter] == 1:
                        dec = arcade.Sprite("images/items/cloud1.png", SCALING)
                    elif row[counter] == 2:
                        dec = arcade.Sprite("images/items/cloud2.png", SCALING)
                    elif row[counter] == 3:
                        dec = arcade.Sprite("images/tiles/liquidWater.png", SCALING)
                    elif row[counter] == 4:
                        dec = arcade.Sprite("images/tiles/liquidWaterTop_mid.png", SCALING)
                    elif row[counter] == 5:
                        dec = arcade.Sprite("images/tiles/fence.png", SCALING)
                    elif row[counter] == 6:
                        dec = arcade.Sprite("images/tiles/signRight.png", SCALING)
                    elif row[counter] == 7:
                        dec = arcade.Sprite("images/items/mushroomRed.png", SCALING)
                    dec.bottom = bottomPos
                    dec.left = leftPos
                    self.allSpritesList.append(dec)
                else:
                    dec = arcade.Sprite("images/tiles/grassCenter.png", SCALING)
                leftPos = leftPos + dec.width
            bottomPos = bottomPos + dec.width
            leftPos = 0


        self.player.stand_right_textures = []
        self.player.stand_right_textures.append(arcade.load_texture("images/player/p1_stand.png", scale=SCALING))
        self.player.stand_left_textures = []
        self.player.stand_left_textures.append(arcade.load_texture("images/player/p1_stand.png", scale=SCALING, mirrored=True))

        self.player.walk_right_textures = []
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk01.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk02.png", scale=SCALING))                                      
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk03.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk03.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk04.png", scale=SCALING))                                       
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk05.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk06.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk07.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk08.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk09.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk10.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk11.png", scale=SCALING))

        self.player.walk_left_textures = []
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk01.png", scale=SCALING, mirrored=True))                                       
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk02.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk03.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk04.png", scale=SCALING, mirrored=True))    
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk05.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk06.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk07.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk08.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk09.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk10.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk11.png", scale=SCALING, mirrored=True))

        self.player.walk_up_textures = []
        self.player.walk_up_textures.append(arcade.load_texture("images/player/p1_jump.png", scale=SCALING))
        self.player.walk_down_textures = []
        self.player.walk_down_textures.append(arcade.load_texture("images/player/p1_stand.png", scale=SCALING))

        # Starting position of the player
        self.player.texture_change_distance = 5
        self.player.center_x = 30
        self.player.center_y = SCREEN_HEIGHT // 2

        self.physicsEngine = arcade.PhysicsEnginePlatformer(self.player, self.wallList, gravity_constant=GRAVITY)

          # -- Draw an enemy on the ground
        enemy = arcade.Sprite("images/enemies/blockerMad.png", SCALING)


        enemy.bottom = SPRITE_SIZE
        enemy.left = SPRITE_SIZE * 2

        # Set enemy initial speed
        enemy.change_x = 2
        self.enemy_list.append()

        # -- Draw a enemy on the platform
        enemy = arcade.Sprite("images/enemies/blockerMad.png", SCALING)

        enemy.bottom = SPRITE_SIZE * 4
        enemy.left = SPRITE_SIZE * 4

        # Set boundaries on the left/right the enemy can't cross
        enemy.boundary_right = SPRITE_SIZE * 8
        enemy.boundary_left = SPRITE_SIZE * 3
        enemy.change_x = 2
        self.enemy_list.append()


    def update(self, delta_tie):
        self.player.update_animation()
        self.physicsEngine.update()

    def on_key_press(self, key, modifiers):
        if key == arcade.key.UP or key == arcade.key.SPACE:
            if self.physicsEngine.can_jump():
                self.player.change_y = MOVEMENT_SPEED * 3
        elif key == arcade.key.DOWN:
            self.player.change_y = -MOVEMENT_SPEED
        elif key == arcade.key.LEFT:
            self.player.change_x = -MOVEMENT_SPEED
        elif key == arcade.key.RIGHT:
            self.player.change_x = MOVEMENT_SPEED

    def on_key_release(self, key, modifiers):
        if key == arcade.key.UP or key == arcade.key.DOWN:
            self.player.change_y = 0
        elif key == arcade.key.LEFT or key == arcade.key.RIGHT:
            self.player.change_x = 0



mainWindow = MyGameWindow(SCREEN_WIDTH, SCREEN_HEIGHT)
mainWindow.setup()
arcade.run()
4

1 回答 1

0

都整理好了。任何想要它的人的代码...

### Samuel Ball ###

import arcade

#Constants for game window
SCALING = 1
SPRITE_NATIVE_SIZE = 128
SPRITE_SIZE = int(SPRITE_NATIVE_SIZE * SCALING)

SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768

# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
VIEWPORT_MARGIN = 40
RIGHT_MARGIN = 150

#Physics
MOVEMENT_SPEED = 5
JUMP_SPEED = 14
GRAVITY = 0.6


# 1 = box, 2 = grassMid, 3 = grassCliffLeft, 4 = grassCliffRight, 5 =grassCenter
sceneTiles = [
    [  2,  2,  2, 00, 00, 00, 00, 00, 00, 00, 00,  5,  5,  5,  2 ], #Bottom Row
    [  2,  2,  2, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,  2,  2 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,  2,  2 ],
    [ 00, 00, 00,  1, 00, 00, 00, 00, 00, 00, 00, 00,  3,  2,  4 ],
    [ 00, 00, 00, 00, 00,  1, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00,  1, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00,  1, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,  3,  2,  4 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],  #Top Row
    ]

# 1 = cloud1 2 = cloud2 3 = liquidWater 4 = liquidWaterTop_mid 5 = fence 6 = signRight 7 = mushroomRed
decorativeTiles = [
    [ 00, 00, 00,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3 ], #Bottom Row
    [ 00, 00,  7,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4 ],
    [  6, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [  1, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00,  2, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [  2, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ],
    [ 00, 00,  1, 00,  2, 00,  1, 00,  2, 00,  1,  0,  2, 00,  1 ],  #Top Row
    ]


# Set up sub class of arcade.window    
class MyGameWindow(arcade.Window):
    allSpritesList = arcade.SpriteList()
    wallList = arcade.SpriteList()
    player = arcade.AnimatedWalkingSprite()
    enemy = arcade.SpriteList()

    def __init__(self, width, height):
        super().__init__(width, height)
        #arcade.set_background_color([101, 216, 255])
        arcade.set_background_color(arcade.color.AERO_BLUE)


    def on_draw(self):
        arcade.start_render()
        self.allSpritesList.draw()
        self.enemy.draw()
        self.player.draw()

    def setup(self):




        leftPos = 0
        bottomPos = 0
        for row in sceneTiles:
            for counter in range(0, len(row)):
                if row[counter] > 0:
                    if row[counter] == 1:
                        wall = arcade.Sprite("images/tiles/box.png", SCALING)
                    elif row[counter] == 2:
                        wall = arcade.Sprite("images/tiles/grass.png", SCALING)
                    elif row[counter] == 3:
                        wall = arcade.Sprite("images/tiles/grassCliffLeft.png", SCALING)
                    elif row[counter] == 4:
                        wall = arcade.Sprite("images/tiles/grassCliffRight.png", SCALING)
                    wall.bottom = bottomPos
                    wall.left = leftPos
                    self.wallList.append(wall)
                    self.allSpritesList.append(wall)
                else:
                    wall = arcade.Sprite("images/tiles/grassCenter.png", SCALING)
                leftPos = leftPos + wall.width
            bottomPos = bottomPos + wall.height
            leftPos = 0

        leftPos = 0
        bottomPos = 0
        for row in decorativeTiles:
            for counter in range(0, len(row)):
                if row[counter] > 0:
                    if row[counter] == 1:
                        dec = arcade.Sprite("images/items/cloud1.png", SCALING)
                    elif row[counter] == 2:
                        dec = arcade.Sprite("images/items/cloud2.png", SCALING)
                    elif row[counter] == 3:
                        dec = arcade.Sprite("images/tiles/liquidWater.png", SCALING)
                    elif row[counter] == 4:
                        dec = arcade.Sprite("images/tiles/liquidWaterTop_mid.png", SCALING)
                    elif row[counter] == 5:
                        dec = arcade.Sprite("images/tiles/fence.png", SCALING)
                    elif row[counter] == 6:
                        dec = arcade.Sprite("images/tiles/signRight.png", SCALING)
                    elif row[counter] == 7:
                        dec = arcade.Sprite("images/items/mushroomRed.png", SCALING)
                    dec.bottom = bottomPos
                    dec.left = leftPos
                    self.allSpritesList.append(dec)
                else:
                    dec = arcade.Sprite("images/tiles/grassCenter.png", SCALING)
                leftPos = leftPos + dec.width
            bottomPos = bottomPos + dec.width
            leftPos = 0


        self.player.stand_right_textures = []
        self.player.stand_right_textures.append(arcade.load_texture("images/player/p1_stand.png", scale=SCALING))
        self.player.stand_left_textures = []
        self.player.stand_left_textures.append(arcade.load_texture("images/player/p1_stand.png", scale=SCALING, mirrored=True))

        self.player.walk_right_textures = []
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk01.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk02.png", scale=SCALING))                                      
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk03.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk03.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk04.png", scale=SCALING))                                       
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk05.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk06.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk07.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk08.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk09.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk10.png", scale=SCALING))
        self.player.walk_right_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk11.png", scale=SCALING))

        self.player.walk_left_textures = []
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk01.png", scale=SCALING, mirrored=True))                                       
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk02.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk03.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk04.png", scale=SCALING, mirrored=True))    
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk05.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk06.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk07.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk08.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk09.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk10.png", scale=SCALING, mirrored=True))
        self.player.walk_left_textures.append(arcade.load_texture("images/player/p1_walk/PNG/p1_walk11.png", scale=SCALING, mirrored=True))

        self.player.walk_up_textures = []
        self.player.walk_up_textures.append(arcade.load_texture("images/player/p1_jump.png", scale=SCALING))
        self.player.walk_down_textures = []
        self.player.walk_down_textures.append(arcade.load_texture("images/player/p1_stand.png", scale=SCALING))

        # Starting position of the player
        self.player.texture_change_distance = 5
        self.player.center_x = 30
        self.player.center_y = SCREEN_HEIGHT // 2

        self.physicsEngine = arcade.PhysicsEnginePlatformer(self.player, self.wallList, gravity_constant=GRAVITY)

        # Draw an enemy on the ground
        enemy = arcade.Sprite("images/enemies/blockerMad.png", SCALING)


        enemy.bottom = SPRITE_SIZE
        enemy.left = SPRITE_SIZE * 2

        # Set enemy initial speed
        enemy.change_x = 4
        self.enemy.append(enemy)

        # -- Draw a enemy on the platform
        enemy = arcade.Sprite("images/enemies/blockerMad.png", SCALING)

        enemy.bottom = SPRITE_SIZE * 4
        enemy.left = SPRITE_SIZE * 4

        # Set boundaries on the left/right the enemy can't cross
        enemy.boundary_right = SPRITE_SIZE * 8
        enemy.boundary_left = SPRITE_SIZE * 3
        enemy.change_x = 4
        self.enemy.append(enemy)


    def update(self, delta_tie):
        self.player.update_animation()
        self.physicsEngine.update()

    def on_key_press(self, key, modifiers):
        if key == arcade.key.UP or key == arcade.key.SPACE:
            if self.physicsEngine.can_jump():
                self.player.change_y = MOVEMENT_SPEED * 3
        elif key == arcade.key.DOWN:
            self.player.change_y = -MOVEMENT_SPEED
        elif key == arcade.key.LEFT:
            self.player.change_x = -MOVEMENT_SPEED
        elif key == arcade.key.RIGHT:
            self.player.change_x = MOVEMENT_SPEED

    def on_key_release(self, key, modifiers):
        if key == arcade.key.UP or key == arcade.key.DOWN:
            self.player.change_y = 0
        elif key == arcade.key.LEFT or key == arcade.key.RIGHT:
            self.player.change_x = 0



mainWindow = MyGameWindow(SCREEN_WIDTH, SCREEN_HEIGHT)
mainWindow.setup()
arcade.run()
于 2018-12-17T15:46:05.110 回答