예제 #1
0
    def fall(self, limx, direction, matrix, ladder, floor, wall, coin, donkey, fireballs):

        self.collectCoin(matrix, coin)

        #direction of fall
        if direction == Direction.EAST:
            offset = self.velx
        elif direction == Direction.WEST:
            offset = -1*self.velx
        else: 
            offset = 0
        if ((direction == Direction.EAST and matrix.SE_of(self) == matrix.symbol) or (direction == Direction.WEST and matrix.SW_of(self) == matrix.symbol) or matrix.getPosition(self) == matrix.symbol):
            while matrix.grid[self.y+self.vely][self.x+offset] in [matrix.symbol, 'o', coin.symbol]:
                self.collectCoin(matrix, coin)
                matrix.update_character_in_matrix(self.y, self.x, self.trace)
                matrix.update_ladders_in_matrix(floor.coordinates, ladder.coordinates, ladder.symbol, floor.gap)
                for fireball in fireballs:
                    matrix.update_character_in_matrix(fireball.y, fireball.x, fireball.trace)
                    fireball.move(limx, matrix, self, ladder, wall, floor, 0)
                    matrix.update_character_in_matrix(fireball.y, fireball.x, fireball.symbol)
                matrix.update_character_in_matrix(donkey.y, donkey.x, donkey.trace)
                donkey.move(matrix.grid, self, 0)
                matrix.update_coins_in_matrix(coin.coordinates, coin.symbol)
                matrix.update_character_in_matrix(donkey.y, donkey.x, donkey.symbol)
                self.y += self.vely
                if matrix.grid[self.y][self.x+offset] != wall:
                    self.x += offset
                matrix.update_character_in_matrix(self.y, self.x, self.symbol) 
                #                time.sleep(0.05)
                matrix.print_matrix(self.score, self.lives)
예제 #2
0
    def jump(self, direction, limx, limy, matrix, ladder, floor, wall, coin, donkey, fireballs, max_height = 2, multiplier = 3):

        self.collectCoin(matrix, coin)

        #direction of jump
        if self.motion == Motion.RIGHT:
            offset = multiplier*self.velx
        elif self.motion == Motion.LEFT:
            offset = -1*multiplier*self.velx
        elif self.motion == Motion.REST:
            offset = 0

        matrix.update_character_in_matrix(self.y, self.x, self.trace)
        #init jump
        if direction == Direction.JUMP and matrix.S_of(self) in [wall, floor.symbol, ladder.symbol]:
            maxjump = self.y-max_height
            initial_height = self.y

            #up
            while self.y > maxjump:
                matrix.update_character_in_matrix(self.y, self.x, self.trace)
                matrix.update_ladders_in_matrix(floor.coordinates, ladder.coordinates, ladder.symbol, floor.gap)
                for fireball in fireballs:
                    matrix.update_character_in_matrix(fireball.y, fireball.x, fireball.trace)
                    fireball.move(limx, matrix, self, ladder, wall, floor, 0)
                    matrix.update_character_in_matrix(fireball.y, fireball.x, fireball.symbol)
                matrix.update_character_in_matrix(donkey.y, donkey.x, donkey.trace)
                donkey.move(matrix.grid, self, 0)
                matrix.update_coins_in_matrix(coin.coordinates, coin.symbol)
                matrix.update_character_in_matrix(donkey.y, donkey.x, donkey.symbol)
                if matrix.N_of(self) != floor.symbol or getPosition(self) != floor.symbol:
                     if matrix.getPosition(self) == ladder.symbol and self.motion != Motion.REST:
                         break
                     self.y -= self.vely
                else:
                     break
                if self.x + offset not in range(1,limx-2):
                     if self.motion == Motion.RIGHT:
                         self.x = limx-2
                         offset = 0
                     elif self.motion == Motion.LEFT:
                         self.x = 1
                         offset = 0
                else:
                     self.x += offset
                matrix.update_character_in_matrix(self.y, self.x, self.symbol)
                time.sleep(0.05)
                matrix.print_matrix(self.score, self.lives)

            #down    
            while matrix.S_of(self) in [matrix.symbol, 'o', coin.symbol]:
                self.collectCoin(matrix, coin)
                matrix.update_character_in_matrix(self.y, self.x, self.trace)
                matrix.update_ladders_in_matrix(floor.coordinates, ladder.coordinates, ladder.symbol, floor.gap)
                for fireball in fireballs:
                    matrix.update_character_in_matrix(fireball.y, fireball.x, fireball.trace)
                    fireball.move(limx, matrix, self, ladder, wall, floor, 0)
                    matrix.update_character_in_matrix(fireball.y, fireball.x, fireball.symbol)
                matrix.update_character_in_matrix(donkey.y, donkey.x, donkey.trace)
                donkey.move(matrix.grid, self, 0)
                matrix.update_coins_in_matrix(coin.coordinates, coin.symbol)
                matrix.update_character_in_matrix(donkey.y, donkey.x, donkey.symbol)
                if matrix.getPosition(self) == ladder.symbol and self.motion != Motion.REST:
                    break
                self.y += self.vely
                if self.x + offset not in range(1,limx-1):
                    if self.motion == Motion.RIGHT:
                        self.x = limx-2
                        offest = 0
                    elif self.motion == Motion.LEFT: 
                        self.x = 1
                        offset = 0
                else:
                    self.x += offset
                matrix.update_character_in_matrix(self.y, self.x, self.symbol)
                time.sleep(0.05)
                matrix.print_matrix(self.score, self.lives)