Example #1
0
    def death_event(self):
        """Modify game state for when the ship hits and asteroid."""
        self.ship.destroy()
        self.ship_breakup = ShipBreakup(self.ship)
        self.death = True
        sound.death()

        if Asteroid.asteroid_score > self.high_score:
            self.high_score = Asteroid.asteroid_score
            save_highscore(constants.HIGH_SCORE_FILE, self.high_score)
Example #2
0
    def draw_game(self):
        pyxel.cls(3)
        #####################################
        # Dad talking to us @ top of screen #
        #####################################
        pyxel.rect(0, 0, SCREEN_WIDTH, 48, 0)
        pyxel.blt(SCREEN_MARGIN, SCREEN_MARGIN, 0, DAD[0], DAD[1], 32, 32, 0)
        line_to_say = self.WHAT_LINE_IS_IT_ANYWAYS
        # if player is hit by shootie, then dad sasses. #
        # we pick from options and display the sass for #
        # ~200 frames                                   #
        if self.dad_sassin:
            if self.line_chosen:
                if self.dialogue_timer == 0:
                    self.dialogue_timer = pyxel.frame_count
                elif pyxel.frame_count - self.dialogue_timer > 200:
                    # special case where dad sass is 2 lines #
                    if self.DAD_LINE == 20:
                        self.DAD_LINE = 21
                        self.dialogue_timer = 0
                    else:
                        self.DAD_LINE = 14
                        self.dad_sassin = False
                        self.line_chosen = False
                        self.dialogue_timer = 0
            else:
                self.DAD_LINE = random.randint(17, 20)
                self.line_chosen = True
            line_to_say = self.DAD_LINE
        pyxel.text(48, SCREEN_MARGIN, self.DAD_LINES[line_to_say], 7)

        #####################################
        # GAMEPLAY
        # DRAWING THE OBJECTS AND PLAYER
        # IN GAME
        #####################################

        # DRAW BAG OF SOULS AND THE POOF OF WISDOM #
        pyxel.blt(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, 0, BAG_A_SOULS[0],
                  BAG_A_SOULS[1], 32, 32, 0)
        pyxel.blt(SCREEN_WIDTH - SCREEN_MARGIN - 32, 24, 0, POOF[0], POOF[1],
                  32, 16, 0)

        if (self.signal_new_tip):
            pyxel.blt(SCREEN_WIDTH - SCREEN_MARGIN - 27, 16, 0, FULL[0],
                      FULL[1], 16, 16, 0)

        # DRAW PLAYER #
        if self.player is None:
            self.player = Player(SCREEN_WIDTH // 2, 24)
            if self.hard_mode:
                self.player.move = 4
                self.player.pitchforks = 5
        if self.player.dash and (
            (pyxel.frame_count - self.dash_timer) > DASH_TIME):
            self.player.dash = False
        self.player.draw()
        self.player.update()

        if self.player.souls == 3:
            pyxel.blt(self.player.x, self.player.y - 8, 0, FULL[0], FULL[1],
                      16, 16, 0)

        ################
        # UPDATE LEVEL #
        ################
        if not self.hard_mode:
            if self.player.score > 10:
                self.numLives = 3
            if self.player.score > 20:
                self.numHalos = 3
                self.numLives = 7
            elif self.player.score > 50:
                self.numHalos = 5
                self.numLives = 10

        ################
        # INSTRUCTIONS #
        # AND TIPS     #
        ################
        if (self.player.x >= (SCREEN_WIDTH // 2)) and \
            (self.player.x <= (SCREEN_WIDTH // 2) + 32) and \
            (self.player.y >= SCREEN_HEIGHT // 2) and \
            (self.player.y <= SCREEN_HEIGHT // 2 + 32):
            pyxel.text(SCREEN_WIDTH // 2, (SCREEN_HEIGHT // 2) + 34,
                       "Bag of souls!\noooooh", 10)

        # Creating tips list based on what's out on the board #
        # You read tips list if not the first instructions    #
        if (not self.seen_lives and not self.lives == []) or \
            (not self.seen_rbs and not self.redbulls == []):
            self.signal_new_tip = True
            if not self.lives == [] and (4 not in self.tips_list):
                self.tips_list.insert(0, 4)
            if not self.redbulls == [] and (5 not in self.tips_list):
                self.tips_list.insert(0, 5)
        if (self.player.x <= SCREEN_WIDTH-SCREEN_MARGIN and \
            self.player.x >= SCREEN_WIDTH-SCREEN_MARGIN-32 and \
            self.player.y >= 16 and \
            self.player.y <= 32):
            if pyxel.btnp(pyxel.KEY_SPACE):
                self.reading_tips = True
                self.next_tip = True
            # This means you are reading tips and not introduction to poof #
            if self.reading_tips:
                if self.next_tip:
                    # This is first instructions #
                    if self.first_tip:
                        if self.tip_idx > 2:
                            self.first_tip = False
                            self.signal_new_tip = False
                            self.tip_idx = 0
                            self.curr_tip_idx = self.tip_idx
                        else:
                            self.curr_tip_idx = self.tip_idx
                            self.tip_idx = self.tip_idx + 1
                    # When poof gets new tips then we display the tips list #
                    else:
                        if self.signal_new_tip:
                            if not self.seen_lives and not self.lives == []:
                                self.seen_lives = True
                                self.signal_new_tip = False
                            if not self.seen_rbs and not self.redbulls == []:
                                self.seen_rbs = True
                                self.signal_new_tip = False
                        self.curr_tip_idx = self.tips_list[self.tip_idx %
                                                           len(self.tips_list)]
                        self.tip_idx = self.tip_idx + 1
                    self.next_tip = False
                pyxel.text(64, 24, self.POOF_TIPS[self.curr_tip_idx], 10)
            # introduction to poof #
            else:
                pyxel.text(64, 24, "I am the poof of wisdom!", 10)
                pyxel.text(
                    64, 32,
                    "Press [space] to hear my tips.\nI will signal when I get new ones.",
                    10)
        else:
            self.tip_idx = 0
            self.reading_tips = False

        ##############
        # DRAW SOULS #
        ##############
        if len(self.souls) < 14:
            self.set_souls()
        else:
            for soul in self.souls:
                soul.draw()
        # DRAW NET TO CATCH SOULS #
        if pyxel.btn(pyxel.KEY_R):
            pyxel.blt(self.player.x - 8, self.player.y, 0, NET[0], NET[1], 16,
                      16, 0)
        # DRAW LIVES #
        if len(self.lives) < self.numLives:
            self.set_lives()
        else:
            for life in self.lives:
                life.draw()
        # DRAW HALOS #
        if len(self.halos) == 0:
            self.set_halos()
        else:
            for i in range(0, self.numHalos):
                self.halos[i].draw()

        # DRAW RED BULL #
        if (pyxel.frame_count % 100 == 0):
            will_redbull = random.randint(0, 100)
            if will_redbull > 85 and len(self.redbulls) < 5:
                self.add_elem_to_arr("rbs", self.redbulls, Redbull)
        for redbull in self.redbulls:
            redbull.draw()

        ####################
        # ITS SHOOTIE TIME #
        ####################

        # (SHOOTIES ARE THE BLUE BALLS THAT SHOOT OUT OF HALOS) #

        # DRAW SHOOTIES #
        if (pyxel.frame_count % self.shootie_speed == 0):
            for i in range(0, self.numHalos):
                diff_x = self.player.x - self.halos[i].x
                diff_y = self.player.y - self.halos[i].y
                shootie_move_x = 0 if (diff_x == 0) else (diff_x) / abs(diff_x)
                shootie_move_y = diff_y / abs(diff_y) if (
                    diff_x == 0) else (diff_y) / (diff_x)
                shootie = Shootie(self.halos[i], shootie_move_x,
                                  shootie_move_y)
                self.shooties.append(shootie)
                shootie.draw()

        # UPDATE SHOOTIE POS #
        for shootie in self.shooties:
            shootie.draw()
            if shootie.x <= self.player.x + 12 and \
                shootie.x >= self.player.x + 4 and \
                shootie.y <= self.player.y + 12 and \
                shootie.y >= self.player.y + 4:
                self.shooties.remove(shootie)
                if self.player.pitchforks > 1:
                    self.player.pitchforks = self.player.pitchforks - 1
                    self.dad_sassin = True
                else:
                    pyxel.playm(2, loop=False)
                    self.dead = True
                    self.hard_mode = False
            # if shootie goes off bounds it dies #
            if shootie.x <= 0 or \
                shootie.x >= SCREEN_WIDTH or \
                shootie.y <= 48 or \
                shootie.y >= SCREEN_HEIGHT:
                self.shooties.remove(shootie)

        # DRAW SCORE #
        pyxel.text(SCREEN_WIDTH // 2 - 16, 50,
                   "SCORE: {:02}".format(self.player.score), 13)
        if (self.player.score > self.highscore):
            self.highscore = self.player.score
            if self.hard_mode:
                save_highscore(HARD_HIGH_SCORE_FILE, self.highscore)
            else:
                save_highscore(HIGH_SCORE_FILE, self.highscore)
        pyxel.text(SCREEN_MARGIN, 50,
                   "HIGHSCORE: {:02}".format(self.highscore), 13)

        # DRAW PITCHFORKS #
        h_shift = 16
        for i in range(self.player.pitchforks):
            pyxel.blt(SCREEN_WIDTH - h_shift - SCREEN_MARGIN,
                      SCREEN_MARGIN + 36, 0, PITCHFORK[0], PITCHFORK[1], 16,
                      16, 0)
            h_shift = h_shift + 16