Exemple #1
0
    def move_and_process_platforms(self, platforms):
        self.x += self.vx

        spaceman_rect = self.get_rect()
        
        for p in platforms:
            platform_rect = p.get_rect()

            if intersects.rect_rect(spaceman_rect, platform_rect):
                if self.vx > 0:
                    self.x = p.x - self.w
                elif self.vx < 0:
                    self.x = p.x + p.w

        self.y += self.vy
        
        spaceman_rect = self.get_rect()
        
        for p in platforms:
            platform_rect = p.get_rect()
            
            if intersects.rect_rect(spaceman_rect, platform_rect):
                if self.vy > 0:
                    self.y = p.y - self.h
                if self.vy < 0:
                    self.y = p.y + p.h
                self.vy = 0
Exemple #2
0
    def process_platforms(self, platforms):
        self.x += self.vx

        student_rect = self.get_rect()
        
        for p in platforms:
            platform_rect = p.get_rect()

            if intersects.rect_rect(student_rect, platform_rect):
                if self.vx > 0:
                    self.x = p.x - self.w
                elif self.vx < 0:
                    self.x = p.x + p.w
                    self.y += self.vy

        self.y += self.vy
        
        student_rect = self.get_rect()
        
        for p in platforms:
            platform_rect = p.get_rect()
            
            if intersects.rect_rect(student_rect, platform_rect):
                if self.vy > 0:
                    self.y = p.y - self.h
                if self.vy < 0:
                    self.y = p.y + p.h
                    self.vy = 0
Exemple #3
0
def on_switch_b():
    for s in switchs_b:
        if intersects.rect_rect(player1, s):
            return True
        elif intersects.rect_rect(player2, s):
            return True

    return False
Exemple #4
0
    def jump(self, platforms, homework):

        can_jump = False

        self.y += 1

        student_rect = self.get_rect()

        #if intersects.rect_rect(student_rect, ground.get_rect()):
            #can_jump = True

        for p in platforms:
            platform_rect = p.get_rect()

            if intersects.rect_rect(student_rect, platform_rect):
                can_jump = True

        if self.y + self.h >= HEIGHT:
            can_jump = True

        if can_jump:
            self.vy = -JUMP_POWER

            if len(homework) > 2:
                self.change_speed_temp(get_current_time() + 1, -2)
            # if self.vx < 0:
            #     self.x -= 15
            # elif self.vx > 0:
            #     self.x += 15

        self.y -= 1
Exemple #5
0
    def jump(self, ground):
        self.y += 1

        if intersects.rect_rect(self.get_rect(), ground.get_rect()):
            self.vy = -JUMP_POWER

        self.y -= 1
Exemple #6
0
def update_coins(coins):
    for c in coins:
        if intersects.rect_rect(player, c):
            coins.remove(c)

    if len(coins) == 0:
        end_screen()
Exemple #7
0
    def process_laserbeam(self, enemies, laserbeams):
        enemy_lives = 1
        enemies_rect = self.get_rect()
        for n in laserbeams:
            laserbeams_rect = n.get_rect()

            if n.on() and intersects.rect_rect(enemies_rect, laserbeams_rect):
                self.die()
Exemple #8
0
def check_collide(collidebles, player, vel):
    ''' resolve collisions horizontally '''
    for c in collidebles:
        if intersects.rect_rect(player, c):
            if vel[0] > 0:
                player[0] = c[0] - player[2]
            elif vel[0] < 0:
                player[0] = c[0] + c[2]
    ''' move the player in vertical direction '''
    player[1] += vel[1]
    ''' resolve collisions vertically '''
    for c in collidebles:
        if intersects.rect_rect(player, c):
            if vel[1] > 0:
                player[1] = c[1] - player[3]
            if vel[1] < 0:
                player[1] = c[1] + c[3]
Exemple #9
0
def collision(player, walls):
    player[0] += player_vx  #move horizontaly

    for w in walls:
        if intersects.rect_rect(player, w):
            if player_vx > 0:
                player[0] = w[0] - player[2]
            elif player_vx < 0:
                player[0] = w[0] + w[2]
    '''moves player in vertical direction'''
    player[1] += player_vy  # move verticaly
    '''wall vertical collisions'''
    for w in walls:
        if intersects.rect_rect(player, w):
            if player_vy > 0:
                player[1] = w[1] - player[3]
            if player_vy < 0:
                player[1] = w[1] + w[3]  # Drawing Code
