Example #1
0
 def updateDistance(self):
     if not self.player.checkDead():
         self.distance += 0.1
     self.distance_counter.setText("Distance: " + str(round(self.distance, 1)))
     self.distance_counter.setPos(x = getWindowDimensionsScaled()[0] - self.distance_counter.width - 16)
     self.max_distance_counter.setText("Max Distance: " + str(round(max(settings.getValue(HIGH_SCORE, 0.0), self.distance), 1)))
     self.max_distance_counter.setPos(x = getWindowDimensionsScaled()[0] - self.max_distance_counter.width - 16)
Example #2
0
 def startCredits(self):
     self.removeMapData()
     resetLag()
     self.fade_darkener.fadeIn(60)
     playMusic(toStringPath(FULL_MUSIC_PATH + ["ending.ogg"]))
     self.removeEndingData()
     self.ending_player = GraphicInterface()
     self.ending_player.setSprite(toStringPath(CHAR_GRAPHICS_FULL_PATH + ["char.png"]))
     self.ending_player.setPos(128,128)
     self.ending_player.setSpriteCenter(True, True)
     self.ending_player.setSpriteFollowCamera(True)
     self.ending_player.setSpriteAnimation("WALK_DOWN")
     self.ending_text = createLabel("Thanks for playing!", font = "kaimono3.gfont2")
     self.ending_text.setPos(128, 64)
     self.ending_text.follow_camera = True
     self.ending_text.setCenter(True,True)
     self.ending_text2 = createLabel("You got the", font = "kaimono3.gfont2")
     self.ending_text2.setPos(128, 192)
     self.ending_text2.follow_camera = True
     self.ending_text2.setCenter(True,True)
     self.ending_text3 = createLabel("Golden Squid!", font = "kaimono3.gfont2")
     self.ending_text3.setPos(128, 176)
     self.ending_text3.follow_camera = True
     self.ending_text3.setCenter(True,True)
     xoffset = getWindowDimensionsScaled()[0]/2 - (len(SQUID_GRAPHICS)-1)*ENDING_SQUID_X_SPACING/2
     for i, val in enumerate(SQUID_GRAPHICS.values()):
         self.ending_squids.append(GraphicInterface())
         self.ending_squids[-1].setSprite(toStringPath(CHAR_GRAPHICS_FULL_PATH + [val]))
         self.ending_squids[-1].setSpriteCenter(True, True)
         self.ending_squids[-1].setSpriteFollowCamera(True)
         self.ending_squids[-1].setPos(xoffset + i*ENDING_SQUID_X_SPACING, 96)
Example #3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.player_starting_pos = (128, 48)
     self.game_flags = {}
     self.trophies_obtained = {}
     self.player_health = 3
     self.fade_darkener = Darkener()
     self.bg = GraphicInterface()
     self.bg.setSprite(toStringPath(BG_GRAPHICS_FULL_PATH + ["loading.png"]))
     self.bg.setSpriteLayer(LOADING_LAYER)
     self.mappe = None
     
     self.ending_player = None
     self.ending_text = None
     self.ending_text2 = None
     self.ending_text3 = None
     self.ending_squids = []
     
     self.player_health_sprites = []
     for i in range(3):
         self.player_health_sprites.append(GraphicInterface())
         self.player_health_sprites[-1].setSprite(toStringPath(UI_GRAPHICS_FULL_PATH  + ["health.png"]))
         self.player_health_sprites[-1].setPos(HEALTH_X_OFFSET + HEALTH_X_STEP*i, getWindowDimensionsScaled()[1] + HEALTH_Y_OFFSET)
         self.player_health_sprites[-1].setSpriteFollowCamera(True)
         self.player_health_sprites[-1].setSpriteLayer(UI_LAYER)
         
     self.squid_trophy_sprites = []
     for i in range(3):
         self.squid_trophy_sprites.append(GraphicInterface())
         self.squid_trophy_sprites[-1].setSpriteFollowCamera(True)
         self.squid_trophy_sprites[-1].setPos(SQUID_X_OFFSET + SQUID_X_STEP*i, getWindowDimensionsScaled()[1] + SQUID_Y_OFFSET)
         self.squid_trophy_sprites[-1].setSpriteLayer(UI_LAYER)
         
     
     self.Schedule(self.createStartingMap, 2)
     
     self.addCustomListener(SQUID_TROPHY_OBTAINED_EVENT, self.squidTrophyObtained)
     self.addQueryListener(SQUID_TROPHY_OBTAINED_QUERY, self.checkTrophyObtained)
     self.addQueryListener(ALL_SQUID_TROPHIES_OBTAINED_QUERY, self.hasAllTrophies)
     self.addCustomListener(PLAYER_REDUCE_HP_EVENT, self.reduceHP)
     self.addCustomListener(PLAYER_MAX_HP_EVENT, self.maxHP)
     self.addQueryListener(CHECK_PLAYER_DEAD_QUERY, self.checkPlayerDead)
     self.addCustomListener(PUSH_SAVE_EVENT, self.pushSave)
     self.addCustomListener(FINAL_SQUID_OBTAINED_EVENT , self.finalSquidObtained)
     self.addCustomListener(GAME_LOST_EVENT, self.gameLost)
     
     self.loadSave()
