def on_savedata_readed(self, data): self.score = data["Player"]["score"] for effect in data["Player"]["Effects"]: effect_class: BaseEffect = Registry.get_effect(effect["id"]) time_length: float = effect["timeRemaining"] strength: float = effect["strength"] self.start_effect(effect_class, Registry.get_scene("Game"), time_length, strength)
def _update_rot_tex(self): """ Updates the rotation texture :return: """ image = Registry.get_texture("sprite", "player", rotation=int(self.rotation - (self.rotation % 1))) c = Registry.get_scene("Game").canvas c.itemconfig(self.id, image=image)
def change_scene(self, name, *args, **kwargs): if not Registry.scene_exists(name): raise SceneNotFoundError(f"scene '{name}' not existent") # Hide old scene first if self.currentScene is not None: self.currentScene.hide_scene() # Get new scene and show it new_scene = Registry.get_scene(name) self.currentSceneName = name self.currentScene: Scene = new_scene self.currentScene.show_scene(*args, **kwargs)
def distance(self, to): canvas = Registry.get_scene("Game").canvas try: # try: x1, y1 = self.get_coords() # except ValueError: # self.instant_death() # try: x2, y2 = to.get_coords() # except ValueError: # to.instant_death() # print(f"POINT_1: {x1, y1}") # print(f"POINT_2: {x2, y2}") # noinspection PyUnboundLocalVariable return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) except ValueError: return math.inf except UnboundLocalError: return math.inf
def create(self, x, y, radius=5, speed=5, health=5): if self.baseClass is None: raise UnlocalizedNameError(f"BubbleObject is used for Sprite information, use the base_class argument with " f"a Bubble-instance instead of NoneType to fix this problem") if self.id is not None: raise OverflowError(f"BubbleObject is already created") canvas: Canvas = Registry.get_scene("Game").canvas self.defenceMultiplier = self.baseClass.defenceMultiplier self.attackMultiplier = self.baseClass.attackMultiplier self.baseSpeed = speed self.health = health self.radius = radius / 2 self.id = canvas.create_image( x, y, image=Registry.get_texture("qbubbles:bubble", self.baseClass.get_uname(), radius=radius)) self._objectData["radius"] = radius self._objectData["speed"] = speed self._objectData["health"] = health self._objectData["Position"] = (x, y) UpdateEvent.bind(self.on_update) CleanUpEvent.bind(self.on_cleanup) CollisionEvent.bind(self.on_collision)
def __init__(self): super(TeleportMode, self).__init__("teleport") self.scene = Registry.get_scene("Game")
def move_joy(self, x=0, y=0): Registry.get_scene("Game").canvas.move(self.id, x, y)
def get_coords(self): return Registry.get_scene("Game").canvas.coords(self.id)
def damage(self, value: float): scene = Registry.get_scene("Game") if not SpriteDamageEvent(scene, self).cancel: self.health -= value / self.defenceValue if self.health <= 0: self.dead = True
def teleport(self, x, y): Registry.get_scene("Game").canvas.coords(self.id, x, y) self._objectData["Position"] = self.get_coords()
def _c_create_image(x, y, image, anchor="nw"): return Registry.get_scene("Game").canvas.create_image(x, y, image=image, anchor=anchor)
def create(self, x, y): Registry.get_scene("Game").gameObjects.append(self)
def delete(self) -> NoReturn: canvas: Canvas = Registry.get_scene("Game").canvas canvas.delete(self.id)
def show_scene(self, log, config, modes, stats, icons, foregrounds, font, launcher_cfg): """ Set store menu. Base of menu control (Used for creating bg, items and icons) :rtype: object """ # Logging information for debug. self.l_cfg = launcher_cfg self.foregrounds = foregrounds log.info("Store.__init__", "Player Opened the store") # Setup for store, the pause and controls. # Set storemode to ON (True) # and the pause ON (True). So the bubbles / ship can't moving. Registry.get_scene("GameScene").pause = True self.canvas.focus_set() self.canvas.bind("<Key-Down>", ) # Background color (Can be changed by fill=<color-string> self.bg = self.canvas.create_rectangle(0, 0, config["width"], config["height"], fill="white") self.title = self.canvas.create_rectangle(-1, -1, config["width"] + 1, 48, fill="#373737") # Selection self.maximal = 3 self.selected = 0 # Info / icons dictionaries self.button = {} self.frame = {} self.item = {} self.name = {} self.d_icon = {} self.info = {} self.price = {} self.c_icon = {} self.coins = {} # Number of diamonds you have: self.vDiamonds = self.canvas.create_text(25, 25, text="Diamonds: " + str(stats["diamonds"]), fill="white", anchor=W, font=(font, 18)) # Setups items and price. info = Reader("versions/"+launcher_cfg["versionDir"]+"/config/store.nzt").get_decoded() i = 0 self.maximal = len(info) - 1 y = 50 x = 2 index = 0 for x in range(int(Registry.gameData["WindowWidth"]/200)): for y in range(50): self.button[index] = self.canvas2.create_rectangle(50 + x, 1 + y, 100 + x, 51 + y, outline="white", fill="white") self.frame[index] = self.canvas2.create_rectangle( 0 + x, 0 + y, 190 + x, 140 + y, outline="#cfcfcf", fill="white") self.item[index] = self.canvas2.create_image( 100 + x, 26 + y, image=None) self.name[index] = self.canvas2.create_text( 100 + x, 75 + y, text=info[index]["name"], fill="#7f7f7f", anchor=CENTER) self.d_icon[index] = self.canvas2.create_image( 170 + x, 117 + y, image=Registry.get_storeicon(), anchor=E) self.info[index] = self.canvas2.create_text( 150 + x, 117 + y, text=str(int(info[index]["diamonds"])), fill="#7f7f7f", anchor=E) self.c_icon[index] = self.canvas2.create_image( 20 + x, 117 + y, image=icons["store-coin"], anchor=W) self.coins[index] = self.canvas2.create_text( 40 + x, 117 + y, text=info[index]["coins"], fill="#7f7f7f", anchor=W) self.price[i] = int(info[index]["diamonds"]) for b in info: if y > config["height"] - 160: y -= 900 x += 200 self.button[i] = self.canvas.create_rectangle(50 + x, 1 + y, 100 + x, 51 + y, outline="white", fill="white") self.frame[i] = self.canvas.create_rectangle(0 + x, 0 + y, 190 + x, 140 + y, outline="#cfcfcf", fill="white") self.item[i] = self.canvas.create_image(100 + x, 26 + y, image=icons["store-pack"][i]) self.name[i] = self.canvas.create_text(100 + x, 75 + y, text=b["name"], fill="#7f7f7f", anchor=CENTER) self.d_icon[i] = self.canvas.create_image(170 + x, 117 + y, image=icons["store-diamond"], anchor=E) self.info[i] = self.canvas.create_text(150 + x, 117 + y, text=str(int(b["diamonds"])), fill="#7f7f7f", anchor=E) self.price[i] = int(b["diamonds"]) self.c_icon[i] = self.canvas.create_image(20 + x, 117 + y, image=icons["store-coin"], anchor=W) self.coins[i] = self.canvas.create_text(40 + x, 117 + y, text=b["coins"], fill="#7f7f7f", anchor=W) y += 150 i += 1 # Sets up the selected, the first. self.canvas.itemconfig(self.button[self.selected], fill="#7f7f7f", outline="#373737") self.canvas.itemconfig(self.frame[self.selected], fill="#7f7f7f", outline="#7f7f7f") self.canvas.itemconfig(self.info[self.selected], fill="#373737") self.canvas.itemconfig(self.coins[self.selected], fill="#373737") # Foreground for fade # self.fg = self.canvas.create_image(mid_x, mid_y, image=foregrounds["store-fg"]) self.w = None self.b = None self.b2 = None self.close = None