Пример #1
0
    def draw_kugel(self):

        if self.number == 0:
            draw.set_pen_color(color.WHITE)
        if self.number == 1:
            draw.set_pen_color(color.YELLOW)
        if self.number == 2:
            draw.set_pen_color(color.BLUE)
        if self.number == 3:
            draw.set_pen_color(color.RED)
        if self.number == 4:
            draw.set_pen_color(color.VIOLET)
        if self.number == 5:
            draw.set_pen_color(color.ORANGE)
        if self.number == 6:
            draw.set_pen_color(color.DARK_GREEN)
        if self.number == 7:
            draw.set_pen_color(color.BROWN)
        if self.number == 8:
            draw.set_pen_color(color.BLACK)
        if self.number == 9:
            draw.set_pen_color(color.YELLOW)
        if self.number == 10:
            draw.set_pen_color(color.BLUE)
        if self.number == 11:
            draw.set_pen_color(color.RED)
        if self.number == 12:
            draw.set_pen_color(color.VIOLET)
        if self.number == 13:
            draw.set_pen_color(color.ORANGE)
        if self.number == 14:
            draw.set_pen_color(color.DARK_GREEN)
        if self.number == 15:
            draw.set_pen_color(color.BROWN)

        #draw.set_pen_color(self.color)
        draw.filled_circle(self.x, self.y, self.r)
        if self.number >= 8:
            draw.set_pen_color(color.WHITE)
            draw.filled_circle(self.x, self.y, self.r * 0.8)
        draw.set_pen_color(color.BLACK)
        if self.number == 0:
            draw.set_pen_color(color.WHITE)
        draw.text(self.x, self.y, str(self.number))
def example_get_adjusted_map():
    net = Network.load_native('data/janos-us.txt')
    points = [(n.long, n.lati) for n in net.nodes]
    projection = MercatorProjection.from_points(points,
                                                map_size=(1024, 512),
                                                padding=50)

    status = mapbox.get_map_as_file(
        'data/map-us.png',
        replace=True,
        api_token=os.environ['MAPBOX_API_KEY'],
        projection=projection,
        style='countries_basic',
    )
    print('Map ' + ('' if status else 'not ') + 'dowloaded')

    net.add_pixel_coordinates(projection)

    draw.prepare('data/map-us.png')
    for u, v in net.edges:
        sx, sy = net.edge_middle_point(u, v, pixel_value=True)
        distance = haversine(u.long, u.lati, v.long, v.lati)
        draw.line(u.x, u.y, v.x, v.y, marker='o', color='gray')
        draw.text(sx,
                  sy,
                  f'{distance:.0f}km',
                  fontsize=7,
                  color='navy',
                  weight='bold',
                  horizontalalignment='center')

    for node in net.nodes:
        draw.text(node.x,
                  node.y,
                  node.name,
                  fontsize=8,
                  color='black',
                  weight='bold',
                  horizontalalignment='center')
    draw.show()
def example_sndlib_draw_geomanip():
    projection = MercatorProjection(map_size=(1024, 512),
                                    center=(19.6153711, 52.0892499),
                                    zoom=5)

    status = mapbox.get_map_as_file(
        'data/map-pl.png',
        replace=True,
        api_token=os.environ['MAPBOX_API_KEY'],
        projection=projection,
        style='countries_basic',
    )
    print('Map ' + ('' if status else 'not ') + 'dowloaded')

    net = Network.load_native('data/polska.txt')
    net.add_pixel_coordinates(projection)

    draw.prepare('data/map-pl.png')
    for u, v in net.edges:
        sx, sy = net.edge_middle_point(u, v, pixel_value=True)
        distance = haversine(u.long, u.lati, v.long, v.lati)
        draw.line(u.x, u.y, v.x, v.y, marker='o', color='gray')
        draw.text(sx,
                  sy,
                  f'{distance:.0f}km',
                  fontsize=7,
                  color='navy',
                  weight='bold',
                  horizontalalignment='center')

    for node in net.nodes:
        draw.text(node.x,
                  node.y,
                  node.name,
                  fontsize=8,
                  color='black',
                  weight='bold',
                  horizontalalignment='center')
    draw.show()
