from pygame import *
from sys import *
init()
font.init()
screen=display.set_mode((0,0),FULLSCREEN)
ship_x,ship_y=900,1000
bullet=[]
bullet_x=[]
bullet_y=[]
alien_x=[]
alien_y=[]
alien_delete=[]
get_alien_x=0
get_alien_y=0
alien_left=False
alien_right=True
game_over=False
score=0
you_win=False
for a in range(8):
for a in range(8):
alien_x.append(get_alien_x)
alien_y.append(get_alien_y)
get_alien_x+=191
get_alien_x=0
get_alien_y+=61
Left_down=False
Right_down=False
while True:
i=0
for a in event.get():
if a.type == KEYDOWN:
if a.key == K_LEFT and game_over==False and you_win==False:
Left_down = True
if a.key == K_RIGHT and game_over==False and you_win==False:
Right_down = True
if a.key == K_SPACE and game_over==False and you_win==False:
bullet.append(1)
bullet_x.append(ship_x+20)
bullet_y.append(ship_y)
if a.key == K_q:
quit()
exit()
if a.type == KEYUP:
if a.key == K_LEFT:
Left_down=False
if a.key == K_RIGHT:
Right_down = False
screen.fill((255,255,255))
if ship_x+60>1900:
Right_down=False
if ship_x-30<0:
Left_down=False
ship=image.load("ship.bmp").convert()
ship.set_colorkey((230,230,230))
screen.blit(ship,(ship_x,ship_y))
for a in range(len(bullet)):
draw.rect(screen,(0,0,0),(bullet_x[a],bullet_y[a],5,6))
for a in range(len(bullet)):
bullet_y[a]-=25
for c in range(8):
for a in range(8):
b=image.load("alien.bmp").convert()
b.set_colorkey((230,230,230))
screen.blit(b,(alien_x[i],alien_y[i]))
i+=1
if Left_down and game_over==False and you_win==False:
ship_x-=30
if Right_down and game_over==False and you_win==False:
ship_x+=30
if alien_right and game_over==False and you_win==False:
for a in range(64):
alien_x[a]+=5
if alien_x[a]+90>2000 and (str(a) in alien_delete) == False:
alien_right=False
alien_left=True
for a in range(64):
alien_y[a]+=5
if alien_y[a]>1000:
game_over=True
if ship_x>alien_x[a] and ship_x<alien_x[a]+60 and ship_y>alien_y[a] and ship_y<alien_y[a]+58:
game_over=True
for b in range(len(bullet_x)):
if bullet_x[b]>alien_x[a] and bullet_x[b]<alien_x[a]+60 and bullet_y[b]<alien_y[a]+60 and bullet_y[b]>alien_y[a]:
alien_x[a],bullet_x[b]=1000000,100000
alien_delete.append(str(a))
score+=10
break
if alien_left and game_over==False and you_win==False:
for a in range(64):
alien_x[a]-=5
if alien_x[a]<0 and (str(a) in alien_delete) ==False:
alien_right=True
alien_left=False
for a in range(64):
alien_y[a]+=5
if alien_y[a]>1000:
game_over=True
if ship_x>alien_x[a] and ship_x<alien_x[a]+60 and ship_y>alien_y[a] and ship_y<alien_y[a]+58:
game_over=True
for b in range(len(bullet_x)):
if bullet_x[b]>alien_x[a] and bullet_x[b]<alien_x[a]+60 and bullet_y[b]<alien_y[a]+60 and bullet_y[b]>alien_y[a]:
alien_x[a],bullet_x[b]=1000000,100000
alien_delete.append(str(a))
score+=10
break
if game_over:
screen.blit(font.SysFont("simhei",100).render("Game Over",0,(0,0,0)),(700,530))
if score==640:
you_win=True
screen.blit(font.SysFont("simhei",100).render("You Win",0,(0,0,0)),(700,530))
screen.blit(font.SysFont("simhei",100).render("%s"%str(score),0,(0,0,0)),(1400,00))
time.Clock().tick(40)
display.flip()
外星人入侵游戏开发
最新推荐文章于 2024-07-26 11:32:54 发布