Exemple #10
0
    def jump(self, ground, platforms):
        can_jump = False
        
        self.y += 1
        if intersects.rect_rect(self.get_rect(), ground.get_rect()):
            can_jump = True
    
        spaceman_rect = self.get_rect()
        
        for p in platforms:
            platform_rect = p.get_rect()

            if intersects.rect_rect(spaceman_rect, platform_rect):
                can_jump = True

        if can_jump:
            self.vy = -JUMP_POWER

        self.y -= 1
Exemple #11
0
    def is_touching(self, other_rect, dont_set_flag=False, ignore_untouchable=False):
        if (not self.is_untouchable) or ignore_untouchable:
            if intersects.rect_rect(self.get_rect(), other_rect):
                if not dont_set_flag:
                    self.is_untouchable = True
                    self.last_touch = get_current_time()

                return True

        return False
Exemple #12
0
def move_bullets(bullets):
    for bullet in bullets:
        b_vel = bullet[4]

        bullet[0] += b_vel[0]
        bullet[1] += b_vel[1]

    for w in walls:
        for b in bullets:
            if intersects.rect_rect(b, w):
                bullets.remove(b)
Exemple #13
0
    def process_enemies(self, enemies):
        spaceman_rect = self.get_rect()
        global lives
        for p in enemies:
            enemy_rect = p.get_rect()

            if intersects.rect_rect(spaceman_rect, enemy_rect):
                print("skadoosh")
                lives -= 1
                self.x = 0
                self.y = 615
Exemple #14
0
    def move_and_process_platforms(self, platforms):
        self.x += self.vx

        person_rect = self.get_rect()

        for p in platforms:
            platform_rect = p.get_rect()

            if intersects.rect_rect(person_rect, platform_rect):
                if self.vx > 0:
                    self.x = p.x - self.w
                    self.vx *= -1
                elif self.vx < 0:
                    self.x = p.x + p.w
                    self.vx *= -1

            if self.platform_bound:
                if (person_rect[0] == platform_rect[0] and
                        platform_rect[1] == person_rect[1] + person_rect[3]
                        and self.vx == -1):
                    self.vx *= -1
                elif (person_rect[0] + person_rect[2] == platform_rect[0] + platform_rect[2] and
                      person_rect[1] + person_rect[3] == platform_rect[1] and
                      self.vx == 1):
                    self.vx *= -1


        self.y += self.vy

        person_rect = self.get_rect()

        for p in platforms:
            platform_rect = p.get_rect()

            if intersects.rect_rect(person_rect, platform_rect):
                if self.vy > 0:
                    self.y = p.y - self.h
                if self.vy < 0:
                    self.y = p.y + p.h
                self.vy = 0
Exemple #15
0
    def process_coins(self, coins):
        global score
        spaceman_rect = self.get_rect()
        coins_to_remove = []

        for c in coins:
            coin_rect = c.get_rect()
            
            if intersects.rect_rect(spaceman_rect, coin_rect):
                coins_to_remove.append(c)
                score += 1

        for c in coins_to_remove:
            coins.remove(c)
Exemple #16
0
    def process_button(self, buttons, laserbeams):
        hit = False
        
        spaceman_rect = self.get_rect()
        for b in buttons:
            button_rect = b.get_rect()

            if intersects.rect_rect(spaceman_rect, button_rect):
                self.x = 0
                self.y = 615
                hit = True
                
        if hit:
            for l in laserbeams:
                l.shoot()        
Exemple #17
0
    def process_belongings(self, belongings, inventory):

        student_rect = self.get_rect()

        for b in belongings:
            if b.is_collectible:
                item_rect = b.get_rect()

                if intersects.rect_rect(student_rect, item_rect):
                    belongings.remove(b)
                    inventory.append(b)
                    fix_inventory(inventory)

                    if len(belongings) > 0:
                        belongings[0].activate()
    def process_coins(self, coins):
        global score
        
        student_rect = self.get_rect()
        coins_to_remove = []
        
        for c in coins:
            coin_rect = c.get_rect()

            if intersects.rect_rect(student_rect, coin_rect):
                coins_to_remove.append(c)
                score += 1
                print(score)

        for c in coins_to_remove:
            coins.remove(c)
            vel2[0] = player2_speed
        else:
            vel2[0] = 0

        if up:
            vel2[1] = -player2_speed
        elif down:
            vel2[1] = player2_speed
        else:
            vel2[1] = 0
        ''' move the players in horizontal direction '''
        player1[0] += vel1[0]
        player2[0] += vel2[0]
        ''' resolve collisions horizontally '''
        for w in walls:
            if intersects.rect_rect(player1, w):
                if vel1[0] > 0:
                    player1[0] = w[0] - player1[2]
                elif vel1[0] < 0:
                    player1[0] = w[0] + w[2]

        for w in walls:
            if intersects.rect_rect(player2, w):
                if vel2[0] > 0:
                    player2[0] = w[0] - player2[2]
                elif vel2[0] < 0:
                    player2[0] = w[0] + w[2]
        ''' move the players in vertical direction '''
        player1[1] += vel1[1]
        player2[1] += vel2[1]
        ''' resolve collisions vertically '''