Пример #4
0
def main():
    pygame.init()

    #screen = pygame.display.set_mode((1200, 1200))

    pygame.mouse.set_visible(1)

    pygame.key.set_repeat(1, 100)

    pygame.display.set_caption("Billard")

    draw.set_canvas_size(1000, 600)

    running = True

    c_bande = 0.02
    c_bande_2 = c_bande * 1000 / 600
    
    #setzt Löcher
    holes = [(0.2,0.25),(0.2,0.75),(0.5,0.25),(0.5,0.75),(0.8,0.25),(0.8,0.75)]
    
    #Initialisiert die Kugeln
    liste = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15]
    random.shuffle(liste)

    x = 0
    j = 0
    liste_neu = []
    while x != 7:
        if liste[j] < 9:
            liste_neu.append(liste[j])
            j = j + 1
            x = x + 1
        else:
            j = j + 1

    x = 0
    j = 0
    while x != 7:
        if liste[j] >= 9:
            liste_neu.append(liste[j])
            j = j + 1
            x = x + 1
        else:
            j = j + 1

    for i in liste_neu:
        liste.remove(i)


    c = (((8 * ((((((3**(1/2)) / 2) * c_bande)**2) + ((0.5 * c_bande_2)**2))**(1/2)))**2) - ((4 * c_bande_2)**2))**(1/2)

    startwert_1 = 0.65
    startwert_2 = 0.5


    k_0 = bowl.kugel(0.35, 0.5, 0, 0, c_bande * 0.5, 0)
    k_1 = bowl.kugel(startwert_1, startwert_2, 0, 0, c_bande * 0.5, liste_neu[0])
    k_2 = bowl.kugel(startwert_1 + (c / 8), startwert_2 + (c_bande_2 / 2), 0, 0, c_bande * 0.5, liste_neu[1])
    k_3 = bowl.kugel(startwert_1 + (c / 8), startwert_2 - (c_bande_2 / 2), 0, 0, c_bande * 0.5, liste_neu[7])
    k_4 = bowl.kugel(startwert_1 + (c / 4), startwert_2 + c_bande_2, 0, 0, c_bande * 0.5, liste_neu[8])
    k_5 = bowl.kugel(startwert_1 + (c / 4), startwert_2, 0, 0, c_bande * 0.5, 8)
    k_6 = bowl.kugel(startwert_1 + (c / 4), startwert_2 - c_bande_2, 0, 0, c_bande * 0.5, liste_neu[2])
    k_7 = bowl.kugel(startwert_1 + (3*c / 8), startwert_2 + (1.5 * c_bande_2), 0, 0, c_bande * 0.5, liste_neu[3])
    k_8 = bowl.kugel(startwert_1 + (3*c / 8), startwert_2 + (0.5 * c_bande_2), 0, 0, c_bande * 0.5, liste_neu[9])
    k_9 = bowl.kugel(startwert_1 + (3*c / 8), startwert_2 - (0.5 * c_bande_2), 0, 0, c_bande * 0.5, liste_neu[4])
    k_10 = bowl.kugel(startwert_1 + (3*c / 8), startwert_2 - 1.5 * c_bande_2, 0, 0, c_bande * 0.5, liste_neu[10])
    k_11 = bowl.kugel(startwert_1 + (c / 2), startwert_2 + (2 * c_bande_2), 0, 0, c_bande * 0.5, liste_neu[11])
    k_12 = bowl.kugel(startwert_1 + (c / 2), startwert_2 + c_bande_2, 0, 0, c_bande * 0.5, liste_neu[12])
    k_13 = bowl.kugel(startwert_1 + (c / 2), startwert_2, 0, 0, c_bande * 0.5, liste_neu[5])
    k_14 = bowl.kugel(startwert_1 + (c / 2), startwert_2 - c_bande_2, 0, 0, c_bande * 0.5, liste_neu[13])
    k_15 = bowl.kugel(startwert_1 + (c / 2), startwert_2 - (2 * c_bande_2), 0, 0, c_bande * 0.5, liste_neu[6])

    hole_in = []
    k = [k_0, k_1, k_2, k_3, k_4, k_5, k_6, k_7, k_8, k_9, k_10, k_11, k_12, k_13, k_14, k_15]
    
    #Spieler konfigurieren
    player = []
    player.append(spieler.spieler(0))
    player.append(spieler.spieler(1))
    round_counter = 0
    no_ply = 0
    end = False
    while running:
 #       clock.tick(1000000)
        tisch.tisch()

        kugel_geschw_test = 0
        for i in k:
            if i.v_x or i.v_y != 0:
                kugel_geschw_test += 1

        if kugel_geschw_test == 0:
            queue(k_0,)
            k_0.move()

        #eingelochte Kugeln
        for ply in player:
            ply.draw_holeins()
                
                
        if (k_0 in hole_in) and (kugel_geschw_test == 0):
            check = True
            while(check):
                tisch.tisch()
                draw.set_pen_color(color.WHITE)
                draw._thick_line(0.35, 0.25, 0.35, 0.75, 0.001)
                for kugel in k:
                    kugel.draw_kugel()
                draw.show(1)
                if draw.mouse_pressed():
                    (press_x, press_y) = draw.mouse_position()
                    if 0.25 <= press_y <= 0.75:
                        ueberlagerungstest = 0
                        for i in k:
                            dx = i.x - 0.35
                            dy = (i.y - press_y) * 6 / 10
                            dist = ((dx ** 2) + (dy ** 2)) ** 0.5
                            if dist <= (2 * i.r):
                                ueberlagerungstest = ueberlagerungstest + 1
                        if ueberlagerungstest == 0:
                            hole_in.remove(k_0)
                            k_0 = bowl.kugel(0.35, press_y, 0, 0, c_bande * 0.5, 0)
                            k.append(k_0)
                            check = False
                            
        else:
            if draw.mouse_pressed() and k_0.v_x == k_0.v_y == 0:

                (press_x, press_y) = draw.mouse_position()
                k_0.v_x = (press_x - k_0.x) / 25
                k_0.v_y = (press_y - k_0.y) / 25
                round_counter += 1
          
        #Text Spieleranzeige
        if kugel_geschw_test == 0:
            if not (round_counter % 2 == no_ply):
                hole_in = []
            no_ply = round_counter % 2
            draw.set_pen_color(color.BLACK)
            draw.set_font_size(16)
            draw.set_pen_radius(5)
            draw.text(0.2,0.85,"Spieler "+str(no_ply+1)+" ist an der Reihe")
        
            # Bewegungen durchführen und zeichnen
        for kugel_1 in k:
            kugel_1.move()
            # Zeichnen
            kugel_1.draw_kugel()
            # Kollision
            k_tmp = k.copy()
            k_tmp.remove(kugel_1)
            for kugel_2 in k_tmp:
                if kollision_check(kugel_1, kugel_2):
                    kugel_1.kollision(kugel_2) 
            #Abfrage ob Kugel eingelocht
            for hole in holes :
                if strike_check(kugel_1,hole[0],hole[1],c_bande*0.75):
                    k.remove(kugel_1)
                    hole_in.append(kugel_1)
                    
                        
                    #weist die kugel_art den Spielern durch
                    if player[0].kugel_art == None and player[1].kugel_art == None :
                        if kugel_1.number == 8 :
                            end = True
                            ply = player.copy()
                            ply.remove(ply[no_ply])
                            winner = ply[0]
                        if not kugel_1.number == 0:
                            round_counter += 1    
                        player[no_ply].strike(kugel_1)
                        if no_ply == 0 and player[no_ply].kugel_art == 'voll' :
                            player[1].kugel_art = 'halb'
                        if i == 0 and player[no_ply].kugel_art == 'halb' :
                            player[1].kugel_art = 'voll'
                        if no_ply == 1 and player[no_ply].kugel_art == 'voll' :
                            player[0].kugel_art = 'halb'
                        if no_ply == 1 and player[no_ply].kugel_art == 'halb' :
                            player[0].kugel_art = 'voll'
                    #Schaut welche Kugel eingelocht wurde
                    #bestimmt das Resultat für die Spieler
                    else :
                        #Falls Schwarze Kugel versenkt wurde
                        if kugel_1.number == 8 and not (len(player[no_ply].hole_in) == 7):
                            end = True
                            ply = player.copy()
                            ply.remove(player[no_ply])
                            winner = ply[0]
                        elif kugel_1.number == 8 and len(player[no_ply].hole_in) == 7:
                            end = True
                            winner = player[no_ply]
                        #Falls eine Kugel versenkt wurde die nicht weiß oder Schwarz ist  
                        if not ((kugel_1.number > 8 and player[no_ply].kugel_art == 'halb') or (kugel_1.number < 8 and kugel_1.number > 0 and player[no_ply].kugel_art == 'voll'))                   :
                            if no_ply == 0 and not kugel_1.number == 0 :
                                player[1].strike(kugel_1)
                            if no_ply == 1 and not kugel_1.number == 0 :
                                player[0].strike(kugel_1)
                        else:
                            player[no_ply].strike(kugel_1)
                            round_counter += 1
        
        draw.show(1)
        draw.clear()
        #Bricht die while schleife ab, falls ein Spieler gewonnen hat
        if end :
            break
    #Gibt den gewinner an    
    draw.set_pen_color(color.BLACK) 
    draw.set_font_size(20)
    draw.text(0.5,0.5,"Spieler "+ str(winner.num + 1) + " hat gewonnen")
    draw.show()
