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

如本文章标有价格,需议价或其它事情商议请加微信pythonxia

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()

下载完整源代码与素材,请扫码付款。

VIP免费查看

已有3人支付

本站所有作品,教程等皆为原创,版权所有。只供个人及单位内部研究使用,对外展示或传播必需经本站同意,且注明来自本站。培训机构等用本站资源培训学生,需经本站授权。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。入住QQ群:225792826 和爱好者共同交流,并且能下载免费提供的Python资源(需提供真实姓名才可入群)
李兴球的博客_Python创意编程技术前沿_pygame » python街机萤火虫勇闯黑夜迷宫_大型滚动地图
scratch

学本领,探索更大的世界!

李兴球博客 风火轮编程主页