pygame飛機大戰4

2021-08-17 11:17:10 字數 1073 閱讀 3009

pygame.mask.from_su***ce(self,image)

對的非透明部分做標記

pygame.sprite.spritecollide(b, enemies, false, pygame.sprite.collide_mask)

完美檢測碰撞

me.rect.midtop,子彈生成在飛機的中間的頂部

if not(delay % 10):

bullet1[bullet1_index].reset(me.rect.midtop)

bullet1_index = (bullet1_index + 1) % bullet1_num

每10幀繪製一枚子彈,子彈索引0~3,

按照子彈的飛行速度,4個子彈差不多乙個螢幕的高度

pygame.draw.line(screen, black, \

(each.rect.left, each.rect.top - 5), \

(each.rect.right, each.rect.top - 5), \

2)繪製血槽的底槽,黑色,放在飛機的上方5個畫素的位置,2個畫素的寬度

energy_remain = each.energy / enemy.bigenemy.energy

if energy_remain > 0.2:

energy_color = green

else:

energy_color = red

pygame.draw.line(screen, energy_color, \

(each.rect.left, each.rect.top - 5), \

(each.rect.left + each.rect.width * energy_remain, \

each.rect.top - 5), 2)

如果energy(血量)大於百分之20,血條顏色為綠色,低於則為紅色

起點(each.rect.left, each.rect.top - 5)

終點(each.rect.left + each.rect.width * energy_remain, \each.rect.top - 5)

pygame飛機大戰3

self.destroy images.extend pygame.image.load images enemy1 down1.png convert alpha pygame.image.load images enemy1 down2.png convert alpha pygame.imag...

pygame飛機大戰5

score font.render score s str score true,white render函式把字元字串轉換為su ce物件 true拒絕鋸齒 paused rect.collidepoint event.pos 在paused rect矩形類裡有collidepoint event...

pygame飛機大戰7

if me destroy index 0 life num 1 me.reset pygame.time.set timer invincible time,3 1000 if enemies down and not me.invincible me.active false for e in ...