Пример #5
0
def game_over():
    # Play background music
    pygame.mixer.music.load(os.path.join(sound_folder,
                                         'Sci-fi_Pulse_Loop.wav'))
    pygame.mixer.music.set_volume(1)
    pygame.mixer.music.play(-1)
    # Gameover condition
    gameover = True
    # Create conditions
    continue_botton_current = 1
    quit_botton_current = 1
    continue_blinking = True
    quit_blinking = False

    # Gameover loop
    while gameover:

        # Background
        mainSurface.blit(menu_background, background_rect)

        # Initiate text and buttons
        continue_botton = draw.draw_botton(mainSurface, 'Continue', 300, 200,
                                           200, 50, blue, black, True)
        quit_botton = draw.draw_botton(mainSurface, 'Quit', 300, 300, 200, 50,
                                       blue, black, True)
        gameover_text = draw.text(mainSurface, 'Game Over', 90,
                                  SCREEN_WIDTH / 2, 40, white)

        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        # print (mouse)
        # print(click)

        # Conditions for mouse and bottons interaction
        mouse_resume_botton_x = (300 < mouse[0] < 300 + 200)
        mouse_resume_botton_y = (200 < mouse[1] < 200 + 50)
        if mouse_resume_botton_x and mouse_resume_botton_y:
            continue_botton_shadow = draw.draw_botton(mainSurface, 'Continue',
                                                      300, 200, 200, 50, white,
                                                      blue, True)
            # print('mouse is on start game botton')
            if click[0] == 1:
                gameover = False

        mouse_quit_botton_x = (300 < mouse[0] < 300 + 200)
        mouse_quit_botton_y = (300 < mouse[1] < 300 + 50)
        if mouse_quit_botton_x and mouse_quit_botton_y:
            # print('mouse is on quit game botton')
            quit_botton = draw.draw_botton(mainSurface, 'Quit', 300, 300, 200,
                                           50, white, blue, True)
            if click[0] == 1:
                botton_select_sound.play()
                pygame.quit()
                quit()

        # Events loop
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_DOWN:
                    continue_blinking = False
                    quit_blinking = True
                    botton_select_sound.play()
                if event.key == pygame.K_UP:
                    continue_blinking = True
                    quit_blinking = False
                    botton_select_sound.play()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    if continue_blinking:
                        gameover = False
                        botton_select_sound.play()
                    if quit_blinking:
                        pygame.quit()
                        quit()
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        # Continue botton animation
        if continue_blinking:
            if continue_botton_current == 1:
                continue_botton = draw.draw_botton(mainSurface, 'Continue',
                                                   300, 200, 200, 50, blue,
                                                   white, True)
            if continue_botton_current == 2:
                continue_botton_shadow = draw.draw_botton(
                    mainSurface, 'Continue', 300, 200, 200, 50, white, blue,
                    True)
            if continue_botton_current == 2:
                continue_botton_current = 1
            else:
                continue_botton_current += 1
        # Quit botton animation
        if quit_blinking:
            if quit_botton_current == 1:
                quit_botton = draw.draw_botton(mainSurface, 'Quit', 300, 300,
                                               200, 50, blue, white, True)
            if quit_botton_current == 2:
                quit_botton_shadow = draw.draw_botton(mainSurface, 'Quit', 300,
                                                      300, 200, 50, white,
                                                      blue, True)
            if quit_botton_current == 2:
                quit_botton_current = 1
            else:
                quit_botton_current += 1

        # Update screen
        pygame.display.update()
        clock.tick(7)
