Commit 61e871d8 authored by christopher.spray's avatar christopher.spray

FINAL final push

parent a94fec03
...@@ -17,8 +17,6 @@ class Bandit(pygame.sprite.Sprite): ...@@ -17,8 +17,6 @@ class Bandit(pygame.sprite.Sprite):
self.image.set_colorkey(WHITE) #set transparency to white self.image.set_colorkey(WHITE) #set transparency to white
self.rect = self.image.get_rect() #get the rect for the img self.rect = self.image.get_rect() #get the rect for the img
self.rect.center = (window_height / 2, window_width / 2) #place in center of screen self.rect.center = (window_height / 2, window_width / 2) #place in center of screen
#self.rect.y = randint(0, window_height-self.rect.width)
#self.rect.x = randint(0, window_height-self.rect.width)
self.speed = speedAI self.speed = speedAI
self.playerRef = player self.playerRef = player
self.observer = observer self.observer = observer
...@@ -66,7 +64,6 @@ class Bandit(pygame.sprite.Sprite): ...@@ -66,7 +64,6 @@ class Bandit(pygame.sprite.Sprite):
if totalDiff < self.rect.width and otherBandit.playerDist() < self.playerDist(): if totalDiff < self.rect.width and otherBandit.playerDist() < self.playerDist():
self.stopped = True self.stopped = True
self.stoppedTimer = time.time() self.stoppedTimer = time.time()
print("STOPPED")
if self.stopped and time.time() > self.stoppedTimer + self.stopWaitLength: if self.stopped and time.time() > self.stoppedTimer + self.stopWaitLength:
self.stopped = False self.stopped = False
......
...@@ -28,9 +28,11 @@ rightPressed = False ...@@ -28,9 +28,11 @@ rightPressed = False
bulletFired = False bulletFired = False
bulletFiredTime = 0 bulletFiredTime = 0
bulletFireRate = 0.333 bulletFireRate = 0.333
gameWon = False
gameLost = False
# pygame.mixer.music.load('music.mp3') pygame.mixer.music.load('music.mp3')
# pygame.mixer.music.play(-1) pygame.mixer.music.play(-1)
pygame.display.set_caption("Cowboy Shooter") pygame.display.set_caption("Cowboy Shooter")
screenSize = (window_width, window_height) screenSize = (window_width, window_height)
...@@ -71,29 +73,9 @@ spriteGroupWall.add(wallBotRightVer) ...@@ -71,29 +73,9 @@ spriteGroupWall.add(wallBotRightVer)
player = Cowboy(window_width, window_height, speed) player = Cowboy(window_width, window_height, speed)
observer = ai_observer(maxBandits) observer = ai_observer(maxBandits)
#bandit1 = Bandit(player, window_height, window_width, speedAI)
enemiesOnScreen = 0 enemiesOnScreen = 0
#for i in range (maxBandits):
# if(enemiesOnScreen <5):
# enemiesOnScreen += 1
# b = Bandit(player, window_height, window_width, speedAI, observer,spriteGroupAI)
# spriteGroupAI.add(b)
# else:
spriteGroup.add(player) spriteGroup.add(player)
#-------------------------------------------------------------
#BULLETS
#-------------------------------------------------------------
upCollide = False upCollide = False
downCollide = False downCollide = False
leftCollide = False leftCollide = False
...@@ -187,12 +169,16 @@ while run is True: ...@@ -187,12 +169,16 @@ while run is True:
if time.time() > bulletFiredTime + bulletFireRate: if time.time() > bulletFiredTime + bulletFireRate:
bulletFired = False bulletFired = False
if not observer.gameWon and not gameLost:
if(enemiesOnScreen <5): if(enemiesOnScreen <5):
enemiesOnScreen += 1 enemiesOnScreen += 1
b = Bandit(player, window_height, window_width, speedAI, observer,spriteGroupAI, spriteGroupWall, enemiesOnScreen) b = Bandit(player, window_height, window_width, speedAI, observer,spriteGroupAI, spriteGroupWall, enemiesOnScreen)
spriteGroupAI.add(b) spriteGroupAI.add(b)
else: else:
pass; pass;
elif enemiesOnScreen <=0 and not gameLost:
winText = font.render("GAME WON", True, (0,0,0))
screen.blit(winText, (350,350))
#------------------------------------------------------------- #-------------------------------------------------------------
#COLLISIONS #COLLISIONS
...@@ -204,7 +190,8 @@ while run is True: ...@@ -204,7 +190,8 @@ while run is True:
observer.notify_enemy_died() observer.notify_enemy_died()
enemiesOnScreen -=1 enemiesOnScreen -=1
if(player.health <=0): if(player.health <=0):
run = False gameLost = True
#run = False
for b in spriteGroupAI: for b in spriteGroupAI:
...@@ -213,23 +200,6 @@ while run is True: ...@@ -213,23 +200,6 @@ while run is True:
b.kill() b.kill()
enemiesOnScreen -=1 enemiesOnScreen -=1
#Checking if player hits wall
# playerHitWall = pygame.sprite.spritecollide(player, spriteGroupWall, False) #if player collides with any wall
# if playerHitWall:
# if wPressed:
# upCollide = True
# elif aPressed:
# leftCollide = True
# elif sPressed:
# downCollide = True
# elif dPressed:
# rightCollide = True
# else:
# upCollide = False
# leftCollide = False
# downCollide = False
# rightCollide = False
#checking if bullets hit the bandits #checking if bullets hit the bandits
bulletHitBandit = pygame.sprite.groupcollide(spriteGroupBullet, spriteGroupAI, True, True) bulletHitBandit = pygame.sprite.groupcollide(spriteGroupBullet, spriteGroupAI, True, True)
if bulletHitBandit: if bulletHitBandit:
...@@ -248,17 +218,26 @@ while run is True: ...@@ -248,17 +218,26 @@ while run is True:
healthText = font.render("Health: x" + str(player.health), True, (0,0,0)) healthText = font.render("Health: x" + str(player.health), True, (0,0,0))
#------------------------------------------------------------- #-------------------------------------------------------------
spriteGroup.update(window_width, window_height) #calls all the update functions in all sprites
spriteGroupAI.update()
spriteGroupWall.update() spriteGroupWall.update()
spriteGroupBullet.update() spriteGroupBullet.update()
if not gameLost:
spriteGroup.update(window_width, window_height) #calls all the update functions in all sprites
spriteGroupAI.update()
spriteGroup.draw(screen) spriteGroup.draw(screen)
spriteGroupAI.draw(screen) spriteGroupAI.draw(screen)
spriteGroupWall.draw(screen) spriteGroupWall.draw(screen)
spriteGroupBullet.draw(screen) spriteGroupBullet.draw(screen)
screen.blit(enemiesLeftText, (5,5)) screen.blit(enemiesLeftText, (5,5))
screen.blit(healthText, (575,3)) screen.blit(healthText, (575,3))
if gameLost:
lostText = font.render("YOU LOSE", True, (0,0,0))
screen.blit(lostText, (350,350))
pygame.display.flip() pygame.display.flip()
...@@ -4,10 +4,13 @@ class ai_observer(): ...@@ -4,10 +4,13 @@ class ai_observer():
def __init__(self, maxBandits): def __init__(self, maxBandits):
self.enemiesRemaining = maxBandits self.enemiesRemaining = maxBandits
self.gameWon = False
def notify_enemy_died(self): def notify_enemy_died(self):
if self.enemiesRemaining <= 0:
self.gameWon = True
else:
self.enemiesRemaining -=1 self.enemiesRemaining -=1
print("enemies remaining:", self.enemiesRemaining) print("enemies remaining:", self.enemiesRemaining)
if self.enemiesRemaining <= 0:
game.run == False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment