def __init__(self, parent, position: (int, int) = (0, 0)) -> None: self._res_dir = resource_path("res/images") self.parent = parent self._rect = Rect((0, 0, 0, 0)) self._rect.x = position[0] self._rect.y = position[1] self.__is_draw = True
def __init__(self, width: int, height: int) -> None: pygame.init() os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.display.set_caption("Bee Island") self.__FPS = 60 self.__size = self.width, self.height = width, height self.__screen = pygame.display.set_mode(self.size) icon = pygame.image.load("{0}/icon.ico".format( resource_path("res/images/"))) pygame.display.set_icon(icon) Localization.set_locale(LocalList.RU) self.database = Database() self.main_player = Player() self.__scene_map = { "Map": MapScene(self, name="Map", player=self.main_player), "Farm": FarmScene(self, name="Farm", player=self.main_player), "Main": MainMenuScene(self, name="Main", player=self.main_player) } self.__current_scene = self.__scene_map["Map"] self.change_scene("Main") self.__prev_scene = None self.__done = False self.__clock = Clock()
def __init__(self, main_window, name: str, player: Player) -> None: self._res_dir = resource_path("res") self.main_window = main_window self.player = player self._name = name self._render_list = [] self._localization = None
def __init__(self) -> None: if Database.__instance is not None: raise Exception("This class is singleton") else: Database.__instance = self self.__db_location_dir = resource_path("res/db") p = "{0}/main.db".format(self.__db_location_dir) self.__conn = sqlite3.connect(p)
def __init__(self, parent, position: (int, int), area) -> None: RenderObject.__init__(self, parent=parent, position=position) self.images = dict() self.images.update( {"right": pygame.image.load("{0}/images/bee/bee1_r.png".format(resource_path("res"))).convert_alpha()}) self.images.update( {"down": pygame.image.load("{0}/images/bee/bee1_d.png".format(resource_path("res"))).convert_alpha()}) self.image = self.images["right"] self.image.set_colorkey((0, 0, 0)) self.movement = Direction.STILL self.speed = 2 self._rect = self.image.get_rect() self.points = [] self.area = area self.area_size = area.rect.x, area.rect.y self.mask = pygame.mask.from_surface(self.image) self.in_conquered = False self.move_keys_wasd = [pygame.K_d, pygame.K_a, pygame.K_w, pygame.K_s]
def set_image_by_state(self, state: ButtonState, path: str) -> None: state = int(state) path = resource_path("{0}/{1}".format(self._res_dir, path)) try: ext = os.path.splitext(path)[1] if ext == ".png": self._images[state] = pygame.image.load(path).convert_alpha() else: self._images[state] = pygame.image.load(path) except pygame.error: raise FileNotFoundError("image {0} not found".format(path))
def __init__(self, parent, font_size: int, text: str = "", font_name: str = "segoeprint", position: (int, int) = (0, 0), bold: bool = False, color: tuple = (159, 80, 17)) -> None: RenderObject.__init__(self, parent=parent, position=position) self._font_name = font_name self._font_size = font_size self._bold = bold self._font = pygame.font.Font(resource_path("res/fonts/{0}.ttf".format(self._font_name)), self._font_size) self._font.set_bold(self._bold) self._text = text self._color = color self._normal_color = color self._image = None self.set_text(text)
def __init__(self, area) -> None: pygame.sprite.Sprite.__init__(self) self.area = area self.image = pygame.image.load("{0}/images/spider1.png".format( resource_path("res"))).convert_alpha() self.image.set_colorkey((255, 255, 255)) self.alive = True self.__velocity_x = 0 self.__velocity_y = 0 self.vel_x = 5 self.vel_y = 5 self.rect = self.image.get_rect() self.rect.x = random.randint( self.area.border_size, self.area.rect.w - self.area.border_size - self.rect.w) self.rect.y = random.randint( self.area.border_size, self.area.rect.h - self.area.border_size - self.rect.h) self.mask = pygame.mask.from_surface(self.image)
def __read_locale(self): locale_path = resource_path("res/locales/{0}.json".format(self.__path)) with open(locale_path, encoding="utf-8") as json_file: data = json.load(json_file) return data
def __init__(self, position: (int, int), color: FlowersData) -> None: Sprite.__init__(self) self.color = color self.image = pygame.image.load("{0}/flowers/{1}.png".format( resource_path("res/images"), self.color.value)).convert_alpha() self.rect = self.image.get_rect(topleft=position)