Пример #6
0
def game_loop():

    new()

    # Create game loop conditions and score
    running = True
    score = 0
    count = 0
    shadow_score = 0
    rocks_condition = True
    bullets_exist = False
    dialogue = True
    music_play = True
    stage_1_end = False
    explosion_counter = 0

    # Play background music
    def music_1(condition):
        if condition:
            pygame.mixer.music.load(
                os.path.join(sound_folder, 'Vegas_Loop.wav'))
            pygame.mixer.music.set_volume(.5)
            pygame.mixer.music.play(-1)
        else:
            pygame.mixer.music.load(os.path.join(sound_folder,
                                                 'Serotonin.wav'))
            pygame.mixer.music.set_volume(1)
            pygame.mixer.music.play(-1)

    # Game Loop
    while running:
        # Set FPS
        dt = clock.tick(FPS) / 1000
        mainSurface.blit(background, background_rect)
        if music_play and rocks_condition:
            music_1(True)
            music_play = False

        if not music_play and not rocks_condition:
            music_1(False)
            music_play = True
        if score > 1500:
            rocks_condition = False

        # Events loop
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if dialogue:
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_RETURN:
                        dialogue = False
            elif event.type == pygame.KEYDOWN and not dialogue:
                if event.key == pygame.K_ESCAPE:
                    # pygame.mixer.music.pause()
                    menu_resume()
                if event.key == pygame.K_SPACE:
                    shoot_sound.play()
                    shoot_sound.set_volume(.3)
                    shoot_player(player)
                if event.key == pygame.K_RETURN and dialogue:
                    dialogue = False

        # Control rules for all units movement
        for player in units_player:
            if not dialogue and not stage_1_end:
                Player.player_1.manual_control(player)
        for unit in units_rocks:
            if not dialogue:
                SpaceRock.space_rock1.AI_control(unit)
        if not rocks_condition:
            for unit in units_mobships:
                if not dialogue:
                    Mobship.mob_ship.AI_control_outside(unit)
        for planet in units_planets:
            Planet.planet_1.AI_control(planet, shadow_score, count)
            count = 0
            shadow_score = 0

        # Checking if mobs entered the screen and assign new controls and assign bullet
        for unit in units_mobships:
            if unit.rect.right <= SCREEN_WIDTH or unit.rect.top <= 0:
                Mobship.mob_ship.AI_control_inside(unit)
                if (unit.rect.left <
                        SCREEN_WIDTH / 2 + 200) and not bullets_exist:
                    super_bullet = Bullets.bullet_2(mainSurface,
                                                    unit.rect.left,
                                                    unit.rect.centery)
                    shoot_sound_2.play()
                    shoot_sound_2.set_volume(.2)
                    units_bullets_mob.add(super_bullet)
                    units_all.add(super_bullet)
                    bullets_exist = True
                if bullets_exist:
                    expl_bullet = Explosion.explosion(
                        mainSurface, super_bullet.rect.left,
                        super_bullet.rect.centery, 'small')
                    units_all.add(expl_bullet)
                if len(units_bullets_mob) == 0:
                    bullets_exist = False

        # Checking if any rock passed the screen to apply self destruct
        for unit in units_rocks:
            if unit.rect.right <= 0:
                unit.kill()
                score += 10
                if rocks_condition:
                    rock = new_rock()
                count += 1
            if unit.rect.bottom > SCREEN_HEIGHT:
                print('check3!')
                unit.kill()
                if rocks_condition:
                    rock = new_rock()

        # Checking collision between rocks and rocks and initiating speedy rocks
        for unit in units_rocks:
            units_rocks.remove(unit)
            if (collision_check(unit, units_rocks, False,
                                False)) and unit.rect.x <= SCREEN_WIDTH:
                unit.speedx -= 5
                explosion_sound.set_volume(.2)
                explosion_sound.play()
                expl_rock = Explosion.explosion(mainSurface, unit.rect.centerx,
                                                unit.rect.centery, 'large')
                units_all.add(expl_rock)
            units_rocks.add(unit)

        # Checking collision between rocks and bullets
        hits_2 = pygame.sprite.groupcollide(units_rocks, units_bullets, True,
                                            True, pygame.sprite.collide_circle)
        for hit in hits_2:
            if rocks_condition:
                new_rock()
            score += 10
            shadow_score += 10
            explosion_sound.set_volume(.2)
            explosion_sound.play()
            expl_rock = Explosion.explosion(mainSurface, hit.rect.centerx,
                                            hit.rect.centery, 'large')
            units_all.add(expl_rock)

        # Checking collision between player and rocks
        hits_1 = pygame.sprite.groupcollide(units_player, units_rocks, False,
                                            True, pygame.sprite.collide_circle)
        for hit in hits_1:
            rock = new_rock()
            for unit in units_rocks:
                damage = unit.hit_damage
            player.hp -= damage
            explosion_player_sound.play()
            expl_player = Explosion.explosion(mainSurface, player.rect.centerx,
                                              player.rect.centery, 'large')
            units_all.add(expl_player)
            if player.hp <= 0:
                player.hide()
                player.lives += -1
                player.hp = player.full_hp
                if player.lives == 0:
                    running = False

        # Check collision between player ship and enemy bullets
        if collision_check_groups(units_player, units_bullets_mob, False,
                                  True):
            player.hp -= 100
            explosion_player_sound.play()
            expl_player = Explosion.explosion(mainSurface, player.rect.centerx,
                                              player.rect.centery, 'large')
            units_all.add(expl_player)
            if player.hp <= 0:
                player.hide()
                player.lives += -1
                player.hp = player.full_hp
                if player.lives == 0:
                    running = False

        # Check collision between player bullets and enemy bullets
        if collision_check_groups(units_bullets, units_bullets_mob, True,
                                  False):
            pass

        # Check collision between player bullets and enemy ship
        if collision_check_groups(units_mobships, units_bullets, False, True):
            for unit in units_mobships:
                unit.hp -= 100
                expl_mob_ship = Explosion.explosion(mainSurface,
                                                    unit.rect.centerx,
                                                    unit.rect.centery, 'large')
                explosion_sound_2.play()
                units_all.add(expl_mob_ship)
                print(unit.hp)
                if unit.hp <= 0:
                    stage_1_end = True

        # Explosion of boss when dead
        if stage_1_end:
            for unit in units_bullets_mob:
                unit.kill()
            for unit in units_bullets:
                unit.kill()
        if explosion_counter < 5 and stage_1_end:
            clock.tick(3)
            for unit in units_mobships:
                if explosion_counter == 0:
                    expl_mob_ship = Explosion.explosion(
                        mainSurface, unit.rect.right, unit.rect.centery,
                        'small')
                    units_all.add(expl_mob_ship)
                    explosion_sound_3.play()
                    explosion_counter += 1
                    print('explosion of boss 0')
                elif explosion_counter == 1:
                    expl_mob_ship = Explosion.explosion(
                        mainSurface, unit.rect.left, unit.rect.centery,
                        'large')
                    units_all.add(expl_mob_ship)
                    explosion_sound_3.play()
                    explosion_counter += 1
                    print('explosion of boss 1')
                elif explosion_counter == 2:
                    expl_mob_ship = Explosion.explosion(
                        mainSurface, unit.rect.right, unit.rect.centery,
                        'small')
                    units_all.add(expl_mob_ship)
                    explosion_sound_3.play()
                    explosion_counter += 1
                elif explosion_counter == 3:
                    expl_mob_ship = Explosion.explosion(
                        mainSurface, unit.rect.left, unit.rect.centery,
                        'large')
                    units_all.add(expl_mob_ship)
                    explosion_sound_3.play()
                    explosion_counter += 1
                elif explosion_counter == 4:
                    expl_mob_ship = Explosion.explosion(
                        mainSurface, unit.rect.right, unit.rect.centery,
                        'small')
                    explosion_sound_3.play()
                    units_all.add(expl_mob_ship)
                    explosion_counter += 1
                    unit.kill()

        # Background and game units on screen
        units_all.update()
        units_all.draw(mainSurface)
        if dialogue:
            dialogue_1 = draw.dialogue(
                mainSurface,
                "Welcome this is my first game. Press Enter to continue! ", 0,
                400, SCREEN_WIDTH, 300, blue, white, True)
        # Screen platform, e.g. (Score, Hp bar)
        text_1 = draw.text(mainSurface, 'Score ' + str(score), 18,
                           SCREEN_WIDTH / 2, 20, white)
        hp_bar = draw.draw_hp_bar(mainSurface, 0, 20, player.full_hp,
                                  player.hp)
        lives_icons = draw.draw_icons_lives(mainSurface, 0, player.lives)
        if explosion_counter == 5:
            text_2 = draw.text(mainSurface, 'You Win', 40, SCREEN_WIDTH / 2,
                               SCREEN_HEIGHT / 2, blue_bright)
        pygame.display.update()
