python街机萤火虫勇闯黑夜迷宫_大型滚动地图

python街机萤火虫勇闯黑夜迷宫_大型滚动地图

python arcade 萤火虫勇闯黑夜迷宫_大型滚动地图 lixingqiu

python arcade 萤火虫勇闯黑夜迷宫_大型滚动地图 lixingqiu下面gif动录制作软件把图片进行了压缩,所以呈现了“圆圈”效果。实际上效果像上图这样。python arcade 萤火虫勇闯黑夜迷宫_大型滚动地图 lixingqiu

以下是部分代码预览:

"""
萤火虫勇闯黑夜迷宫_大型滚动地图

"""

import random
import arcade
import os

SPRITE_SCALING = 1

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SPRITE_PIXEL_SIZE = 64

# 距离屏幕边距的最小距离 

VIEWPORT_MARGIN = 40
MOVEMENT_SPEED = 5

class MyGame(arcade.Window):
    """主应用程序类. """

    def __init__(self, width, height):
        """
        初始化器
        """
        super().__init__(width, height,"萤火虫勇闯黑夜迷宫_大型滚动地图 lixingqiu")

        self.game_over = False

        # 角色列表
        self.player_list = None
        self.coin_list = None

        # 设置游戏及玩家相关变量
        self.score = 0
        self.player_sprite = None
        self.wall_list = None
        self.physics_engine = None
        self.view_bottom = 0
        self.view_left = 0

    def setup(self):
        """ 实例化变量 """

        # 角色列表
        self.player_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()

        # 设置蒙板
        self.mask = arcade.Sprite("images/mask.png")
        self.mask.scale = 2

        # 实例化玩家操作的角色
        self.score = 0
        self.player_sprite = arcade.Sprite("images/lixingqiu.png", 0.4)
        self.player_sprite.center_x = 128
        self.player_sprite.center_y = 270
        self.player_list.append(self.player_sprite)

    def on_draw(self):
        """
        渲染屏幕
        """

        # 开始渲染
        arcade.start_render()

        # 画各个角色
        self.wall_list.draw()
        self.player_list.draw()
        self.小东西_list.draw()
        self.mask.draw()
                

    def on_key_press(self, key, modifiers):
        """当按键时调用此方法 """

        if key == arcade.key.UP:
            self.player_sprite.change_y = MOVEMENT_SPEED
        elif key == arcade.key.DOWN:
            self.player_sprite.change_y = -MOVEMENT_SPEED
        elif key == arcade.key.LEFT:
            self.player_sprite.change_x = -MOVEMENT_SPEED
        elif key == arcade.key.RIGHT:
            self.player_sprite.change_x = MOVEMENT_SPEED

    def on_key_release(self, key, modifiers):
        """当松开按键时调用此方法 """

        if key == arcade.key.UP or key == arcade.key.DOWN:
            self.player_sprite.change_y = 0
        elif key == arcade.key.LEFT or key == arcade.key.RIGHT:
            self.player_sprite.change_x = 0

    def update(self, delta_time):
        """ 游戏逻辑设定,结果都是更新坐标/角度,删除/添加角色等。"""

        # 调用物理引擎
        self.physics_engine.update()

        # 蒙板跟随玩家角色
        self.mask.center_x = self.player_sprite.center_x
        self.mask.center_y = self.player_sprite.center_y


def main():
    """ 主要方法"""
    window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT)
    window.setup()
    arcade.run()

if __name__ == "__main__":
    main()

下载完整源代码与素材,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客

评论已关闭。