1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
def SpaceInvader():
pygame.init()
#size=width,height=600,500
#screen = pygame.display.set_mode(size)
global width, screen, background, backgroundRect
pygame.display.set_caption("Boolean Space Invader")
background = pygame.image.load("background.gif")
backgroundRect = background.get_rect()
size = (width, height) = background.get_size()
screen = pygame.display.set_mode(size)
white=255,255,255,255
global shooted
global shoots
shoots =[]
shooted = 0
#--- creating player AND computers ships
global Comica
Comica = PlayerShip()
global Computer
Computer = Wave(5)
Computer.MyInit()
#---- end
pygame.key.set_repeat(500,30)
count = 0
inGame = True
screen.blit(background,backgroundRect)
screen.blit(Comica.image, Comica.rect)
for x in Computer.ships:
screen.blit(x.image, x.rect )
while inGame:
count = count +1
#------ displaying player ship
move(clavier())
#--------- end
#----- displaying computers ships
if(Computer.loose == False):
if (count%170)==0:
Computer.moveAll(width)
screen.blit(background,backgroundRect)
for x in Computer.ships:
screen.blit(x.image, x.rect )
screen.blit(Comica.image, Comica.rect)
count = 1
#-------- end
#---- shooting display
if shooted == 1:
for x2 in shoots:
screen.blit(x2.image,x2.rect)
if ((x2.test == True) & ((count%25)==0)):
screen.blit(background, backgroundRect )
for x in Computer.ships:
screen.blit(x.image, x.rect )
screen.blit(Comica.image, Comica.rect)
x2.Continue(Computer)
elif(x2.test == False):
shoots.remove(x2)
#----------end
else:
#---- lost...
inGame = False
screen.blit(Computer.image, Computer.rect )
pygame.display.update()
def clavier():
# inputs from player
for event in pygame.event.get():
while event.type==pygame.KEYDOWN:
if event.key==pygame.K_UP:
return("up")
if event.key==pygame.K_DOWN:
return("down")
if event.key==pygame.K_LEFT:
return("left")
if event.key==pygame.K_RIGHT:
return("right")
if event.key==pygame.K_q:
sys.exit()
if event.type==pygame.QUIT:
sys.exit()
def move(direction):
# direction depending of clavier() function
X = 20
global shooted
if direction=="left":
newpos=[-X,0]
essai= Comica.rect.move(newpos)
if essai[0]>=-10:
Comica.move(-X)
screen.blit(background,backgroundRect)
screen.blit(Comica.image, Comica.rect)
for x in Computer.ships:
screen.blit(x.image, x.rect )
if direction=="right":
newpos=[X,0]
essai= Comica.rect.move(newpos)
if essai[0]<width:
Comica.move(X)
screen.blit(background,backgroundRect)
screen.blit(Comica.image, Comica.rect)
for x in Computer.ships:
screen.blit(x.image, x.rect )
if direction=="down":
print "ok"
if direction == "up":
shooted = 1
shoots.append( Shoot(Comica.X, Comica.Y)) |
Partager