def main(): 
    while Running == True:  # Makes a game loop
        if PG.PlayerTwoJoined == False:
            key = pygame.key.get_pressed()
            if key[pygame.K_LEFT] or key[pygame.K_UP] or key[pygame.K_RIGHT] or key[pygame.K_DOWN]:
                P_2 = C.player_two()
                PlayerGroup.append(P_2)
                PG.PlayerTwoJoined = True
        PG.Character_Dead = P.Check_For_Life(screen, Character_Dead)
        if Character_Dead == True:
            PG.Close_Game()
        RenderL = PG.RenderL
        for i in range(0, len(PG.PlayerGroup)):
            PG.PlayerGroup[i].move(screen)  # Function that makes player move
            if PG.PlayerGroup[i].Moving == True and PG.PlayerGroup[i].Jumping == True: # Cheks if the gravity will work
                print("I am moving")
            elif PG.PlayerGroup[i].Moving == False and PG.PlayerGroup[i].Jumping == False and PG.Gravity == True: # Cheks if the gravity will work
                print("I am wrong")
                Py.Gravity(PG.PlayerGroup[i])
            Py.Borders(PlayerGroup[i], screen) # Used if players goes under screen
            PG.HitBox = PG.PlayerGroup[i].HitBox(screen)
        if PG.i == 1:
            R.El, PG.i, StarL, L.EnemyGroup = LB.Load_level_1(screen, OPS.Mode, P, Approval_SpecialDraw, PG.Screen_Diff)
            print ("Level loading/creating")
        if PG.PrviZagon == 0:
            PG.RenderL.append(R.El)
            PG.RenderL.append(StarL)
            PG.RenderL.append(L.EnemyGroup)
        #h = len(StarL)
        #i = 0
        #for i in range(0,h-1):
        #    if P.certall.colliderect(StarL[i].cert):
        #        P.Score +=1
        #        print("Tvoj Score:", P.Score)
        #        R.Start_Animation = True
        #        StarL.remove(StarL[i])
        if PG.PrviZagon == 0:
            PG.PrviZagon = 1
        i=0
        j = 0
        x = len(R.E)
        for i in range(0,x):  # Checks for any collision with blocks
            for j in range(0,len(PG.PlayerGroup)):
                if PG.PlayerGroup[j].certall.colliderect(R.E[i]):
                    Py.Collision(screen, R.E, R.El, i, PG.PlayerGroup[j], RenderL)
        j = 0
        i = 0
        if L.EnemyGroup != []:  # Checks for any collisions with enemies
            for j in range(0, len(L.EnemyGroup)):
                if L.EnemyGroup != []:
                    i = 0
                    print("Stevilo kvadratov: " + str(len(L.EnemyGroup)))
                    for i in range(0, len(PG.PlayerGroup)):
                        if not(j < 0) and not(j > len(L.EnemyGroup)) and not(i < 0) and not(i > len(PlayerGroup)) and PG.PlayerGroup[i].certall.colliderect(L.EnemyGroup[j-1].CertAll):
                            Py.Collision_Enemy(screen, PG.PlayerGroup[i], L.EnemyGroup[j-1], L.EnemyGroup, R.El)
                            if j == len(L.EnemyGroup):
                                break                
        RenderL = PG.RenderL
        R.Build_screen(screen, PG.PlayerGroup, RenderL, PG.Character_Dead, Camera, Approval_SpecialDraw)  # Function that renders the scene
        PG.updates += 1
        print("Update: ", updates)
        T2 = time.clock()
        T = T2-PG.t0
        print("Toliko casa minilo: ", T)
        if T > 10 and PG.Approval == True:  # System to measure how much loops happened in 10 seconds
            PS = myfont.render('Updates per 10 seconds:', False, red)
            PG.updates = str(PG.updates)
            PS1 = myfont.render(PG.updates, False, red)
            screen.fill(white)
            screen.blit(PS, [650,490])
            screen.blit(PS1, [650,550])
            pygame.display.update()
            time.sleep(2)
            pygame.quit()
        for event in pygame.event.get():
            if event.type == pygame.QUIT: #For ending the loop
                PG.Close_Game()
Exemple #2
0
def main():
    while Running == True:  # Makes a game loop
        RenderL = PG.RenderL
        P.move(screen, P)  # Function that makes player move
        if P.Moving == True and P.Jumping == True:  # Cheks if the gravity will work
            print("I am moving")
        elif P.Moving == False and P.Jumping == False and PG.Gravity == True:  # Cheks if the gravity will work
            print("I am wrong")
            Py.Gravity(P)
        if PG.i == 1:
            R.El, PG.i, StarL, L.EnemyGroup = LB.Load_level_1(
                screen, "custom", P)
            print("Level loading/creating")
        HitBoxes = P.HitBox(screen)
        if PrviZagon == 0:
            PG.RenderL.append(R.El)
            PG.RenderL.append(StarL)
            PG.RenderL.append(HitBoxes)
            PG.RenderL.append(L.EnemyGroup)
        #h = len(StarL)
        #i = 0
        #for i in range(0,h-1):
        #    if P.certall.colliderect(StarL[i].cert):
        #        P.Score +=1
        #        print("Tvoj Score:", P.Score)
        #        R.Start_Animation = True
        #        StarL.remove(StarL[i])
        i = 0
        x = len(R.E)
        for i in range(0, x):  # Checks for any collision with blocks
            if P.certall.colliderect(R.E[i]):
                Py.Collision(screen, HitBoxes, R.E, R.El, i, P, RenderL)
        j = 0
        if L.EnemyGroup != []:  # Checks for any collisions with enemies
            for j in range(0, len(L.EnemyGroup)):
                if L.EnemyGroup != []:
                    if P.certall.colliderect(L.EnemyGroup[j - 1].CertAll):
                        Py.Collision_Enemy(screen, P, L.EnemyGroup[j - 1],
                                           L.EnemyGroup)
                        if j != 0:
                            j -= 1
        Py.Borders(P, screen)  # Used if players goes under screen
        RenderL = PG.RenderL
        R.Build_screen(screen, P, RenderL)  #Function that renders the scene
        PG.updates += 1
        print("Update: ", updates)
        T2 = time.clock()
        T = T2 - PG.t0
        print("Toliko casa minilo: ", T)
        if T > 10 and PG.Approval == True:  # System to measure how much loops happened in 10 seconds
            PS = myfont.render('Updates per 10 seconds:', False, red)
            PG.updates = str(PG.updates)
            PS1 = myfont.render(PG.updates, False, red)
            screen.fill(white)
            screen.blit(PS, [650, 490])
            screen.blit(PS1, [650, 550])
            pygame.display.update()
            time.sleep(2)
            pygame.quit()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  #For ending the loop
                PG.Close_Game()