1 Star 0 Fork 0

MACRO/飞机大战小游戏

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
#!/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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/macro886/aircraft_war_games.git
git@gitee.com:macro886/aircraft_war_games.git
macro886
aircraft_war_games
飞机大战小游戏
master

搜索帮助