Exemplo n.º 1
0
    def bullet_lazer_collision(self, bullet_list, lazer_list):
        for i in bullet_list:
            if i[2] == 1:  ##bullet is alive
                for j in lazer_list:

                    if j[3] == 1 and j[2] == 1:  ##horizontal lazer
                        ans = check_collision(i[0], i[1], 1, 3, j[0], j[1], 1,
                                              5)
                        if ans == 1:
                            ##remove the lazer and kill the bullet
                            i[2] = -1  ##bullet flag changed
                            j[3] = -1  ##lazer dead,flag changed

                            for k in range(0, 5):  ##remove the lazer from grid
                                self._matrix[j[1]][j[0] + k] = ' '

                            for k in range(0, 3):  ##remove bullet from grid
                                self._matrix[i[1]][i[0] + k] = ' '

                    if j[3] == 1 and j[2] == 2:  ##vertical lazer
                        ans = check_collision(i[0], i[1], 1, 3, j[0], j[1], 5,
                                              1)
                        if ans == 1:
                            i[2] = -1  ##bullet flag changed
                            j[3] = -1  ##lazer dead,flag changed

                            for k in range(0, 5):  ##remove lazer from grid
                                self._matrix[j[1] + k][j[0]] = ' '
                            for k in range(0, 3):  ##remove bullet from grid
                                self._matrix[i[1]][i[0] + k] = ' '

                    if j[3] == 1 and j[2] == 3:  ## diagonal lazer
                        ans = check_collision(i[0], i[1], 1, 3, j[0], j[1], 5,
                                              5)
                        if ans == 1:
                            i[2] = -1  ##bullet flag changed
                            j[3] = -1  ##lazer dead,flag changed

                            for m in range(0, 5):  ##remove lazer from grid
                                for n in range(0, 5):
                                    self._matrix[j[1] + m][j[0] + n] = ' '
                            for k in range(0, 3):  ##remove bullet from grid
                                self._matrix[i[1]][i[0] + k] = ' '

                    if j[3] == 1 and j[2] == 4:  ## diagonal lazer
                        ans = check_collision(i[0], i[1], 1, 3, j[0], j[1], 5,
                                              5)
                        if ans == 1:
                            i[2] = -1  ##bullet flag changed
                            j[3] = -1  ##lazer dead,flag changed

                            for m in range(0, 5):  ##remove lazer from grid
                                for n in range(0, 5):
                                    self._matrix[j[1] + m][j[0] + n] = ' '
                            for k in range(0, 3):  ##remove bullet from grid
                                self._matrix[i[1]][i[0] + k] = ' '
Exemplo n.º 2
0
    def mando_lazer_collision(self, lazer_list, manga, grid):
        x1 = self._xcor
        y1 = self._ycor
        r1 = self._rows
        c1 = self._columns

        for i in lazer_list:
            if i[3] == 1:
                if i[2] == 1:
                    ans = check_collision(x1, y1, r1, c1, i[0], i[1], 1, 5)
                    if ans == 1:
                        lives = manga.decrease_lives(
                        )  ##decrease mando's lives
                        i[3] = -1  ## changing lazer flag
                        grid.remove_lazer_from_board(i, 1)
                        # for k in range(0,5):##remove the lazer from grid
                        # 	matrix[i[1]][i[0]+k]=' '
                if i[2] == 2:
                    ans = check_collision(x1, y1, r1, c1, i[0], i[1], 5, 1)
                    if ans == 1:
                        lives = manga.decrease_lives(
                        )  ##decrease mando's lives
                        i[3] = -1  ## changing lazer flag
                        grid.remove_lazer_from_board(i, 2)

                        # for k in range (0,5): ##remove lazer from grid
                        # 	matrix[i[1]+k][i[0]]=' '

                if i[2] == 3:
                    ans = check_collision(x1, y1, r1, c1, i[0], i[1], 5, 5)
                    if ans == 1:
                        lives = manga.decrease_lives(
                        )  ##decrease mando's lives
                        i[3] = -1  ## changing lazer flag
                        grid.remove_lazer_from_board(i, 3)

                        # for m in range(0,5): ##remove lazer from grid
                        # 	for n in range(0,5):
                        # 		matrix[i[1]+m][i[0]+n]=' '

                if i[2] == 4:
                    ans = check_collision(x1, y1, r1, c1, i[0], i[1], 5, 5)
                    if ans == 1:
                        lives = manga.decrease_lives(
                        )  ##decrease mando's lives
                        i[3] = -1  ## changing lazer flag
                        grid.remove_lazer_from_board(i, 4)
