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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
| def redrawGameWindow(win):
global powerups
global battleship
global alienkills
global spaceshipkills
global pausebutton
global holdingpowerup
global usepowerup
global poweruploop
global alien2kills
global move_back
global count
global poweruploop2
global circle
global flash
global no_protection
img_explose = "data/shrapnel.png"
fog.draw(win)
lvlfont = pygame.font.Font(set.font, 40)
text = lvlfont.render('Niveau: ' + str(level), 1, red) # texte en haut
win.blit(text, (1100 - round(text.get_width() / 2), 10))
text = lvlfont.render('Pouvoirs : ', 1, (green)) # texte Powerups seul en haut ecran
win.blit(text, (5, 55))
if circle:
color = counter()
textp = text_font('PROTECTION', color, 'large') # fonction text_font gere largeur police
win.blit(textp, (350, 950))
flash = False # plus d'eclaire sur héro
no_protection = False # le score héro ne bouge plus
anneau.animate('anneaux')
for powerup in powerups:
if powerup[1] == True:
holdingpowerup = True
color = counter()
textp = text_font(powerup[0], color, 'large') # fonction text_font gere largeur police
win.blit(textp, (text.get_width() + 10, 55))
poweruploop2 += 1
if poweruploop2 == 1500:
poweruploop2 = 0
holdingpowerup = False
for powerup in powerups:
if powerup[1] == True:
powerup[1] = False
if holdingpowerup: # holdingpowerup : maintien du pouvoir
usebutton = t.button(win, 'Utilisation', 50 + text.get_width() + textp.get_width() + 20, 25, 150, 40, green,
black,
green)
if usebutton:
holdingpowerup = False
usepowerup = True # utilisation du pouvoir
if usepowerup: # utiliser la pouvoir , a False au debut fichier
for powerup in powerups: # powerup : pouvoir utilisé
if powerup[1] == True: # remise de powerup a False
powerup[1] = False
powerup[2] = True # 2eme booleen passe a True
for powerup in powerups:
if powerup[2]:
textp = lvlfont.render(powerup[0], 1, green)
win.blit(textp, (text.get_width() + 10, 55))
poweruploop += 1
if poweruploop == 1720:
poweruploop = 0
powerup[2] = False
usepowerup = False
if not holdingpowerup and not usepowerup:
textp = lvlfont.render('aucun', 1, green)
win.blit(textp, (text.get_width() + 10, 55))
pausebutton = t.button(win, 'Pause', 825, 10, 150, 50, green, black, green)
keys = pygame.key.get_pressed()
if pausebutton or keys[pygame.K_ESCAPE]: # if pausebutton = si clique sur pause
pause(win)
for laser in lasers:
laser.draw(win)
for laser in enemylasers:
laser.draw(win)
for laser in aliens2_lasers:
laser.draw(win)
for laser in aliens2_lasers2:
laser.draw(win)
for laser in alien3_lasers:
laser.draw(win)
for alien in aliens:
if alien.health >= 1:
alien.draw(win)
else:
for x in range(17):
shrap = Shrapnel(2, alien.rect.x, alien.rect.y, 40, 8, 8, img_explose, 16) # "explode" shrapnel
shrap.x_force = random.randrange(-40, 40) / 5
shrap.y_force = random.randrange(-40, 40) / 5
shrapnel_list.add(shrap)
explosesound.play()
explosesound.set_volume(0.5)
aliens.pop(aliens.index(alien))
alienkills += 1
if alien.rect.x + alien.hitbox[2] < 0:
aliens.pop(aliens.index(alien))
for v in enemyspaceships:
if v.health >= 1:
v.animate('paon')
v.draw(win)
else:
explosesound.play()
explosesound.set_volume(0.5)
explosion = Animations(v.rect.x, v.rect.y, 'explose2', 300, 300)
explosion_group.add(explosion)
enemyspaceships.pop()
spaceshipkills += 1
for alien in aliens2:
global alien2loop
if alien.health >= 1:
if len(aliens) <= 25:
alien2loop += 1
if alien2loop < 250:
alien.animate('sentinel_2')
alien.move(win)
alien.fire()
if alien2loop > 250 and alien2loop < 1500:
alien.animate('sentinel')
move_back = False
alien.up_and_down(win)
alien.fire()
if alien2loop > 1500 and alien2loop < 1800:
alien.animate('sentinel')
move_back = False
alien.move_back(win)
if alien2loop > 1800 and alien2loop < 3000:
move_back = True
alien.animate('sentinel_2')
alien.up_and_down(win)
alien.fire()
if alien2loop > 3000:
alien.animate('sentinel_2')
move_back = True
alien.move_exit(win)
else:
explosesound.play()
explosesound.set_volume(0.5)
explosion = Animations(alien.rect.x, alien.rect.y, 'explose', 250, 250)
explosion_group.add(explosion)
aliens2.pop()
alienkills += 1
alien2loop = 0
if alien.rect.x + alien.image.get_width() < 0:
aliens2.pop()
alien2loop = 0
for alien in alien3:
global alien3loop
if alien.health >= 1:
alien3loop += 1
if alien3loop < 630:
alien.animate('bouleRight') # 550,400
alien.move(win)
if alien3loop > 630 and alien3loop < 5000:
alien.animate('boule')
alien.up_and_down(win)
if alien3loop > 5000:
alien.animate('boule')
alien.move_exit(win)
else:
shrap = Shrapnel(2, alien.rect.x, alien.rect.y, 40, 8, 8, "data/shrapnel.png")
shrapnel_list.add(shrap)
for x in range(17):
shrap = Shrapnel(2, alien.rect.x, alien.rect.y, 40, 8, 8, "data/shrapnel.png") # "explode" shrapnel
shrap.x_force = random.randrange(-20, 20) / 10
shrap.y_force = random.randrange(-20, 20) / 10
shrapnel_list.add(shrap)
explosesound.play()
explosesound.set_volume(0.5)
alien3.pop(alien3.index(alien))
alienkills += 1
if alien.rect.x + alien.img_w + 50 < 0:
alien3.pop()
if len(alien3) == 0:
alien3loop = 0
shrapnel_list.update()
shrapnel_list.draw(win)
if battleship.visible: # battleship : instance héro
battleship.draw(win)
if circle:
anneau.draw(win)
battleship.drawHealthBar(win) # barre de vie
explosion_group.draw(win)
explosion_group.update()
anim_group.draw(win)
anim_group.update()
pygame.display.update() |
Partager