Example #4
0
    def __init__(self, color=COLOR_BLACK, *args, **kwargs):
        super(Darkener, self).__init__(*args, **kwargs)
        self.fade_total_time = 0
        self.fade_time = 0
        self.done_fading = True

        self.setSprite(WHITE_PIXEL_FILENAME)
        self.setSpriteLayer(DARKENER_LAYER)
        self.setSpriteDimensions(*getWindowDimensionsScaled())
        self.setSpriteColor(*color)
        self.setSpriteAlpha(0.0)
        self.setSpriteFollowCamera(True)
Example #5
0
    def __init__(self, *args, fade_in_time=DEFAULT_FADE_TIME, **kwargs):
        super().__init__(*args, **kwargs)
        #fade attributes
        self.fade_total_time = 0
        self.fade_time = 0
        self.done_fading = True

        #setup background
        self.setSpriteFollowCamera(
            True)  #set background to follow camera by default
        self.setSpriteDimensions(
            *getWindowDimensionsScaled())  # tile the background
        self.tileSprite(True)

        #setup darkener
        darkener = ScreenElement(WHITE_PIXEL_FILEPATH)
        self._darkener_id = self.addChild(darkener, False)
        darkener.setSpriteFollowCamera(True)
        darkener.setSpriteDimensions(*getWindowDimensionsScaled())
        darkener.setSpriteColor(*COLOR_BLACK)
        darkener.setSpriteAlpha(0.0)

        if fade_in_time > 0:
            self.fadeIn(fade_in_time)
Example #6
0
    def __init__(self, sprite_path = None, button_type = None, **kwargs):
        super().__init__(**kwargs)
        sprite_path = sprite_path or self.getOrderedStylesheetData(DEFAULT_MENU_GRAPHIC, DEFAULT_GRAPHIC, default=tuple(FULL_MISC_PATH + ["menugraphics", "menu0.bordered"]))
        if sprite_path:
            self.setSprite(sprite_path)
        if button_type is not None:
            self.button_type = button_type
        self._first_button = True
        self._buttons = set()
        self._menu_interlinks = {}

        #overwrites
        self.border = self.stylesheet.get(DEFAULT_BORDER, None) or self.stylesheet.get(DEFAULT_MENU_BORDER, None) or (8,8)

        #defaults
        self.setSpriteCenter(True, True)
        self.setSpriteFollowCamera(True)
        self.setPos(*map(operator.truediv, getWindowDimensionsScaled(), (2,2)))

        self.addQueryListener(self.getEventID(MENU_LOOKUP_KEY), lambda: self)
Example #7
0
 def updateMovement(self):
     self.z_pos += self.jump_speed
     if self.z_pos < 0:
         self.jumpFinished()
     pos = list(self.getPos())
     xspeed = 0
     yspeed = 0
     if not self.jumping:
         if not self.dead:
             if checkKeyHeld(MOVE_UP):
                 yspeed = PLAYER_MOVEMENT_SPEED_Y
             elif checkKeyHeld(MOVE_DOWN):
                 yspeed = -PLAYER_MOVEMENT_SPEED_Y
             if checkKeyHeld(MOVE_RIGHT):
                 xspeed = PLAYER_MOVEMENT_SPEED_X
             elif checkKeyHeld(MOVE_LEFT):
                 xspeed = -PLAYER_MOVEMENT_SPEED_X
     else:
         yspeed = self.jumping_y_speed
         xspeed = self.jumping_x_speed
     if not self.dead:
         pos[0] = max(0, min(getWindowDimensionsScaled()[0] - self.getSpriteWidth(), pos[0] + xspeed))
     pos[1] = max(0, min(MAX_Y_POSITION, pos[1] + yspeed))
     self.setPos(*pos)
Example #8
0
 def checkOffscreen(self, x_buffer = None, y_buffer = None):
     from kaiengine.display import getWindowDimensionsScaled
     if x_buffer is None: x_buffer = self.width
     if y_buffer is None: y_buffer = self.height
     x, y = self.getScreenPosition()
     return x < -x_buffer or y < -y_buffer or x > getWindowDimensionsScaled()[0] + x_buffer or y > getWindowDimensionsScaled()[1] + y_buffer
Example #9
0
 def checkOffscreen(self):
     if self.getPos(
     )[0] > getWindowDimensionsScaled()[0] + OFFSCREEN_BUFFER:
         customEvent(REMOVE_BOULDER_EVENT, self.index)