Пример #7
0
def para(data, kill):
    '''
    This function create a pygame window that dynamically adjust some parameters for KSI
    Input: arguments are variables in Manager
    data is a dict:
        to be filled
    kill is a list, kill[0] is bool, meaning this process should stop or not.
    '''
    pygame.init()
    screen = pygame.display.set_mode((500, 700))
    myfont = pygame.font.SysFont("monospace", 20)
    clock = pygame.time.Clock()
    # parameter : minimal value, range
    gainRange = [0, 1]
    threshRangeL = [20, 40]  # to 80
    threshRangeH = [200, 55]  # to 80
    gauseRange = [1, 10]  # to 11
    ydisRange = [10, 50]
    alphaRange = [0, 0.2]
    ythRange = [100, 50]  # to 80
    stepRange = [0, 6]  # to 6
    touchRange = [0, 1.5]
    while not kill['kill']:
        screen.fill((0, 0, 0))
        # gain
        gain0 = 'Gain 0 = %.4f' % (data['gain'][0])
        draw.text(screen, gain0, myfont, 10, 80)
        draw.rec(screen, 100,
                 (data['gain'][0] - gainRange[0]) / gainRange[1] * 200)
        gain1 = 'Gain 1 = %.4f' % (data['gain'][1])
        draw.text(screen, gain1, myfont, 10, 130)
        draw.rec(screen, 150,
                 (data['gain'][1] - gainRange[0]) / gainRange[1] * 200)
        # sbs
        if data['step'] == 1:
            thresh0 = 'SbsThresh L 0 = %.4f' % (data['sbsThreshL'][0])
            draw.text(screen, thresh0, myfont, 10, 180)
            draw.rec(
                screen, 200, 200 * (data['sbsThreshL'][0] - threshRangeL[0]) /
                threshRangeL[1])
            thresh1 = 'SbsThresh L 1 = %.4f' % (data['sbsThreshL'][1])
            draw.text(screen, thresh1, myfont, 10, 230)
            draw.rec(
                screen, 250, 200 * (data['sbsThreshL'][1] - threshRangeL[0]) /
                threshRangeL[1])
        else:
            thresh0 = 'SbsThresh H 0 = %.4f' % (data['sbsThreshH'][0])
            draw.text(screen, thresh0, myfont, 10, 180)
            draw.rec(
                screen, 200, 200 * (data['sbsThreshH'][0] - threshRangeH[0]) /
                threshRangeH[1])
            thresh1 = 'SbsThresh H 1 = %.4f' % (data['sbsThreshH'][1])
            draw.text(screen, thresh1, myfont, 10, 230)
            draw.rec(
                screen, 250, 200 * (data['sbsThreshH'][1] - threshRangeH[0]) /
                threshRangeH[1])
        gause0 = 'SbsGause 0 = %.4f' % (data['sbsGause'][0])
        draw.text(screen, gause0, myfont, 10, 280)
        draw.rec(screen, 300,
                 200 * (data['sbsGause'][0] - gauseRange[0]) / gauseRange[1])
        gause1 = 'SbsGause 1 = %.4f' % (data['sbsGause'][1])
        draw.text(screen, gause1, myfont, 10, 330)
        draw.rec(screen, 350,
                 200 * (data['sbsGause'][1] - gauseRange[0]) / gauseRange[1])
        # special case
        gain0 = 'Dis 23-0 = %.4f' % (data['ydis'][0])
        draw.text(screen, gain0, myfont, 10, 380)
        draw.rec(screen, 400,
                 (data['ydis'][0] - ydisRange[0]) / ydisRange[1] * 200)

        thresh0 = 'yThresh 0 = %.4f' % (data['yth'][0])
        draw.text(screen, thresh0, myfont, 10, 430)
        draw.rec(screen, 450,
                 200 * (data['yth'][0] - ythRange[0]) / ythRange[1])

        touch = 'Touch Range %.4f' % (data['touch'])
        draw.text(screen, touch, myfont, 10, 480)
        draw.rec(screen, 500,
                 100.0 * (data['touch'] - touchRange[0]) / touchRange[1])

        step = 'Step %.4f' % (data['step'])
        draw.text(screen, step, myfont, 10, 530)
        draw.rec(screen, 550,
                 200 * (data['step'] - stepRange[0]) / stepRange[1])

        alpha = 'alpha = %.4f' % (data['alpha'])
        draw.text(screen, alpha, myfont, 10, 630)
        draw.rec(screen, 650,
                 (data['alpha'] - alphaRange[0]) / alphaRange[1] * 200)

        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
            elif event.type == MOUSEBUTTONDOWN:
                pressed_array = pygame.mouse.get_pressed()
                for index in range(len(pressed_array)):
                    if pressed_array[index]:
                        if index == 0:
                            pos = pygame.mouse.get_pos()
                            if pos[1] > 100 and pos[1] < 120:
                                data['gain'] = [
                                    gainRange[0] + gainRange[1] *
                                    (pos[0] - 10) / 200.0, data['gain'][1]
                                ]
                                data['gainChange'] = True
                            elif pos[1] > 150 and pos[1] < 170:
                                data['gain'] = [
                                    data['gain'][0], gainRange[0] +
                                    gainRange[1] * (pos[0] - 10) / 200.0
                                ]
                                data['gainChange'] = True
                            elif pos[1] > 200 and pos[1] < 220:
                                if data['step'] == 1:
                                    data['sbsThreshL'] = [
                                        threshRangeL[0] + threshRangeL[1] *
                                        (pos[0] - 10) / 200.0,
                                        data['sbsThreshL'][1]
                                    ]
                                else:
                                    data['sbsThreshH'] = [
                                        threshRangeH[0] + threshRangeH[1] *
                                        (pos[0] - 10) / 200.0,
                                        data['sbsThreshH'][1]
                                    ]
                            elif pos[1] > 250 and pos[1] < 270:
                                if data['step'] == 1:
                                    data['sbsThreshL'] = [
                                        data['sbsThreshL'][1],
                                        threshRangeL[0] + threshRangeL[1] *
                                        (pos[0] - 10) / 200.0
                                    ]
                                else:
                                    data['sbsThreshH'] = [
                                        data['sbsThreshH'][1],
                                        threshRangeH[0] + threshRangeH[1] *
                                        (pos[0] - 10) / 200.0
                                    ]
                            elif pos[1] > 300 and pos[1] < 320:
                                data['sbsGause'] = [
                                    (gauseRange[0] + gauseRange[1] *
                                     (pos[0] - 10) / 200) / 2 * 2 + 1,
                                    data['sbsGause'][1]
                                ]
                                data['threshChange'] = True
                            elif pos[1] > 350 and pos[1] < 370:
                                data['sbsGause'] = [
                                    data['sbsGause'][0],
                                    (gauseRange[0] + gauseRange[1] *
                                     (pos[0] - 10) / 200) / 2 * 2 + 1
                                ]
                                data['threshChange'] = True
                            elif pos[1] > 400 and pos[1] < 420:
                                data['ydis'] = [
                                    ydisRange[0] + ydisRange[1] *
                                    (pos[0] - 10) / 200.0, data['ydis'][1]
                                ]
                            elif pos[1] > 450 and pos[1] < 470:
                                data['yth'] = [
                                    ythRange[0] + ythRange[1] *
                                    (pos[0] - 10) / 200.0, data['yth'][1]
                                ]
                            elif pos[1] > 500 and pos[1] < 520:
                                data['touch'] = touchRange[
                                    0] + touchRange[1] * (pos[0] - 10) / 200.0
                            elif pos[1] > 550 and pos[1] < 570:
                                data['step'] = stepRange[0] + stepRange[1] * (
                                    pos[0] - 10) / 200 + 1
                            elif pos[1] > 600 and pos[1] < 620:
                                pass
                            elif pos[1] > 650 and pos[1] < 670:
                                data['alpha'] = alphaRange[
                                    0] + alphaRange[1] * (pos[0] - 10) / 200.0
        pygame.display.update()
        msElapsed = clock.tick(30)