Exemplo n.º 3
0
 def coin_collision(self, coin_list, coins):
     x1 = self._xcor
     y1 = self._ycor
     r1 = self._rows
     c1 = self._columns
     for i in coin_list:
         if i[2] == 1:
             ans = check_collision(x1, y1, r1, c1, i[0], i[1], 1, 1)
             if ans == 1:
                 i[2] = -1  ## change flag for coin
                 coins += 1  ##inc no of coins
     return coins
Exemplo n.º 4
0
 def ice_bullet_collision(self, bullet_list, grid):
     for i in bullet_list:
         if i[2] == 1:  ##bullet is alive
             check = check_collision(self._xcor, self._ycor, self._rows,
                                     self._columns, i[0], i[1], 1, 3)
             if check == 1:
                 self._alive = 0  ##change both flags
                 i[2] = -1
                 ###remove bullet
                 grid.remove_bullet_from_board(i)
                 ###remove ice ball
                 grid.remove_ice_balls_from_board(self)
Exemplo n.º 5
0
    def kill_mando(self, manga):
        if self._alive == 1:  ##only if the ice_ball is alive and in the screen
            x1 = manga.give_xcor()
            y1 = manga.give_ycor()
            r1 = manga.give_rows()
            c1 = manga.give_columns()

            check = check_collision(x1, y1, r1, c1, self._xcor, self._ycor,
                                    self._rows, self._columns)
            if check == 1:  ##ice_ball hit mando
                self._alive = 0  ###bullet is now dead
                manga.decrease_lives()  ###decrease lives
Exemplo n.º 6
0
    def bullet_enemy_collision(self, bullet_list, ene, grid):
        x1 = self._xcor
        y1 = self._ycor
        r1 = self._rows
        c1 = self._columns

        for i in bullet_list:
            if i[2] == 1:  ## bullet is alive
                check = check_collision(x1, y1, r1, c1, i[0], i[1], 1, 3)

                if check == 1:  ### bullet hit the enemy
                    i[2] = -1  ####change the bullet flag
                    grid.remove_bullet_from_board(i)
                    # for k in range(0,3): ##remove bullet from grid
                    # 	matrix[i[1]][i[0]+k]=' '
                    ene.decrease_lives()
Exemplo n.º 7
0
    def mando_booster_collision(self, store_booster, grid):
        x1 = self._xcor
        y1 = self._ycor
        r1 = self._rows
        c1 = self._columns

        for i in store_booster:
            status = i.give_status()
            if status == 0:  ## booster is not taken
                x2 = i.give_xcor()
                y2 = i.give_ycor()
                r2 = i.give_rows()
                c2 = i.give_columns()

                check = check_collision(x1, y1, r1, c1, x2, y2, r2, c2)
                if check == 1:

                    ###remove booster and change its flag
                    i.change_status()
                    grid.remove_from_board(i)
                    # for m in range(0,3): ##removed booster from grid
                    # 	for n in range(0,7):
                    # 		matrix[y2+m][x2+n]=' '
                    return 1
Exemplo n.º 8
0
def main():
    clock = pygame.time.Clock()
    pygame.init()

    # Some extra variables
    asseleration = 0.025
    speed_game = 30
    points = 0
    direction = "left_down"

    # Initializing objects
    player = Player()
    ball = Ball()     

    # Adding ball to group balls (that's for collision)
    balls = pygame.sprite.Group()
    balls.add(ball)

    # Making group of all sprites (to blit them later faster)
    all_sprites = pygame.sprite.Group()
    all_sprites.add(player)
    all_sprites.add(ball)

    running = True
    screen = pygame.display.set_mode((C.SCREEN_WIDTH, C.SCREEN_HEIGHT))
    pygame.display.set_caption("Ping-Pong")


    font = pygame.font.SysFont('Arial', 800) 

    # Main loop
    while running:

        # Check wheather ball hits botoom
        running = check_collision(player, ball, balls, direction)[0]

        # Checking events for quiting
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    running = False
            elif event.type == QUIT:
                running = False

        # User's input
        pressed_keys = pygame.key.get_pressed()

        # Updating ackground
        screen.fill((25, 50, 50))

        # Rendering text and drawing it
        text_points = font.render('{0}'.format(points), True, (100, 100, 100))
        text_points_rect = text_points.get_rect(center = (C.SCREEN_WIDTH/2, C.SCREEN_HEIGHT/2))
        screen.blit(text_points, text_points_rect)

        # Updating objects
        player.update(pressed_keys)
        ball.update(direction)

        # Drawing objects
        for sprite in all_sprites:
            screen.blit(sprite.surf, sprite.rect)

        points += check_collision(player, ball, balls, direction)[1]
        direction = check_collision(player, ball, balls, direction)[2]
        
        # flipping and asselereting of framerate
        pygame.display.flip()
        if speed_game <+ 120:
            speed_game += asseleration    
        clock.tick(speed_game) 
    pygame.quit()
    over.over(points)