Exemple #20
0
        player.move_vertical()

    if left:
        player_vx = -player_speed
    elif right:
        player_vx  = player_speed
    else:
        player_vx = 0

    # Game Logic (Check for Collitions)
    ''' moves player in horizontal direction'''    
    player[0] += player_vx

    '''wall horizontal collisions'''
    for w in walls:
        if intersects.rect_rect(player, w):
            if player_vx > 0:
                player[0] = w[0] - player[2]
            elif player_vx < 0:
                player[0] = w[0] + w[2]

    '''moves player in vertical direction'''
    player[1] += player_vy

    '''wall vertical collisions'''
    for w in walls:
        if intersects.rect_rect(player, w):
            if player_vy > 0:
                player[1] = w[1] - player[3]
            if player_vy < 0:
                player[1] = w[1] + w[3]# Drawing Code
Exemple #21
0
        if up3:
            vel3[1] = -5
        elif down3:
            vel3[1] = 5
        else:
            vel3[1] = 0

    # Game logic (Check for collisions, update points, etc.)
    ''' move the player in horizontal direction '''
    player1[0] += vel1[0]
    player2[0] += vel2[0]
    player3[0] += vel3[0]
    ''' resolve collisions horizontally '''
    for w in walls:
        if intersects.rect_rect(player1, w):
            if vel1[0] > 0:
                player1[0] = w[0] - player1[2]
            elif vel1[0] < 0:
                player1[0] = w[0] + w[2]

        if intersects.rect_rect(player2, w):
            if vel2[0] > 0:
                player2[0] = w[0] - player2[2]
            elif vel2[0] < 0:
                player2[0] = w[0] + w[2]

        if intersects.rect_rect(player3, w):
            if vel3[0] > 0:
                player3[0] = w[0] - player3[2]
            elif vel3[0] < 0:
Exemple #22
0
        if left:
            enemy_vx = -enemy_speed
        elif right:
            enemy_vx = enemy_speed
        else:
            enemy_vx = 0

    # Game logic (Check for collisions, update points, etc.)
    if stage == PLAYING:
        ''' move the player and enemy in horizontal direction '''
        player[0] += player_vx
        enemy[0] += enemy_vx
        ''' resolve collisions horizontally '''
        for c in collidables:
            if intersects.rect_rect(player, c):
                if player_vx > 0:
                    player[0] = c[0] - player[2]
                elif player_vx < 0:
                    player[0] = c[0] + c[2]
            ''' resolve collisions horizontally '''
        for c in collidables:
            if intersects.rect_rect(enemy, c):
                if enemy_vx > 0:
                    enemy[0] = c[0] - enemy[2]
                elif enemy_vx < 0:
                    enemy[0] = c[0] + c[2]
        ''' move the player in vertical direction '''
        player[1] += player_vy
        enemy[1] += enemy_vy
        ''' resolve collisions vertically '''
        block_vy = block_speed
    else:
        block_vy = 0

    if left:
        block_vx = -block_speed
    elif right:
        block_vx = block_speed
    else:
        block_vx = 0

    # Game logic (Check for collisions, update points, etc.)
    ''' move the block in horizontal direction '''
    block[0] += block_vx
    ''' resolve collision '''
    if intersects.rect_rect(block, wall):
        if block_vx > 0:
            block[0] = wall[0] - block[2]
        elif block_vx < 0:
            block[0] = wall[0] + wall[2]
    ''' move the block in vertical direction '''
    block[1] += block_vy
    ''' resolve collision '''
    if intersects.rect_rect(block, wall):
        if block_vy > 0:
            block[1] = wall[1] - block[3]
        elif block_vy < 0:
            block[1] = wall[1] + wall[3]

    # Drawing code (Describe the picture. It isn't actually drawn yet.)
    screen.fill(BLACK)
