def setSpeed(self, speed): self.speed = speed # update the interval since we edited the speed if not self.timer is None: self.timer.destroy() self.timer = Global.Interval(self.updateFrames, 1000 / self.getSpeed())
def create(self): sX = Global.screenSize[0] sY = Global.screenSize[1] self.currentOpacity = 0 self.fadeDone = False self.fadeDirection = "in" self.fadeInterval = Global.Interval(self.updateOpacity, 100) self.functionToCallWhenDone = None super().create()
def moveElementTo(self, elementName, x, y, time, steps=24): currentElement = self.getElementByName(elementName) if currentElement: if currentElement['element']: currentPosition = currentElement['element'].getPosition() currentElement['isMoving'] = True currentElement['target'] = [x, y] currentElement['vector'] = [(x - currentPosition[0]) / steps, (y - currentPosition[1]) / steps] currentElement['timer'] = Global.Interval( (lambda: self.updatePosition(currentElement, x, y)), time / steps) currentElement['timeout'] = Global.setTimeout( (lambda: self.destroyTimer(currentElement)), time) else: return None
def __init__(self, imagePath, frames=None, uniqueLoop=False): super().__init__(imagePath) self.type = "sprite" self.speed = 24 # images per second self.isPaused = False self.currentImage = 0 self.isUniqueLoop = uniqueLoop self.loopFinished = False self.isFlipped = False texture = self.getTexture() textureSize = texture.get_size() if not frames: self.maxImage = textureSize[0] / 64 else: self.maxImage = frames self.frameWidth = textureSize[0] / self.maxImage self.frameHeight = textureSize[1] self.timer = None self.timer = Global.Interval(self.updateFrames, 1000 / self.getSpeed())
def define(self): sX = Global.screenSize[0] sY = Global.screenSize[1] self.elements['background'] = Image("assets/homescreen.png") self.elements['background'].setPosition(0, 0) self.elements['background'].setSize(1 * sX, 1 * sY) self.elements['background'].setDepth(22) self.elements['sky'] = Image("assets/sky.png") self.elements['sky'].setPosition(0, 0) self.elements['sky'].setSize(1 * sX, 1 * sY) self.elements['sky'].setDepth(21) self.elements['sky'].setVisible(False) self.elements['sky_darker'] = Image("assets/sky_darker.png") self.elements['sky_darker'].setPosition(0, 0) self.elements['sky_darker'].setSize(1 * sX, 1 * sY) self.elements['sky_darker'].setDepth(20) self.elements['sky_darker'].setVisible(False) self.elements['menu_background'] = Image("assets/dot.png") self.elements['menu_background'].setPosition(0, 0) self.elements['menu_background'].setSize(0.5 * sX, 1 * sY) self.elements['menu_background'].setDepth(23) self.elements['menu_background'].setOpacity(0.25) self.elements['logo'] = Image("assets/logo_white.png") self.elements['logo'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, 60) self.elements['logo'].setSize((0.5 * sX) - 180, ((0.5 * sX) - 180) / (649 / 186)) self.elements['logo'].setDepth(24) button_width = (0.5 * sX) - 180 button_height = ((0.5 * sX) - 180) / (269 / 68) # play button self.elements['play_background'] = Image("assets/white.png") self.elements['play_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, 60 + ((0.5 * sX) - 180) / (649 / 186) + 20) self.elements['play_background'].setSize(button_width, button_height) self.elements['play_background'].setDepth(24) self.elements['play_background'].setVisible(False) self.elements['play_text'] = Text("Jouer", "arial") self.elements['play_text'].setFontSize(25) self.elements['play_text'].setColor((43, 56, 66)) self.elements['play_text'].setDepth(25) self.elements['play_text'].setAlign("center") self.elements['play_text'].setPosition( ((0.5 * sX) / 2), 60 + ((0.5 * sX) - 180) / (649 / 186) + 20 + button_height / 2 - 20) # settings button self.elements['settings_background'] = Image("assets/white.png") self.elements['settings_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, self.elements['play_background'].position[1] + 80) self.elements['settings_background'].setSize(button_width, button_height) self.elements['settings_background'].setDepth(24) self.elements['settings_background'].setVisible(False) self.elements['settings_text'] = Text("Paramètres", "arial") self.elements['settings_text'].setFontSize(25) self.elements['settings_text'].setColor((43, 56, 66)) self.elements['settings_text'].setDepth(25) self.elements['settings_text'].setAlign("center") self.elements['settings_text'].setPosition( ((0.5 * sX) / 2), self.elements['play_text'].position[1] + 80) # credits button self.elements['credits_background'] = Image("assets/white.png") self.elements['credits_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, self.elements['settings_background'].position[1] + 80) self.elements['credits_background'].setSize(button_width, button_height) self.elements['credits_background'].setDepth(24) self.elements['credits_background'].setVisible(False) self.elements['credits_text'] = Text("Crédits", "arial") self.elements['credits_text'].setFontSize(25) self.elements['credits_text'].setColor((43, 56, 66)) self.elements['credits_text'].setDepth(25) self.elements['credits_text'].setAlign("center") self.elements['credits_text'].setPosition( ((0.5 * sX) / 2), self.elements['settings_text'].position[1] + 80) # quit button self.elements['quit_background'] = Image("assets/white.png") self.elements['quit_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, self.elements['credits_background'].position[1] + 80) self.elements['quit_background'].setSize(button_width, button_height) self.elements['quit_background'].setDepth(24) self.elements['quit_background'].setVisible(False) self.elements['quit_text'] = Text("Quitter", "arial") self.elements['quit_text'].setFontSize(25) self.elements['quit_text'].setColor((43, 56, 66)) self.elements['quit_text'].setDepth(25) self.elements['quit_text'].setAlign("center") self.elements['quit_text'].setPosition( ((0.5 * sX) / 2), self.elements['credits_text'].position[1] + 80) # game menu self.elements['game_background'] = Image("assets/dot.png") self.elements['game_background'].setPosition( 0.5 * sX + 20, 60 + ((0.5 * sX) - 180) / (649 / 186) + 20) self.elements['game_background'].setSize(0.5 * sX - 40, 160) self.elements['game_background'].setDepth(25) self.elements['game_background'].setOpacity(0.25) self.elements['game_background'].setVisible(False) self.elements['continue_background'] = Image("assets/white.png") self.elements['continue_background'].setPosition( 0.5 * sX + 20, self.elements['game_background'].position[1]) self.elements['continue_background'].setSize(0.5 * sX - 40, button_height) self.elements['continue_background'].setDepth(26) self.elements['continue_background'].setVisible(False) self.elements['continue_text'] = Text("Continuer", "arial") self.elements['continue_text'].setFontSize(25) self.elements['continue_text'].setColor((243, 243, 243)) self.elements['continue_text'].setDepth(27) self.elements['continue_text'].setAlign("center") self.elements['continue_text'].setVisible(False) self.elements['continue_text'].setPosition( ((0.5 * sX) / 2) + 0.5 * sX + 20, self.elements['game_background'].position[1] + 20) self.elements['new_background'] = Image("assets/white.png") self.elements['new_background'].setPosition( 0.5 * sX + 20, self.elements['continue_background'].position[1] + 80) self.elements['new_background'].setSize(0.5 * sX - 40, button_height) self.elements['new_background'].setDepth(26) self.elements['new_background'].setVisible(False) self.elements['new_text'] = Text("Nouvelle partie", "arial") self.elements['new_text'].setFontSize(25) self.elements['new_text'].setColor((243, 243, 243)) self.elements['new_text'].setDepth(27) self.elements['new_text'].setAlign("center") self.elements['new_text'].setVisible(False) self.elements['new_text'].setPosition( ((0.5 * sX) / 2) + 0.5 * sX + 20, self.elements['continue_text'].position[1] + 80) global thunderInterval thunderInterval = Global.Interval(self.editSky, 1000)
def changeFade(self): self.fadeDirection = "out" self.fadeInterval = Global.Interval(self.updateOpacity, 100) self.fadeDone = False