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

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

Pygame:試圖讓整個(gè)精靈穿過(guò)邊界而不僅僅是左上角的像素

Pygame:試圖讓整個(gè)精靈穿過(guò)邊界而不僅僅是左上角的像素

qq_笑_17 2022-12-06 15:23:24
我正在嘗試根據(jù) astar 尋路算法讓我的精靈移動(dòng)。然而,在我實(shí)現(xiàn)它之后,我意識(shí)到精靈的移動(dòng)只是按照左上角的像素。這意味著如果算法告訴它在越過(guò)邊界后向上移動(dòng),一旦左上角像素越過(guò)該邊界,它就會(huì)這樣做。然而,這意味著整個(gè)精靈實(shí)際上并沒(méi)有穿過(guò),如果它上方有障礙物就會(huì)導(dǎo)致碰撞。有沒(méi)有辦法告訴它在向上移動(dòng)之前向左移動(dòng)更多] 1def astar_ghost(pac,ghost):    maze=astar.create_maze(screen_width,screen_height,obstacles) #creates a maze of 0s and 1s. The 1s represent the obstacles    start=(ghost.gridloc[0],ghost.gridloc[1])    end=(ghost.goal_node[0],ghost.goal_node[1])    goal_node=astar.astar(maze,start,end)    if goal_node==None:        pass    else:        ghost.goal_node=goal_node    game=True    if ghost.goal_node[0]<ghost.gridloc[0]:#left         print('move left')         game=collision(pac,ghost) #collision is another function that checks for collision and returns True or False. If False, the game will be over         ghost.left=True         ghost.right=False         ghost.up=False         ghost.down=False     elif ghost.goal_node[0]>ghost.gridloc[0]:#right         print('move right')         game=collision(pac,ghost)         ghost.left=False         ghost.right=True         ghost.up=False         ghost.down=False    elif ghost.goal_node[1]<ghost.gridloc[1]:#up         print('move up')         game=collision(pac,ghost)         ghost.left=False         ghost.right=False         ghost.up=True         ghost.down=False    elif ghost.goal_node[1]>ghost.gridloc[1]:#down        print('move down')        game=collision(pac,ghost)        ghost.left=False        ghost.right=False        ghost.up=False        ghost.down=True
查看完整描述

1 回答

?
心有法竹

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

您在這里問(wèn)了幾個(gè)不同的問(wèn)題。我會(huì)在這里回答我認(rèn)為你想問(wèn)的問(wèn)題:有沒(méi)有辦法檢查整個(gè)精靈是否已經(jīng)越過(guò)邊界,而不僅僅是左上角?. 所以,我的回答(請(qǐng)注意,這僅在您的邊界線是線性的情況下才有效):您需要單獨(dú)檢查每個(gè)角,然后,如果所有角都返回True,那么您繼續(xù)前進(jìn)。例子:


def collision(sprite1, boundary):

    def internal_collision(point, boundary):

        ... # The actual math happens here, returns True/False

    corners = []

    for h in [0, 1]:

        for j in [0, 1]:

            corners.append([sprite1.rect.x+(h*sprite1.rect.width),

                            sprite1.rect.y+(j*sprite1.rect.height)])

    corner_check = []

    for corner in corners:

        corner_check.append(internal_collision(corner, boundary))

    return all(corner_check)

我不知道你的代碼是如何工作的,所以我盡量保持它的可塑性和可理解性,這樣你就可以在你自己的代碼中重新實(shí)現(xiàn)它。


查看完整回答
反對(duì) 回復(fù) 2022-12-06
  • 1 回答
  • 0 關(guān)注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報(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)