Exemple #24
0
            pplayer_vy = 0

        if a:
            pplayer_vx = -pplayer_speed
        elif d:
            pplayer_vx = pplayer_speed
        else:
            pplayer_vx = 0

    # Game logic (Check for collisions, update points, etc.)
    if stage == PLAYING:
        ''' move the player in horizontal direction '''
        player[0] += player_vx
        ''' resolve collisions horizontally '''
        for w in walls:
            if intersects.rect_rect(player, w):
                if player_vx > 0:
                    player[0] = w[0] - player[2]
                elif player_vx < 0:
                    player[0] = w[0] + w[2]
        ''' move the player in vertical direction '''
        player[1] += player_vy
        ''' resolve collisions vertically '''
        for w in walls:
            if intersects.rect_rect(player, w):
                if player_vy > 0:
                    player[1] = w[1] - player[3]
                if player_vy < 0:
                    player[1] = w[1] + w[3]
        '''llllllllll'''
        ''' move the player in horizontal direction '''
Exemple #25
0
        if intersects.point_circle(mouse_pos, circle):
            color = RED
        else:
            color = WHITE
    elif case == 2:
        if intersects.point_rect(mouse_pos, rectangle):
            color = RED
        else:
            color = WHITE
    elif case == 3:
        if intersects.circle_circle(circle, circle2):
            color = RED
        else:
            color = WHITE
    elif case == 4:
        if intersects.rect_rect(rectangle, rectangle2):
            color = RED
        else:
            color = WHITE

    # Drawing code
    screen.fill(BLACK)

    if case == 1:
        pygame.draw.circle(screen, color, [circle[0], circle[1]], circle[2])
    elif case == 2:
        pygame.draw.rect(
            screen, color,
            [rectangle[0], rectangle[1], rectangle[2], rectangle[3]])
    elif case == 3:
        pygame.draw.circle(screen, color, [circle[0], circle[1]], circle[2])
Exemple #26
0
    if up:
        vel[1] = -speed
    elif down:
        vel[1]  = speed
    else:
        vel[1]  = 0
        
        
    # Game logic (Check for collisions, update points, etc.)
    ''' move the block in horizontal direction '''
    block[0] += vel[0]

    ''' resolve collisions '''
    for w in walls:
        if intersects.rect_rect(block, w):        
            if vel[0]> 0:
                block[0] = w[0] - block[2]
            elif vel[0] < 0:
                block[0] = w[0] + w[2]

    ''' move the block in vertical direction '''
    block[1] += vel[1]
    
    ''' resolve collisions '''
    for w in walls:
        if intersects.rect_rect(block, w):                    
            if vel[1] > 0:
                block[1] = w[1] - block[3]
            if vel[1] < 0:
                block[1] = w[1] + w[3]
Exemple #27
0
        block_vy = 0
        
    if left:
        block_vx = -block_speed
    elif right:
        block_vx = block_speed
    else:
        block_vx = 0

        
    # Game logic (Check for collisions, update points, etc.)
    ''' move the block in horizontal direction '''
    block[0] += block_vx

    ''' resolve collision '''
    if intersects.rect_rect(block, wall):
        if block_vx > 0:
            block[0] = wall[0] - block[2]
        elif block_vx < 0:
            block[0] = wall[0] + wall[2]

    ''' move the block in vertical direction '''
    block[1] += block_vy
    
    ''' resolve collision '''
    if intersects.rect_rect(block, wall):
        if block_vy > 0:
            block[1] = wall[1] - block[3]
        elif block_vy < 0:
            block[1] = wall[1] + wall[3]
