第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何讓第二輛車說(shuō)第二名?

如何讓第二輛車說(shuō)第二名?

弒天下 2023-03-16 17:24:07
我想做的是所以我基本上想做的是每次一輛車越過(guò)終點(diǎn) 它說(shuō)哪輛車有一個(gè)但我想做的是每次第一輛車獲勝并且第二輛車越過(guò)終點(diǎn)線我想要它說(shuō)哪輛車排在第二位和第三位等等import pygame, randompygame.init()# musicmusic = pygame.mixer.music.load(“image/Led Zeppelin - Rock And Roll (Alternate Mix) (Official Music Video).mp3”)pygame.mixer.music.play(-1)#Setting up our colors that we are going to useGREEN = (20, 255, 140)GREY = (210, 210, 210)WHITE = (255, 255, 255)RED = (255, 0, 0)PURPLE = (255, 0, 255)BLACKWHITE =(96, 96, 96)SCREENWIDTH = 400SCREENHEIGHT = 500size = (SCREENWIDTH, SCREENHEIGHT)screen = pygame.display.set_mode(size)pygame.display.set_caption("Car Racing")Icon = pygame.image.load("image/redca_iconr.png")pygame.display.set_icon((Icon))# This will be a list that will contain all the sprites we intend to use in our game.#all_sprites_list = pygame.sprite.Group()#playerplayerIMG = pygame.image.load("image/red_racecar.png")playerX = 250playerY = 450playerCar_position = 0#player2playerIMG_two = pygame.image.load("image/greencar.png")playerX_two = 150playerY_two = 450playerCar_position_two = 0#player3playerIMG_three = pygame.image.load("image/Orangecar.png")playerX_three = 50playerY_three = 450playerCar_position_three = 0#player4playerIMG_four = pygame.image.load("image/yellow_car.png")playerX_four = 200playerY_four = 450playerCar_position_four = 0#Putting cars to the screendef player(x, y):    screen.blit(playerIMG, (x, y))def player_two(x, y):    screen.blit(playerIMG_two, (x, y))def player_three(x, y):    screen.blit(playerIMG_three, (x, y))def player_four(x, y):    screen.blit(playerIMG_four, (x, y))
查看完整描述

2 回答

?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊

所以,你得到的代碼有效,唯一的問(wèn)題是當(dāng)汽車與終點(diǎn)線相交時(shí),你只在屏幕上顯示文本


因此,每幀都有一個(gè)字符串放在屏幕上,當(dāng)汽車越過(guò)這條線時(shí),將字符串更改為那輛車


#put these outside the game loop

finish_text = ""

font2 = pygame.font.SysFont("Papyrus", 45)

players_finished = 0

placings = ["1st", "2nd", "3rd", "4th"]



while running: #game loop


...


     # Did anyone cross the line?

    if (finish_line_rect.collidepoint(playerX, playerY)):

        if finish_text[:9] != "Player 1": #so it doesnt do this every frame the car is intersecting

            finish_text = "Player 1 is " + placings[players_finished]

            players_finished += 1

            print("Player (one) has crossed into finish line!")



    elif (finish_line_rect.collidepoint(playerX_two , playerY_two)):

        if finish_text[:9] != "Player 2":

            print("Player one has crossed into finish line first other car lost!")

            finish_text = "Player 2 is " + placings[players_finished]

            players_finished += 1


    elif (finish_line_rect.collidepoint(playerX , playerY)):

        if finish_text[:9] != "Player 3":

            print("Player two has crossed into finish line first other car lost!")

            finish_text = "Player 3 is " + placings[players_finished]

            players_finished += 1


    elif (finish_line_rect.collidepoint(playerX_two, playerY_two)):

        if finish_text[:9] != "Player 4":

            print("Player two has crossed into finish line first other car lost!")

            finish_text = "Player 4 is " + placings[players_finished]

            players_finished += 1

    


    if finish_text != "": #test to see if there is anything to put on screen

        text2 = font2.render(finish_text, 5, (255, 99, 7))

        screen.blit(text2, (135 - (text2.get_width() / 5), 95))

    pygame.display.flip()



筆記。還沒(méi)有測(cè)試過(guò)


查看完整回答
反對(duì) 回復(fù) 2023-03-16
?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊

我從未使用過(guò) pygame,所以不知道是否有內(nèi)置函數(shù)。但是,您可以輕松地制作一個(gè)計(jì)數(shù)器。


#this is all in your while loop

if playerY<50 or playerY_two<50 or playerY_three<50 or playerY_four<50:

        count+=1

        if count == 1:

            if playerY<50:

                print('playerY first place')

                playerY=10000

            if playerY_two<50:

                print('playerY_two first place')

                playerY_two=100000

            if playerY_three<50:

                print('playerY_three first place')

                playerY_three=100000

            if playerY_four<50:

                print('playerY_four first place')

                playerY_four=1000000

        if count == 2:

            if playerY<50:

                print('playerY second place')

                playerY=10000

            if playerY_two<50:

                print('playerY_two seoncd place')

                playerY_two=100000

            if playerY_three<50:

                print('playerY_three second place')

                playerY_three=100000

            if playerY_four<50:

                print('playerY_four second place')

                playerY_four=1000000

        if count == 3:

            if playerY<50:

                print('playerY third place')

                playerY=10000

            if playerY_two<50:

                print('playerY_two third place')

                playerY_two=100000

            if playerY_three<50:

                print('playerY_three third place')

                playerY_three=100000

            if playerY_four<50:

                print('playerY_four third place')

                playerY_four=1000000

        if count == 4:

            if playerY<50:

                print('playerY 4th place')

                playerY=10000

            if playerY_two<50:

                print('playerY_two 4th place')

                playerY_two=100000

            if playerY_three<50:

                print('playerY_three 4th place')

                playerY_three=100000

            if playerY_four<50:

                print('playerY_four 4th place')

                playerY_four=1000000

            break   

你可以創(chuàng)建一個(gè)類/函數(shù)來(lái)將上面的全部?jī)?nèi)容寫成 4 行到 5 行,但一般的想法是你想打印出誰(shuí)越過(guò)終點(diǎn)線,但你只希望打印一次。


查看完整回答
反對(duì) 回復(fù) 2023-03-16
  • 2 回答
  • 0 關(guān)注
  • 97 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)