コード例 #1
0
    def __init__(self):
        Scene.__init__(self)
        self.data = AppData()
        self.data["account"]["status"] = ""
        self.interface = None
        self.map_manager = MapManager()
        self.char = None
        self.audio = AudioManager()
        self.audio.add_track("data/music/iraq.mp3")

        @self.api.on("get_char_info")
        def char_info(data):
            if data["status"] == "ok":
                self.account["char"] = {**self.account["char"], **data["char"]}
            else:
                print("Network error")

        @self.api.on("find")
        @self.check
        def found(data):
            if data["status"] == "ok":
                self.account["battle_step"] = data["step"]
                self.account["battle_enemy"] = data["enemy"]
                self.account["battle_char"] = data["player"]
                self.account["battle_skills"] = data["skills"]
                self.account["battle_status"] = ""
                self.scene_manager.change("Battle",
                                          self.scene_manager.dumps["Battle"])
            elif data["desc"] == "Not enough money":
                self.account[
                    "status"] = "Не достаточно денег, чтобы начать бой (мин.: 10 руб.)"
            else:
                print("Network error")

        self.start()
コード例 #2
0
    def __init__(self):
        self.data = AppData()
        self.screen = self.data["screen"]
        self.ui = self.data["ui"]
        self.scene_manager = self.data["scene"]
        self.inventory_button = None
        self.elements = list()

        self.init_ui()
コード例 #3
0
ファイル: Window.py プロジェクト: mihett05/online-rpg
    def __init__(self, title: str):
        self.data = AppData()
        self.__title = title
        super().__init__(
            pygame.Rect(100, 100, self.data["screen"].get_width() - 200,
                        self.data["screen"].get_height() - 200),
            self.data["ui"], ["store"])

        self.close_button = None
        self.title_label = None
        self.init_ui()
コード例 #4
0
ファイル: Scene.py プロジェクト: mihett05/online-rpg
 def __init__(self):
     self.data = AppData()
     self.screen = self.data["screen"]
     self.size = (self.screen.get_width(), self.screen.get_height())
     self.ui = self.data["ui"]
     self.load_image = self.data["load_image"]
     self.api = self.data["api"]
     self.loader = self.data["loader"]
     self.account = self.data["account"]
     self.scene_manager = self.data["scene"]
     self.elements = list()
     self.name = None
コード例 #5
0
    def __init__(self):
        pygame.init()
        self.running = True
        self.data = AppData()

        self.data["load_image"] = self.load_image
        self.data["account"] = dict()
        self.isfullscreen = False
        if self.isfullscreen:
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode((1600, 900))
        pygame.display.set_caption("Kingdom of Eternal Kizaru")
        icon = pygame.image.load('data/icon.png')
        pygame.display.set_icon(icon)
        self.sprites = pygame.sprite.Group()
        self.data.set("screen", self.screen)
        with open("server.txt", "r") as f:
            text = f.read()
        self.loader = Loader(self.screen)
        self.data["loader"] = self.loader
        self.api = ServerAPI(text.split(":")[0], int(text.split(":")[1]))
        self.data["api"] = self.api
        self.ui = pygame_gui.UIManager((self.screen.get_width(), self.screen.get_height()))
        self.data["ui"] = self.ui
        self.clock = pygame.time.Clock()
        self.data["clock"] = self.clock
        self.fps = 60
        self.data["fps"] = self.fps
        self.scene = SceneManager()
        self.data["scene"] = self.scene
        self.data["close"] = self.close
        self.data["draw"] = self.draw
        self.data["windows"] = WindowManager()

        self.receive_thread = threading.Thread(target=self.api.receive_thread)
        self.broadcast_thread = threading.Thread(target=self.api.broadcast_thread)
