代码拉取完成,页面将自动刷新
#!/home/abc/anaconda3/bin/python
import pygame
import myplane
import enemy
import supply
import bullet
from sys import exit
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((480,700))
bg=pygame.image.load('images/background.png').convert()
screen.blit(bg,(0,0))
again=pygame.image.load('images/again.png').convert_alpha()
again_rect=again.get_rect()
again_rect.x,again_rect.y=(90,330)
gameover=pygame.image.load('images/gameover.png').convert_alpha()
gameover_rect=gameover.get_rect()
gameover_rect.x,gameover_rect.y=(90,390)
font=pygame.font.Font('font/font.ttf',32)
def main():
clock=pygame.time.Clock()
plane=myplane.Myplane(480,700)
bullet_list=[bullet.Bullet(plane.rect) for x in range(4)]
bullet_index=0
delay=0
enemys_group=pygame.sprite.Group([enemy.Enemy(480,700) for x in range(10)])
score=0
bomb=supply.Bomb_supply(480,700)
BOMBSUPPLYEVN=USEREVENT+1
pygame.time.set_timer(BOMBSUPPLYEVN,30*1000)
while True:
for event in pygame.event.get():
if event.type==QUIT:
exit()
elif event.type==BOMBSUPPLYEVN:
bomb.active=True
print("fsdfsd")
#屏幕
screen.blit(bg,(0,0))
#飞机
plane.move()
plane.collide(enemys_group)
plane.draw(screen)
#子弹
if not delay%12:
bullet_list[bullet_index%4].reset(plane.rect)
bullet_index+=1
for b in bullet_list:
b.move()
b.collide(enemys_group)
b.draw(screen)
#敌机
for e in enemys_group:
e.move()
e.draw(screen)
if e.score:
score+=e.score
e.score=0
bomb.move()
bomb.collide(plane)
bomb.draw(screen)
#打印份数
screen.blit(font.render("score:"+str(score),True,(0,0,0)),(20,5))
if plane.life_num==0:
break
delay+=1
pygame.display.flip()
clock.tick(30)
def game():
while True:
main()
#退出游戏
screen.blit(bg,(0,0))
screen.blit(again,again_rect)
screen.blit(gameover,gameover_rect)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type==QUIT:
exit()
if pygame.mouse.get_pressed()[0]:
print(pygame.mouse.get_pressed())
mx,my=pygame.mouse.get_pos()
print(mx,my)
if again_rect.collidepoint(mx,my):
break
if gameover_rect.collidepoint(mx,my):
pygame.quit()
exit()
game()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。