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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

碰撞發(fā)生時如何顯示爆炸圖像?

碰撞發(fā)生時如何顯示爆炸圖像?

守候你守候我 2023-10-31 21:30:07
不知道為什么沒有爆炸效果。其他圖都畫得很好,唯獨爆炸圖不行explosion = pygame.image.load(os.path.join(image_path, "explosion.png"))explosion_size = explosion.get_rect().sizeexplosion_width = explosion_size[0]for missile_idx, missile_val in enumerate(missiles):    missile_pos_x = missile_val[0]    missile_pos_y = missile_val[1]    #weapon information upgrade    missile_rect = missile.get_rect()    missile_rect.left = missile_pos_x    missile_rect.top = missile_pos_y    if missile_rect.colliderect(rock_rect):        explosion_sound.play()        **explosion_pos_x = missile_pos_x        explosion_pos_y = missile_pos_y        screen.blit(explosion,(explosion_pos_x,explosion_pos_y))**        del(rock)        del(missiles)        missiles = []        # missile position coordination        missiles = [[m[0], m[1] - missile_speed] for m in missiles]        # top missile elimination        missiles = [[m[0], m[1]] for m in missiles if m[1]>0]
查看完整描述

2 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

爆炸只顯示了一小會兒。用于pygame.time.get_ticks()返回自調(diào)用以來的毫秒數(shù)pygame.init()。計算必須刪除爆炸圖像之后的時間點。將爆炸的坐標(biāo)和結(jié)束時間點添加到列表的頭部 (?explosionList )。在主應(yīng)用程序循環(huán)中繪制爆炸。從列表尾部刪除過期的爆炸:

explosionList = []


while run:

? ? current_time = pygame.time.get_ticks()

? ? # [...]


? ? for missile_idx, missile_val in enumerate(missiles)

? ? ? ? # [...]


? ? ? ? if missile_rect.colliderect(rock_rect):

? ? ? ? ? ? explosion_sound.play()


? ? ? ? ? ? explosion_pos_x = missile_pos_x

? ? ? ? ? ? explosion_pos_y = missile_pos_y

? ? ? ? ? ? end_time = current_time + 2000 # 2000 milliseconds = 2 seconds

? ? ? ? ? ? explosionList.insert(0, (end_time, explosion_pos_x, explosion_pos_y))


? ? ? ? ? ? # [...]


? ? for i in range(len(explosionList)):

? ? ? ? if current_time < explosionList[i][0]:

? ? ? ? ? ? screen.blit(explosion, (explosionList[i][1], explosionList[i][2]))

? ? ? ? else:

? ? ? ? ? ? explosionList = explosionList[:i]

? ? ? ? ? ? break

? ??

? ? # [...]

使用該算法可以管理多次爆炸。


import pygame

pygame.init()

window = pygame.display.set_mode((210, 210))


def create_rectangles():

? ? global rectangles

? ? w, h = window.get_size()

? ? rectangles = []

? ? for x in range(0, w - 60, 60):

? ? ? ? for y in range(0, h - 60, 60):

? ? ? ? ? ? rectangles.append(pygame.Rect(x + 30, y + 30, 30, 30))


create_rectangles()

hit_list = []

fade_out_time = 3000


run = True

while run:

? ? current_time = pygame.time.get_ticks()

? ??

? ? for event in pygame.event.get():

? ? ? ? if event.type == pygame.QUIT:

? ? ? ? ? ? run = False


? ? point = pygame.mouse.get_pos()

? ? collideindex = pygame.Rect(point, (1, 1)).collidelist(rectangles)

? ? if collideindex >= 0:

? ? ? ? end_time = current_time + fade_out_time

? ? ? ? hit_list.insert(0, (end_time, rectangles[collideindex].center))

? ? ? ? del rectangles[collideindex]

? ? if not hit_list and not rectangles:

? ? ? ? create_rectangles()


? ? window.fill(0)

? ? for r in rectangles:

? ? ? ? pygame.draw.rect(window, (255, 0, 0), r)

? ? for i in range(len(hit_list)):

? ? ? ? delta_time = hit_list[i][0] - current_time

? ? ? ? if delta_time > 0:

? ? ? ? ? ? radius = round(30 * delta_time / fade_out_time)

? ? ? ? ? ? pygame.draw.circle(window, (255, 255, 0), hit_list[i][1], radius)

? ? ? ? else:

? ? ? ? ? ? hit_list = hit_list[:i]

? ? ? ? ? ? break

? ? pygame.display.flip()


查看完整回答
反對 回復(fù) 2023-10-31
?
智慧大石

TA貢獻1946條經(jīng)驗 獲得超3個贊

如果您想顯示爆炸圖像一段時間,此方法可能很有用。


explosion_list = [] # list for explosion effect

running = True

while running:

     start_time = pygame.time.get_ticks() # add time for explosion effect


     for missile_idx, missile_val in enumerate(missiles):

         missile_pos_x = missile_val[0]

         missile_pos_y = missile_val[1]


         #weapon information upgrade

         missile_rect = missile.get_rect()

         missile_rect.left = missile_pos_x

         missile_rect.top = missile_pos_y


         if missile_rect.colliderect(rock_rect):

             explosion_sound.play()

             explosion_pos_x = missile_pos_x

             explosion_pos_y = missile_pos_y

             explosion_time = start_time + 2000 # 1000 milliseconds = 2 seconds

             **explosion_list.insert(0, (explosion_time, explosion_pos_x, explosion_pos_y))**

             del(rock)

             del(missiles)

             missiles = []

            

             # missile position coordination

             missiles = [[m[0], m[1] - missile_speed] for m in missiles]


             # top missile elimination

             missiles = [[m[0], m[1]] for m in missiles if m[1]>0]

                        

             **for i in range(len(explosion_list)):

                 if start_time < explosion_time:

                    pygame.display.update()

                    screen.blit(explosion, (explosion_pos_x - 30, explosion_pos_y - 30))

                    pygame.time.delay(10)**

                    else:

                         explosion_list = explosion_list[:i]


查看完整回答
反對 回復(fù) 2023-10-31
  • 2 回答
  • 0 關(guān)注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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