コード例 #6
0
ファイル: Char.py プロジェクト: mihett05/online-rpg
 def __init__(self):
     self.group = pygame.sprite.Group()
     self.data = AppData()
     self.default_x_speed = math.ceil(self.data["screen"].get_width() / 300)
     self.default_y_speed = math.ceil(self.data["screen"].get_height() /
                                      200)
     scale = ((self.data["screen"].get_width() // 25) // 4 * 3,
              (self.data["screen"].get_height() // 14) // 4 * 3)
     self.sprites = {
         "up":
         AnimatedSprite((), self.load_image("sprites/char/up.png"), 1, 1,
                        128, 320, scale, "up"),
         "left":
         AnimatedSprite((), self.load_image("sprites/char/left.png"), 3, 1,
                        128, 320, scale, "left"),
         "down":
         AnimatedSprite((), self.load_image("sprites/char/down.png"), 3, 1,
                        128, 320, scale, "down"),
         "right":
         AnimatedSprite((), self.load_image("sprites/char/right.png"), 3, 1,
                        128, 320, scale, "right"),
         "up_run":
         AnimatedSprite((), self.load_image("sprites/char/up_run.png"), 10,
                        1, 128, 320, scale, "up_run", False),
         "left_run":
         AnimatedSprite((), self.load_image("sprites/char/left_run.png"),
                        10, 1, 128, 320, scale, "left_run", False),
         "down_run":
         AnimatedSprite((), self.load_image("sprites/char/down_run.png"),
                        10, 1, 128, 320, scale, "down_run", False),
         "right_run":
         AnimatedSprite((), self.load_image("sprites/char/right_run.png"),
                        10, 1, 128, 320, scale, "right_run", False)
     }
     self.sprite = self.sprites["down"].clone(self.group)
     self.side = None
     self.can_go_next = True
     self.x = self.data["map_manager"].map.spawn_point[0] * self.data[
         "map_manager"].map.width
     self.y = self.data["map_manager"].map.spawn_point[1] * self.data[
         "map_manager"].map.height
コード例 #7
0
ファイル: Map.py プロジェクト: mihett05/online-rpg
    def __init__(self, maps_path):
        self.data = AppData()
        self.path = os.path.join("data", "maps", maps_path)
        self.map_name = "".join(maps_path.split(".")[:-1])
        self.cache_path = os.path.join("cache", self.map_name)
        self.map = None
        self.view = None
        self.sprites = pygame.sprite.Group()
        self.blocks = {}
        self.blockers = pygame.sprite.Group()
        self.teleports = pygame.sprite.Group()
        self.windows = pygame.sprite.Group()
        self.is_active = True
        self.spawn_point = (0, 0)
        self.width = self.data["screen"].get_width() // 25
        self.height = self.data["screen"].get_height() // 14

        if zipfile.is_zipfile(self.path):
            self.load()
        else:
            print(f"Can't load {maps_path}")
コード例 #8
0
ファイル: SceneManager.py プロジェクト: mihett05/online-rpg
 def __init__(self):
     try:
         self.__getattribute__("ui")
     except AttributeError:
         self.name = None
         self.proto = None
         self.data = AppData()
         self.dumps = {
             "MainMenu": MainMenuScene,
             "CharsScene": CharsScene,
             "Settings": SettingsScene,
             "CharMaker": CharMakerScene,
             "CharDelete": CharDeleteScene,
             "Game": GameScene,
             "Register": RegisterScene,
             "login": LoginScene,
             "Battle": BattleScene
         }
         self.ui = self.data["ui"]
         self.queue = []
         self.scene = None
         self.last = None
         self.game_scene = None
コード例 #9
0
class Game:
    def __init__(self):
        pygame.init()
        self.running = True
        self.data = AppData()

        self.data["load_image"] = self.load_image
        self.data["account"] = dict()
        self.isfullscreen = False
        if self.isfullscreen:
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode((1600, 900))
        pygame.display.set_caption("Kingdom of Eternal Kizaru")
        icon = pygame.image.load('data/icon.png')
        pygame.display.set_icon(icon)
        self.sprites = pygame.sprite.Group()
        self.data.set("screen", self.screen)
        with open("server.txt", "r") as f:
            text = f.read()
        self.loader = Loader(self.screen)
        self.data["loader"] = self.loader
        self.api = ServerAPI(text.split(":")[0], int(text.split(":")[1]))
        self.data["api"] = self.api
        self.ui = pygame_gui.UIManager((self.screen.get_width(), self.screen.get_height()))
        self.data["ui"] = self.ui
        self.clock = pygame.time.Clock()
        self.data["clock"] = self.clock
        self.fps = 60
        self.data["fps"] = self.fps
        self.scene = SceneManager()
        self.data["scene"] = self.scene
        self.data["close"] = self.close
        self.data["draw"] = self.draw
        self.data["windows"] = WindowManager()

        self.receive_thread = threading.Thread(target=self.api.receive_thread)
        self.broadcast_thread = threading.Thread(target=self.api.broadcast_thread)

    @staticmethod
    def load_image(name, color_key=None):
        try:
            fullname = os.path.join('data', name)
            image = pygame.image.load(fullname)
            if not color_key:
                color_key = image.get_at((0, 0))
            if color_key != 'NO':
                image.set_colorkey(color_key)
            return image
        except pygame.error:
            print("Can't load image data/{}".format(name))
            return pygame.image.load(os.path.join("data", "default.png")).convert()

    def close(self):
        pygame.quit()
        self.api.logout()
        sleep(0.25)
        self.api.close()
        self.receive_thread.join()
        self.broadcast_thread.join()
        self.running = False
        sys.exit(0)

    def draw(self):
        if self.screen is not None:
            self.screen.fill((0, 0, 0))
            if self.scene.scene is not None:
                self.scene.scene.draw()
            self.loader.draw()
            try:
                self.ui.draw_ui(self.screen)
            except BaseException:
                pass
            pygame.display.flip()

    def run(self):
        self.api.connect()
        self.receive_thread.start()
        self.broadcast_thread.start()
        self.scene.change("login", LoginScene)
        while self.running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = False
                elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
                    if event.key == pygame.K_F4:
                        self.running = False
                self.ui.process_events(event)
                self.scene.scene.process_events(event)
            self.draw()
            self.clock.tick(self.fps)
            try:
                self.ui.update(self.clock.tick() / 1000)
            except BaseException:
                pass
        self.close()