以下是部分代码预览:
"""
Arcade街机多房间关卡演示例
"""
import arcade
import os
SPRITE_SCALING = 0.5
SPRITE_NATIVE_SIZE = 128
SPRITE_SIZE = int(SPRITE_NATIVE_SIZE * SPRITE_SCALING)
SCREEN_WIDTH = SPRITE_SIZE * 14
SCREEN_HEIGHT = SPRITE_SIZE * 10
SCREEN_TITLE = "Arcade街机多房间关卡演示例"
MOVEMENT_SPEED = 5
class Room:
"""
房间的父类,只是设定了墙列表和背景属性
"""
def __init__(self):
# 定义墙列表
self.wall_list = None
# 定义背景属性
self.background = None
def setup_room_1():
"""
创建房间一
"""
room = Room()
""" 给房间的wall_list赋值. """
# Sprite lists
room.wall_list = arcade.SpriteList()
wall = arcade.Sprite("images/boxCrate_double.png", SPRITE_SCALING)
wall.left = 7 * SPRITE_SIZE
wall.bottom = 5 * SPRITE_SIZE
room.wall_list.append(wall)
# 可以在房间里加些金币道具等角色
# 加载此关的背景
room.background = arcade.load_texture("images/background.jpg")
return room
def setup_room_2():
"""
创建房间2
"""
room = Room()
class MyGame(arcade.Window):
""" Main application class. """
def __init__(self, width, height, title):
"""
Initializer
"""
super().__init__(width, height, title)
# 房间的索引号
self.current_room = 0
# 定义玩家的一些变量
self.rooms = None
self.player_sprite = None
self.player_list = None
self.physics_engine = None
def setup(self):
""" Set up the game and initialize the variables. """
# 实例化玩家对象
self.player_sprite = arcade.Sprite("images/character.png", SPRITE_SCALING)
self.player_sprite.center_x = 100
self.player_sprite.center_y = 100
self.player_list = arcade.SpriteList()
self.player_list.append(self.player_sprite)
# 房间列表
self.rooms = []
# 设置房间.
room = setup_room_1()
self.rooms.append(room)
def on_draw(self):
"""
渲染房间
"""
def main():
""" Main method """
window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
window.setup()
arcade.run()
if __name__ == "__main__":
main()
如需要查看完整代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
