I have a serious problem with my game right now, after each kill I get the game starts lagging more and more. I thought it was because he was drawing the same thing twice and stuff and went trough some functions that was useless. But I cleaned it up as far as I can see anyways but it dident help. So now I turn to you guys, please help me, I really want to have enemies and not just one boss and I know that having one mayor file with code makes it a bit more difficoult then it would have been if I had used classes but please try with thie big chunk of code.
The code is quite large now but here it is:
# -*- coding: cp1252 -*-
import time
import pygame
from pygame.locals import*
pygame.init()
music = pygame.mixer.Sound('GameSoundtrack.wav')
music.play(1,0,10000)
vol = 1
Oldvol = 0
mute = False
Sfont = pygame.font.SysFont('Arial',20,False,True)
mutetxt = Sfont.render("Mute",1,(255,255,255))
screenWidth = 1018
screenHeight = 720
screen = pygame.display.set_mode((screenWidth,screenHeight))
facingLeft = False
clock = pygame.time.Clock()
fps = 50
shootLeft = False
shootRight = False
go = False
#Text
textSize = 55
font = pygame.font.SysFont('Arial',textSize,True,True)
Wintext = font.render("Congratulations, you have killed the evil boss!", 1, (0,255,0))
Losetext = font.render("You have failed this city!", 1, (255,0,0))
font2 = pygame.font.SysFont('Arial',40,True)
Lifetxt = font2.render("Life:",1,(255,255,255))
#Houses
house = pygame.image.load('Husen.png')
#Player
Player_facing_screen = pygame.image.load('GoodGuyFramPng.png')
Player_left = pygame.image.load('GubbeVanster.png')
Player_right = pygame.image.load('GubbeSidan.png')
Player = Player_facing_screen
PlayerRect = Player.get_rect()
Health = 100
#Boss
Boss_right = pygame.image.load('OndgubbeHoger.png')
Boss_left = pygame.image.load('OndgubbeVanster.png')
Bossen = Boss_left
Boss = Bossen.get_rect()
shoot = False
done = False
count = 0
Bhealth = 100
#Mobs
#Mob 1
Mob_Right = pygame.image.load('GangsterRight.png')
Mob_Left = pygame.image.load('GangsterLeft.png')
Mobs = Mob_Right
Mob = Mobs.get_rect()
Mob.x = 161
Mob.y = 206
M1vy = 0
Life = 25
dead1 = False
MobGoingLeft = False
MobGoingRight = True
M1onGround = False
M1moving = True
M1Shoot = False
M1Count = 0
#Mob 2
Mob2_Right = pygame.image.load('GangsterRight.png')
Mob2_Left = pygame.image.load('GangsterLeft.png')
Mobs2 = Mob2_Right
Mob2 = Mobs2.get_rect()
Mob2.x = 182
Mob2.y = 484
M2vy = 0
Life2 = 25
dead2 = False
Mob2GoingLeft = False
Mob2GoingRight = True
M2onGround = False
M2moving = True
M2Shoot = False
M2Count = 0
#Mob 3
Mob3_Right = pygame.image.load('GangsterRight.png')
Mob3_Left = pygame.image.load('GangsterLeft.png')
Mobs3 = Mob3_Right
Mob3 = Mobs3.get_rect()
Mob3.x = 450
Mob3.y = screenHeight - 80
M3vy = 0
Life3 = 25
dead3 = False
Mob3GoingLeft = False
Mob3GoingRight = True
M3onGround = False
M3moving = True
M3Shoot = False
M3Count = 0
#Mob 4
Mob4_Right = pygame.image.load('GangsterRight.png')
Mob4_Left = pygame.image.load('GangsterLeft.png')
Mobs4 = Mob4_Right
Mob4 = Mobs4.get_rect()
Mob4.x = 708
Mob4.y = screenHeight - 80
M4vy = 0
Life4 = 25
dead4 = False
Mob4GoingLeft = False
Mob4GoingRight = True
M4onGround = False
M4moving = True
M4Shoot = False
M4Count = 0
#Player variabler
x = 0
PlayerRect.y = screenHeight - 111
vx = 0
vy = 0
g = 2
onGround = False
jumping = False
moving = False
bmoving = True
finished = False
#Boss variabler
Boss.x = 800
Boss.y = 207
goingLeft = False
goingRight = True
bvy = 0
radius = 10
BonGround = False
Bdead = False
bullets = []
shoots = []
M1bullets = []
M2bullets = []
M3bullets = []
M4bullets = []
floors = [#house 1
(182,565,245),
(182,425,245),
#hus 2
(707,583,235),
(707,423,235),
(707,267,235)]
roofs = [#roof on house 1
(160,287,290),
#Top most balkony on house 1
(450,375,40),
#lowest most balkony on house 1
(450,520,40),
#roof on house 2
(685,100,275),
#pants
(520,577,45),
#top most balkony on house 2
(643,220,43),
#lowest most balkony on house 2
(643,533,43),
#middle balcony on house 2
(960,365,43)]
rects = [#house 1
(162,287,20,303),
(428,287,21,527),
#house 2
(686,101,22,322),
(937,101,23,615),
(686,533,23,220)]
while not done:
#Kommandon
for event in pygame.event.get():
#Shoot
if event.type == KEYDOWN and event.key == K_LCTRL:
bullets.append((PlayerRect.x,(PlayerRect.y + 40), (1,-1)[facingLeft] * 20))
if event.type == KEYDOWN and event.key == K_m and mute == True:
music.set_volume(Oldvol)
mute = False
elif event.type == KEYDOWN and event.key == K_m and mute == False:
vol = 0
music.set_volume(vol)
mute = True
elif event.type == KEYDOWN and event.key == K_KP_PLUS and mute == False:
vol += 0.1
Oldvol = vol
music.set_volume(vol)
elif event.type == KEYDOWN and event.key == K_KP_MINUS and mute == False:
vol -= 0.1
Oldvol = vol
music.set_volume(vol)
#Jump
elif event.type == KEYDOWN and event.key == K_SPACE and onGround:
vy = -25
onGround = False
jumping = True
elif event.type == KEYUP and event.key == K_SPACE and not onGround and vy < 0:
vy = 0
jumping = False
pressedKeys = pygame.key.get_pressed()
#walk/run
if pressedKeys[K_LEFT]:
PlayerRect.x -= (4 + pressedKeys[K_LSHIFT] * 8)
facingLeft = True
moving = True
Player = Player_left
if PlayerRect.left < 0:
PlayerRect.x += (4 + pressedKeys[K_LSHIFT] * 8)
for rect in rects:
if PlayerRect.left <= rect [0] + rect[2] and PlayerRect.left >= rect[0] and PlayerRect.y < rect[1] + rect[3] and PlayerRect.y > rect[1]:
PlayerRect.x += (4 + pressedKeys[K_LSHIFT] * 8)
elif pressedKeys[K_RIGHT]:
PlayerRect.x += (4 + pressedKeys[K_LSHIFT] * 8)
facingLeft = False
moving = True
Player = Player_right
if PlayerRect.right > screenWidth:
PlayerRect.right -= (4 + pressedKeys[K_LSHIFT] * 8)
#walks against house rects
for rect in rects:
if PlayerRect.right >= rect[0] and PlayerRect.x <= rect[0] + rect[2]/2 and PlayerRect.y < rect[1] + rect[3] and PlayerRect.y > rect[1]:
PlayerRect.right -= (4 + pressedKeys[K_LSHIFT] * 8)
#Avsluta
if event.type == KEYUP and (event.key == K_RIGHT or event.key == K_LEFT):
moving = False
if event.type == pygame.QUIT:
done = True
elif pressedKeys[K_ESCAPE]:
done = True
if not moving:
Player = Player_facing_screen
#----Bossen shoots player-----------------------------------------
if goingLeft and PlayerRect.x < Boss.x and not finished and go:
if Boss.x - PlayerRect.x <= 150 and PlayerRect.y + 20 == Boss.y:
bmoving = False
shoot = True
count += 1
else:
bmoving = True
count = 0
elif goingRight and PlayerRect.x > Boss.x and not finished and go:
if PlayerRect.x - Boss.x <= 150 and PlayerRect.y + 20 == Boss.y:
bmoving = False
shoot= True
count += 1
else:
bmoving = True
count = 0
elif goingLeft and PlayerRect.x > Boss.x and not finished and go:
bmoving = True
elif goingRight and PlayerRect.x < Boss.x and not finished and go:
bmoving = True
if shoot == True and count == 1:
shoots.append((Boss.x,(Boss.y + 5), (1,-1) [goingLeft] * 20))
shoot = False
#---Mob1 shoots player--------------------------------------
if MobGoingLeft and PlayerRect.x < Mob.x and not finished and not dead1:
if Mob.x - PlayerRect.x <= 150 and PlayerRect.y + 11 == Mob.y:
M1moving = False
M1Shoot = True
M1Count += 1
else:
M1moving = True
M1Count = 0
elif MobGoingRight and PlayerRect.x > Mob.x and not finished and not dead1:
if PlayerRect.x - Mob.x <= 150 and PlayerRect.y + 11 == Mob.y:
M1moving = False
M1Shoot = True
M1Count += 1
else:
M1moving = True
M1Count = 0
elif MobGoingLeft and PlayerRect.x > Mob.x and not finished and not dead1:
M1moving = True
elif MobGoingRight and PlayerRect.x < Mob.x and not finished and not dead1:
M1moving = True
if M1Shoot == True and M1Count == 1:
M1bullets.append((Mob.x,(Mob.y + 45), (1,-1) [MobGoingLeft] * 20))
M1Shoot == False
newM1bullets = []
for M1bullet in M1bullets:
if(-(screenWidth+100) < M1bullet[0] - Mob.x < (screenWidth + 100)):
newM1bullets.append((M1bullet[0] + M1bullet[2], M1bullet[1], M1bullet[2]))
M1bullets = newM1bullets
#-----------------------------------------------------------------------
#---Mob 2 shoots player------------------------------------------
if Mob2GoingLeft and PlayerRect.x < Mob2.x and not finished and not dead2:
if Mob2.x - PlayerRect.x <= 150 and PlayerRect.y + 11 == Mob2.y:
M2moving = False
M2Shoot = True
M2Count += 1
else:
M2moving = True
M2Count = 0
elif Mob2GoingRight and PlayerRect.x > Mob2.x and not finished and not dead2:
if PlayerRect.x - Mob2.x <= 150 and PlayerRect.y + 11 == Mob2.y:
M2moving = False
M2Shoot = True
M2Count += 1
else:
M2moving = True
M2Count = 0
elif Mob2GoingLeft and PlayerRect.x > Mob2.x and not finished and not dead2:
M2moving = True
elif Mob2GoingRight and PlayerRect.x < Mob2.x and not finished and not dead2:
M2moving = True
if M2Shoot == True and M2Count == 1:
M2bullets.append((Mob2.x,(Mob2.y + 45), (1,-1) [Mob2GoingLeft] * 20))
M2Shoot == False
newM2bullets = []
for M2bullet in M2bullets:
if(-(screenWidth+100) < M2bullet[0] - Mob2.x < (screenWidth + 100)):
newM2bullets.append((M2bullet[0] + M2bullet[2], M2bullet[1], M2bullet[2]))
M2bullets = newM2bullets
#---------------------------------------------------------------------------------
#---Mob 3 shoots player----------------------------------------------------
if Mob3GoingLeft and PlayerRect.x < Mob3.x and not finished and not dead3:
if Mob3.x - PlayerRect.x <= 150 and PlayerRect.y + 11 == Mob3.y:
M3moving = False
M3Shoot = True
M3Count += 1
else:
M3moving = True
M3Count = 0
elif Mob3GoingRight and PlayerRect.x > Mob3.x and not finished and not dead3:
if PlayerRect.x - Mob3.x <= 150 and PlayerRect.y + 11 == Mob3.y:
M3moving = False
M3Shoot = True
M3Count += 1
else:
M3moving = True
M3Count = 0
elif Mob3GoingLeft and PlayerRect.x > Mob3.x and not finished and not dead3:
M3moving = True
elif Mob3GoingRight and PlayerRect.x < Mob3.x and not finished and not dead3:
M3moving = True
if M3Shoot == True and M3Count == 1:
M3bullets.append((Mob3.x,(Mob3.y + 45), (1,-1) [Mob3GoingLeft] * 20))
M3Shoot == False
newM3bullets = []
for M3bullet in M3bullets:
if(-(screenWidth+100) < M3bullet[0] - Mob3.x < (screenWidth + 100)):
newM3bullets.append((M3bullet[0] + M3bullet[2], M3bullet[1], M3bullet[2]))
M3bullets = newM3bullets
#----------------------------------------------------------------------------------
#---Mob 4 shoots player----------------------------------------------------
if Mob4GoingLeft and PlayerRect.x < Mob4.x and not finished and not dead4:
if Mob4.x - PlayerRect.x <= 150 and PlayerRect.y + 11 == Mob4.y:
M4moving = False
M4Shoot = True
M4Count += 1
else:
M4moving = True
M4Count = 0
elif Mob4GoingRight and PlayerRect.x > Mob4.x and not finished and not dead4:
if PlayerRect.x - Mob4.x <= 150 and PlayerRect.y + 11 == Mob4.y:
M4moving = False
M4Shoot = True
M4Count += 1
else:
M4moving = True
M4Count = 0
elif Mob4GoingLeft and PlayerRect.x > Mob4.x and not finished and not dead4:
M4moving = True
elif Mob4GoingRight and PlayerRect.x < Mob4.x and not finished and not dead4:
M4moving = True
if M4Shoot == True and M4Count == 1:
M4bullets.append((Mob4.x,(Mob4.y + 45), (1,-1) [Mob4GoingLeft] * 20))
M4Shoot == False
newM4bullets = []
for M4bullet in M4bullets:
if(-(screenWidth+100) < M4bullet[0] - Mob4.x < (screenWidth + 100)):
newM4bullets.append((M4bullet[0] + M4bullet[2], M4bullet[1], M4bullet[2]))
M4bullets = newM4bullets
#----------------------------------------------------------------------------------
#physics
newShoots = []
for shoot in shoots:
if(-(screenWidth+100) < shoot[0] - Boss.x < (screenWidth + 100)):
newShoots.append((shoot[0] + shoot[2], shoot[1], shoot[2]))
shoots = newShoots
newBullets = []
for bullet in bullets:
if(-(screenWidth+100) < bullet[0] - x < (screenWidth + 100)):
newBullets.append((bullet[0] + bullet[2], bullet[1], bullet[2]))
bullets = newBullets
PlayerRect.y += vy
PlayerRect.x += vx
vy = min(vy + g, 20)
onGround = False
# check collisions
# floor
if vy > 0 and PlayerRect.bottom >= screenHeight:
if PlayerRect.bottom >= screenHeight and PlayerRect.bottom < screenHeight + vy:
PlayerRect.bottom = screenHeight
vy = 0
onGround = True
#floor in house
for floor in floors:
if vy > 0 and PlayerRect.x + 16 >= floor[0] and PlayerRect.x + 16 <= floor[0] + floor[2]:
if PlayerRect.bottom >= floor[1] and PlayerRect.bottom < floor[1] + vy * 2:
PlayerRect.bottom = floor[1]
vy = 0
onGround = True
if event.type == KEYDOWN and event.key == K_DOWN:
PlayerRect.bottom = floor[1] + 7
onGround = False
else:
break
#roof on buildings and the balconies
for roof in roofs:
if vy > 0 and PlayerRect.x + 16 >= roof[0] and PlayerRect.x + 16 <= roof[0] + roof[2]:
if PlayerRect.bottom >= roof[1] and PlayerRect.bottom < roof[1] + vy * 2:
PlayerRect.bottom = roof[1]
vy = 0
onGround = True
if event.type == KEYDOWN and event.key == K_DOWN:
PlayerRect.bottom = roof[1] + 7
onGround = False
else:
break
#--------Mobs-------------------------------------------------------------
#--------Mob 1------------------------------------------------------------
if MobGoingRight:
Mobs = Mob_Right
if M1moving:
Mob.x += 3
if Mob.right >= 449:
MobGoingRight = False
MobGoingLeft = True
elif MobGoingLeft:
Mobs = Mob_Left
if M1moving:
Mob.x -= 3
if Mob.left <= 160:
MobGoingLeft = False
MobGoingRight = True
#--------Mob 2-------------------------------------------------------------
if Mob2GoingRight:
Mobs2 = Mob2_Right
if M2moving:
Mob2.x += 3
for rect in rects:
if Mob2.right >= rect[0] and Mob2.x <= rect[0] + rect[2]/2 and Mob2.y < rect[1] + rect[3] and Mob2.y > rect[1]:
Mob2GoingRight = False
Mob2GoingLeft = True
elif Mob2GoingLeft:
Mobs2 = Mob_Left
if M2moving:
Mob2.x -= 3
for rect in rects:
if Mob2.left <= rect[0] + rect[2] and Mob2.left >= rect[0] and Mob2.y < rect[1] + rect[3] and Mob2.y > rect[1]:
Mob2GoingLeft = False
Mob2GoingRight = True
#--------Mob 3-------------------------------------------------------------
if Mob3GoingRight:
Mobs3 = Mob3_Right
if M3moving:
Mob3.x += 3
for rect in rects:
if Mob3.right >= rect[0] and Mob3.x <= rect[0] + rect[2]/2 and Mob3.y < rect[1] + rect[3] and Mob3.y > rect[1]:
Mob3GoingRight = False
Mob3GoingLeft = True
elif Mob3GoingLeft:
Mobs3 = Mob3_Left
if M3moving:
Mob3.x -= 3
for rect in rects:
if Mob3.left <= rect[0] + rect[2] and Mob3.left >= rect[0] and Mob3.y < rect[1] + rect[3] and Mob3.y > rect[1]:
Mob3GoingLeft = False
Mob3GoingRight = True
#--------Mob 4-------------------------------------------------------------
if Mob4GoingRight:
Mobs4 = Mob4_Right
if M4moving:
Mob4.x += 3
for rect in rects:
if Mob4.right >= rect[0] and Mob4.x <= rect[0] + rect[2]/2 and Mob4.y < rect[1] + rect[3] and Mob4.y > rect[1]:
Mob4GoingRight = False
Mob4GoingLeft = True
elif Mob4GoingLeft:
Mobs4 = Mob4_Left
if M4moving:
Mob4.x -= 3
for rect in rects:
if Mob4.left <= rect[0] + rect[2] and Mob4.left >= rect[0] and Mob4.y < rect[1] + rect[3] and Mob4.y > rect[1]:
Mob4GoingLeft = False
Mob4GoingRight = True
#--------Bossen------------------------------------------------------------
#walk
if goingLeft:
Bossen = Boss_left
if bmoving and go:
Boss.x -= 3
for rect in rects:
if Boss.left <= rect [0] + rect[2] and Boss.left >= rect[0] and Boss.y < rect[1] + rect[3] and Boss.y > rect[1]:
goingLeft = False
goingRight = True
elif goingRight:
Bossen = Boss_right
if bmoving and go:
Boss.x += 3
for rect in rects:
if Boss.right >= rect[0] and Boss.x <= rect[0] + rect[2]/2 and Boss.y < rect[1] + rect[3] and Boss.y > rect[1]:
goingRight = False
goingLeft = True
#physics Mob1 och collision
Mob.y += M1vy
M1vy = min(M1vy + g, 20)
M1onGround = False
for roof in roofs:
if M1vy > 0 and Mob.x + 16 >= roof[0] and Mob.x + 16 <= roof[0] + roof[2]:
if Mob.bottom >= roof[1] and Mob.bottom < roof[1] + M1vy * 2:
Mob.bottom = roof[1]
M1vy = 0
M1onGround = True
break
#Physics Mob2 and collisions
Mob2.y += M2vy
M2vy = min(M2vy + g, 20)
M2onGround = False
for floor in floors:
if M2vy > 0 and Mob2.x + 16 >= floor[0] and Mob2.x + 16 <= floor[0] + floor[2]:
if Mob2.bottom >= floor[1] and Mob2.bottom < floor[1] + M2vy * 2:
Mob2.bottom = floor[1]
M2vy = 0
M2onGround = True
break
#Physics Mob3 and collisions
Mob3.y += M3vy
M3vy = min(M3vy + g, 20)
M3onGround = False
if M3vy > 0 and Mob3.bottom >= screenHeight:
if Mob3.bottom >= screenHeight and Mob3.bottom < screenHeight + M3vy:
Mob3.bottom = screenHeight
M3vy = 0
M3onGround = True
#Physics Mob4 and collisions
Mob4.y += M4vy
M4vy = min(M4vy + g, 20)
M4onGround = False
if M4vy > 0 and Mob4.bottom >= screenHeight:
if Mob4.bottom >= screenHeight and Mob4.bottom < screenHeight + M4vy:
Mob4.bottom = screenHeight
M4vy = 0
M4onGround = True
#Physics Boss
Boss.y += bvy
bvy = min(bvy + g, 20)
BonGround = False
# check collisions with floor
for floor in floors:
if bvy > 0 and Boss.x + 16 >= floor[0] and Boss.x + 16 <= floor[0] + floor[2]:
if Boss.bottom >= floor[1] and Boss.bottom < floor[1] + bvy * 2:
Boss.bottom = floor[1]
bvy = 0
BonGround = True
break
#-----------------------------------------------------------------------
jumping = jumping and vy < 0
#draw
#Bcakgrund
for i in range (1):
background = pygame.image.load('bakgrund.jpg')
screen.blit(background, (0,0))
for floor in floors:
pygame.draw.line(screen,(120,88,34),(floor[0], floor[1]),(floor[0] + floor[2],floor[1]),1)
for roof in roofs:
pygame.draw.line(screen,(70,67,63),(roof[0], roof[1]),(roof[0] + roof[2],roof[1]),1)
for rect in rects:
pygame.draw.rect(screen,(255,0,0),(rect[0],rect[1],rect[2],rect[3]),0)
for i in range (1):
screen.blit(house,(0,100))
#Health bar och text
if mute:
screen.blit(mutetxt,(900,5,))
screen.blit(Lifetxt,(5,5))
pygame.draw.rect(screen,(0,255,0),(80,10,(150*(Health/100)),40))
#Player and boss and mobs
if Life >= 0 and Life2 >= 0 and Life3 >= 0 and Life4 >= 0:
screen.blit(Mobs,Mob)
screen.blit(Mobs2,Mob2)
screen.blit(Mobs3,Mob3)
screen.blit(Mobs4,Mob4)
if Life <= 0:
M1moving = False
M1Shoot = False
dead1 = True
screen.blit(background,(0,0))
if mute:
screen.blit(mutetxt,(900,5,))
screen.blit(Lifetxt,(5,5))
pygame.draw.rect(screen,(0,255,0),(80,10,(150*(Health/100)),40))
screen.blit(house,(0,100))
#screen.blit(Player,PlayerRect)
if Life2 > 0:
screen.blit(Mobs2,Mob2)
if Life3 > 0:
screen.blit(Mobs3,Mob3)
if Life4 > 0:
screen.blit(Mobs4,Mob4)
if Life2 <= 0:
M2moving = False
M2Shoot = False
dead2 = True
screen.blit(background,(0,0))
if mute:
screen.blit(mutetxt,(900,5))
screen.blit(Lifetxt,(5,5))
pygame.draw.rect(screen,(0,255,0),(80,10,(150*(Health/100)),40))
screen.blit(house,(0,100))
#screen.blit(Player,PlayerRect)
if Life > 0:
screen.blit(Mobs,Mob)
if Life3 > 0:
screen.blit(Mobs3,Mob3)
if Life4 > 0:
screen.blit(Mobs4,Mob4)
if Life3 <= 0:
M3moving = False
M3Shoot = False
dead3 = True
screen.blit(background,(0,0))
if mute:
screen.blit(mutetxt,(900,5))
screen.blit(Lifetxt,(5,5))
pygame.draw.rect(screen,(0,255,0),(80,10,(150*(Health/100)),40))
screen.blit(house,(0,100))
#screen.blit(Player,PlayerRect)
if Life > 0:
screen.blit(Mobs,Mob)
if Life2 > 0:
screen.blit(Mobs2,Mob2)
if Life4 > 0:
screen.blit(Mobs4,Mob4)
if Life4 <= 0:
M4moving = False
M4Shoot = False
dead4 = True
screen.blit(background,(0,0))
if mute:
screen.blit(mutetxt,(900,5))
screen.blit(Lifetxt,(5,5))
pygame.draw.rect(screen,(0,255,0),(80,10,(150*(Health/100)),40))
screen.blit(house,(0,100))
#screen.blit(Player,PlayerRect)
if Life > 0:
screen.blit(Mobs,Mob)
if Life3 > 0:
screen.blit(Mobs3,Mob3)
if Life2 > 0:
screen.blit(Mobs2,Mob2)
screen.blit(Player,PlayerRect)
#the shots
#the boss shoots
hurt = None
for a, shoot in enumerate(shoots):
brect = pygame.Rect(shoot[0] - 3, shoot[1] - 3,3*2, 3*2)
shots = pygame.draw.circle(screen,(255,255,255),(brect.center),3)
if brect.collidelistall(rects):
hurt = a
del shoots[a]
count = 0
elif brect.colliderect(PlayerRect):
Health -= 25
hurt = a
del shoots[a]
count = 0
#Player shoots
hit = None
for index, bullet in enumerate(bullets):
crect = pygame.Rect(bullet[0] - 3, bullet[1] - 3,3*2,3*2)
shot = pygame.draw.circle(screen,(255,255,255),(crect.center),3)
if crect.collidelistall(rects):
hit = index
del bullets [index]
if crect.colliderect(Boss):
Bhealth -= 35
hit = index
del bullets[index]
if crect.colliderect(Mob):
dead1 = True
Life = 0
del bullets[index]
if crect.colliderect(Mob2):
dead2 = True
Life2 = 0
del bullets[index]
if crect.colliderect(Mob3):
dead3 = True
Life3 = 0
del bullets[index]
if crect.colliderect(Mob4):
dead4 = True
Life4 = 0
del bullets[index]
#Mob1 sshoots
m1 = None
for Mb1, M1bullet in enumerate(M1bullets):
m1rect = pygame.Rect(M1bullet[0] - 3, M1bullet[1] - 3,6,6)
M1shot = pygame.draw.circle(screen,(255,255,255),(m1rect.center),3)
if m1rect.collidelistall(rects):
m1 = Mb1
del M1bullets[Mb1]
M1Count = 0
elif m1rect.colliderect(PlayerRect):
Health -= 10
m1 = Mb1
del M1bullets[Mb1]
M1Count = 0
#Mob2 shoots
m2 = None
for Mb2, M2bullet in enumerate(M2bullets):
m2rect = pygame.Rect(M2bullet[0] - 3, M2bullet[1] - 3,6,6)
M2shot = pygame.draw.circle(screen,(255,255,255),(m2rect.center),3)
if m2rect.collidelistall(rects):
m2 = Mb2
del M2bullets[Mb2]
M2Count = 0
elif m2rect.colliderect(PlayerRect):
Health -= 10
m2 = Mb2
del M2bullets[Mb2]
M2Count = 0
#Mob3 shoots
m3 = None
for Mb3, M3bullet in enumerate(M3bullets):
m3rect = pygame.Rect(M3bullet[0] - 3, M3bullet[1] - 3,6,6)
M3shot = pygame.draw.circle(screen,(255,255,255),(m3rect.center),3)
if m3rect.collidelistall(rects):
m3 = Mb3
del M3bullets[Mb3]
M3Count = 0
elif m3rect.colliderect(PlayerRect):
Health -= 10
m3 = Mb3
del M3bullets[Mb3]
M3Count = 0
#Mob4 shoots
m4 = None
for Mb4, M4bullet in enumerate(M4bullets):
m4rect = pygame.Rect(M4bullet[0] - 3, M4bullet[1] - 3,6,6)
M4shot = pygame.draw.circle(screen,(255,255,255),(m4rect.center),3)
if m4rect.collidelistall(rects):
m4 = Mb4
del M4bullets[Mb4]
M4Count = 0
elif m4rect.colliderect(PlayerRect):
Health -= 10
m4 = Mb4
del M4bullets[Mb4]
M4Count = 0
#If player is dead
if Health <= 0:
finished = True
bmoving = False
shoot = False
screen.blit(house,(0,100))
screen.blit(Bossen,Boss)
screen.blit(Losetext,(250,(screenHeight/2)))
#If boss is dead
if Bhealth <= 0:
Bdead = True
finished = True
bmoving = False
shoot = False
screen.blit(house,(0,100))
screen.blit(Player,PlayerRect)
screen.blit(Wintext,(0,(screenHeight/2)))
#if all gangsters are dead
if Life <= 0 and Life2 <= 0 and Life3 <= 0 and Life4 <= 0 and not Bdead:
go = True
screen.blit(Bossen,Boss)
pygame.display.flip()
clock.tick(fps)
pygame.quit()