Exemple #28
0
            player3_vx = -player3_speed
        elif right:
            player3_vx = player3_speed
        else:
            player3_vx = 0

    


    # Game logic (Check for collisions, update points, etc.)
    ''' move the player in horizontal direction '''
    player[0] += player_vx

    ''' resolve collisions horizontally '''
    for w in walls:
        if intersects.rect_rect(player, w):        
            if player_vx > 0:
                player[0] = w[0] - player[2]
            if player_vx < 0:
                player[0] = w[0] + w[2]

    ''' move the player in vertical direction '''
    player[1] += player_vy
    
    ''' resolve collisions vertically '''
    for w in walls:
        if intersects.rect_rect(player, w):                    
            if player_vy > 0:
                player[1] = w[1] - player[3]
            if player_vy < 0:
                player[1] = w[1] + w[3]
        else:
            vel[0] = 0

        if up:
            vel[1] = -player_speed
        elif down:
            vel[1] = player_speed
        else:
            vel[1] = 0

        # Game logic (Check for collisions, update points, etc.)
        ''' move the player in horizontal direction '''
        player[0] += vel[0]
        ''' resolve collisions horizontally '''
        for w in walls:
            if intersects.rect_rect(player, w):
                if vel[0] > 0:
                    player[0] = w[0] - player[2]
                elif vel[0] < 0:
                    player[0] = w[0] + w[2]
        ''' move the player in vertical direction '''
        player[1] += vel[1]
        ''' resolve collisions vertically '''
        for w in walls:
            if intersects.rect_rect(player, w):
                if vel[1] > 0:
                    player[1] = w[1] - player[3]
                if vel[1] < 0:
                    player[1] = w[1] + w[3]
        ''' here is where you should resolve player collisions with screen edges  '''
        '''get the coins'''
            elif stage == END:
                if event.key == pygame.K_SPACE:
                    setup()

    # Game logic (Check for collisions, update points, etc.)

    if stage == PLAYING:
        ''' move the player in horizontal direction '''
        player1[0] += vel1[0]
        player2[0] += vel2[0]
        ''' move the player in vertical direction '''
        player1[1] += vel1[1]
        player2[1] += vel2[1]
        ''' resolve collisions horizontally '''
        for w in walls:
            if intersects.rect_rect(player1, w):
                if vel1[0] > 0:
                    player1[0] = w[0] - player1[2]
                elif vel1[0] < 0:
                    player1[0] = w[0] + w[2]

            if intersects.rect_rect(player2, w):
                if vel2[0] > 0:
                    player2[0] = w[0] - player2[2]
                elif vel2[0] < 0:
                    player2[0] = w[0] + w[2]
        ''' resolve collisions vertically '''
        for w in walls:
            if intersects.rect_rect(player1, w):
                if vel1[1] > 0:
                    player1[1] = w[1] - player1[3]
Exemple #31
0
        
    if left:
        player_vx = -player_speed
    elif right:
        player_vx = player_speed
    else:
        player_vx = 0

        
    # Game logic (Check for collisions, update points, etc.)
    ''' move the player in horizontal direction '''
    player[0] += player_vx

    ''' resolve collisions horizontally '''
    for w in walls:
        if intersects.rect_rect(player, w):        
            if player_vx > 0:
                player[0] = w[0] - player[2]
            elif player_vx < 0:
                player[0] = w[0] + w[2]

    ''' move the player in vertical direction '''
    player[1] += player_vy
    
    ''' resolve collisions vertically '''
    for w in walls:
        if intersects.rect_rect(player, w):                    
            if player_vy > 0:
                player[1] = w[1] - player[3]
            if player_vy < 0:
                player[1] = w[1] + w[3]
Exemple #32
0
    else:
        player_vy = 0

    if left:
        player_vx = -player_speed
    elif right:
        player_vx = player_speed
    else:
        player_vx = 0

    # Game logic (Check for collisions, update points, etc.)
    ''' move the player in horizontal direction '''
    player[0] += player_vx
    ''' resolve collisions horizontally '''
    for w in walls:
        if intersects.rect_rect(player, w):
            if player_vx > 0:
                player[0] = w[0] - player[2]
            elif player_vx < 0:
                player[0] = w[0] + w[2]
    ''' move the player in vertical direction '''
    player[1] += player_vy
    ''' resolve collisions vertically '''
    for w in walls:
        if intersects.rect_rect(player, w):
            if player_vy > 0:
                player[1] = w[1] - player[3]
            if player_vy < 0:
                player[1] = w[1] + w[3]
    ''' here is where you should resolve player collisions with screen edges '''
    ''' get the coins '''
Exemple #33
0
        block_vy = 0

    if left:
        block_vx = -block_speed
    elif right:
        block_vx = block_speed
    else:
        block_vx = 0

    # Game logic (Check for collisions, update points, etc.)
    """ move the block in horizontal direction """
    block[0] += block_vx

    """ resolve collisions """
    for w in walls:
        if intersects.rect_rect(block, w):
            if block_vx > 0:
                block[0] = w[0] - block[2]
            elif block_vx < 0:
                block[0] = w[0] + w[2]

    """ move the block in horizontal direction """
    block[1] += block_vy

    """ resolve collisions """
    for w in walls:
        if intersects.rect_rect(block, w):
            if block_vy > 0:
                block[1] = w[1] - block[3]
            if block_vy < 0:
                block[1] = w[1] + w[3]