Пример #8
0
def tisch():

    draw.set_pen_radius(1)

    draw.set_pen_color(color.DARK_GREEN)

    draw.filled_rectangle(0.2 - c_bande, 0.25 - c_bande_2, 0.6 + (2 * c_bande),
                          0.5 + (2 * c_bande_2))

    draw.set_pen_color(color.GREEN)

    draw.filled_rectangle(0.2, 0.25, 0.6, 0.5)

    # Goldene Ecken

    draw.set_pen_color(color.GOLD)

    draw.filled_rectangle(0.2 - c_bande, 0.25 - c_bande_2, c_bande, c_bande_2)

    draw.filled_rectangle(0.2 - c_bande, 0.75, c_bande, c_bande_2)

    draw.filled_rectangle(0.5 - (c_bande / 2), 0.25 - c_bande_2, c_bande,
                          c_bande_2)

    draw.filled_rectangle(0.5 - (c_bande / 2), 0.75, c_bande, c_bande_2)

    draw.filled_rectangle(0.8, 0.25 - c_bande_2, c_bande, c_bande_2)

    draw.filled_rectangle(0.8, 0.75, c_bande, c_bande_2)

    # Löcher

    draw.set_pen_color(color.BLACK)

    draw.filled_circle(0.2, 0.25, c_bande * 0.75)

    draw.filled_circle(0.2, 0.75, c_bande * 0.75)

    draw.filled_circle(0.5, 0.25, c_bande * 0.75)

    draw.filled_circle(0.5, 0.75, c_bande * 0.75)

    draw.filled_circle(0.8, 0.25, c_bande * 0.75)

    draw.filled_circle(0.8, 0.75, c_bande * 0.75)

    # Rauten Markierung

    draw.set_pen_color(color.WHITE)

    draw.filled_raute(0.2 - (c_bande / 2), 0.375, c_bande / 2)

    draw.filled_raute(0.2 - (c_bande / 2), 0.5, c_bande / 2)

    draw.filled_raute(0.2 - (c_bande / 2), 0.625, c_bande / 2)

    draw.filled_raute(0.8 + (c_bande / 2), 0.375, c_bande / 2)

    draw.filled_raute(0.8 + (c_bande / 2), 0.5, c_bande / 2)

    draw.filled_raute(0.8 + (c_bande / 2), 0.625, c_bande / 2)

    draw.filled_raute(0.275, 0.25 - (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.35, 0.25 - (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.425, 0.25 - (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.575, 0.25 - (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.65, 0.25 - (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.725, 0.25 - (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.275, 0.75 + (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.35, 0.75 + (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.425, 0.75 + (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.575, 0.75 + (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.65, 0.75 + (c_bande_2 / 2), c_bande / 2)

    draw.filled_raute(0.725, 0.75 + (c_bande_2 / 2), c_bande / 2)

    #Spieler angaben
    draw.set_pen_color(color.BLACK)
    draw.text(0.1, 0.75, "Spieler 1 eingelocht :")
    draw.text(0.9, 0.75, "Spieler 2 eingelocht :")
Пример #9
0
def label2rgb(
    label,
    img=None,
    alpha=0.5,
    label_names=None,
    font_size=30,
    thresh_suppress=0,
    colormap=None,
    loc="centroid",
    font_path=None,
):
    """Convert label to rgb.

    Parameters
    ----------
    label: numpy.ndarray, (H, W), int
        Label image.
    img: numpy.ndarray, (H, W, 3), numpy.uint8
        RGB image.
    alpha: float
        Alpha of RGB (default: 0.5).
    label_names: list of string
        Label id to label name.
    font_size: int
        Font size (default: 30).
    thresh_suppress: float
        Threshold of label ratio in the label image.
    colormap: numpy.ndarray, (M, 3), numpy.uint8
        Label id to color.
        By default, :func:`~imgviz.label_colormap` is used.
    loc: string
        Location of legend (default: 'centroid').
        'lt' and 'rb' are supported.
    font_path: str
        Font path.

    Returns
    -------
    res: numpy.ndarray, (H, W, 3), numpy.uint8
        Visualized image.

    """
    if colormap is None:
        colormap = label_colormap()

    res = colormap[label]

    random_state = np.random.RandomState(seed=1234)

    mask_unlabeled = label < 0
    res[mask_unlabeled] = random_state.rand(*(mask_unlabeled.sum(), 3)) * 255

    if img is not None:
        if img.ndim == 2:
            img = color_module.gray2rgb(img)
        res = (1 - alpha) * img.astype(float) + alpha * res.astype(float)
        res = np.clip(res.round(), 0, 255).astype(np.uint8)

    if label_names is None:
        return res

    unique_labels = np.unique(label)
    unique_labels = unique_labels[unique_labels != -1]
    unique_labels = [l for l in unique_labels if label_names[l] is not None]
    if len(unique_labels) == 0:
        return res

    if loc == "centroid":
        for label_i in unique_labels:
            mask = label == label_i
            if 1.0 * mask.sum() / mask.size < thresh_suppress:
                continue
            y, x = np.array(_center_of_mass(mask), dtype=int)

            if label[y, x] != label_i:
                Y, X = np.where(mask)
                point_index = np.random.randint(0, len(Y))
                y, x = Y[point_index], X[point_index]

            text = label_names[label_i]
            height, width = draw_module.text_size(text,
                                                  size=font_size,
                                                  font_path=font_path)
            color = color_module.get_fg_color(res[y, x])
            res = draw_module.text(
                res,
                yx=(y - height // 2, x - width // 2),
                text=text,
                color=color,
                size=font_size,
                font_path=font_path,
            )
    elif loc in ["rb", "lt"]:
        text_sizes = np.array([
            draw_module.text_size(label_names[l],
                                  font_size,
                                  font_path=font_path) for l in unique_labels
        ])
        text_height, text_width = text_sizes.max(axis=0)
        legend_height = text_height * len(unique_labels) + 5
        legend_width = text_width + 20 + (text_height - 10)

        height, width = label.shape[:2]
        legend = np.zeros((height, width, 3), dtype=np.uint8)
        if loc == "rb":
            aabb2 = np.array([height - 5, width - 5], dtype=float)
            aabb1 = aabb2 - (legend_height, legend_width)
        elif loc == "lt":
            aabb1 = np.array([5, 5], dtype=float)
            aabb2 = aabb1 + (legend_height, legend_width)
        else:
            raise ValueError("unexpected loc: {}".format(loc))
        legend = draw_module.rectangle(legend,
                                       aabb1,
                                       aabb2,
                                       fill=(255, 255, 255))

        alpha = 0.5
        y1, x1 = aabb1.round().astype(int)
        y2, x2 = aabb2.round().astype(int)
        res[y1:y2,
            x1:x2] = (alpha * res[y1:y2, x1:x2] + alpha * legend[y1:y2, x1:x2])

        for i, l in enumerate(unique_labels):
            box_aabb1 = aabb1 + (i * text_height + 5, 5)
            box_aabb2 = box_aabb1 + (text_height - 10, text_height - 10)
            res = draw_module.rectangle(res,
                                        aabb1=box_aabb1,
                                        aabb2=box_aabb2,
                                        fill=colormap[l])
            res = draw_module.text(
                res,
                yx=aabb1 + (i * text_height, 10 + (text_height - 10)),
                text=label_names[l],
                size=font_size,
                font_path=font_path,
            )
    else:
        raise ValueError("unsupported loc: {}".format(loc))

    return res