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

FINAL final push

parent a94fec03
......@@ -17,8 +17,6 @@ class Bandit(pygame.sprite.Sprite):
self.image.set_colorkey(WHITE) #set transparency to white
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.y = randint(0, window_height-self.rect.width)
#self.rect.x = randint(0, window_height-self.rect.width)
self.speed = speedAI
self.playerRef = player
self.observer = observer
......@@ -66,7 +64,6 @@ class Bandit(pygame.sprite.Sprite):
if totalDiff < self.rect.width and otherBandit.playerDist() < self.playerDist():
self.stopped = True
self.stoppedTimer = time.time()
print("STOPPED")
if self.stopped and time.time() > self.stoppedTimer + self.stopWaitLength:
self.stopped = False
......
......@@ -28,9 +28,11 @@ rightPressed = False
bulletFired = False
bulletFiredTime = 0
bulletFireRate = 0.333
gameWon = False
gameLost = False
# pygame.mixer.music.load('music.mp3')
# pygame.mixer.music.play(-1)
pygame.mixer.music.load('music.mp3')
pygame.mixer.music.play(-1)
pygame.display.set_caption("Cowboy Shooter")
screenSize = (window_width, window_height)
......@@ -71,29 +73,9 @@ spriteGroupWall.add(wallBotRightVer)
player = Cowboy(window_width, window_height, speed)
observer = ai_observer(maxBandits)
#bandit1 = Bandit(player, window_height, window_width, speedAI)
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)
#-------------------------------------------------------------
#BULLETS
#-------------------------------------------------------------
upCollide = False
downCollide = False
leftCollide = False
......@@ -187,12 +169,16 @@ while run is True:
if time.time() > bulletFiredTime + bulletFireRate:
bulletFired = False
if(enemiesOnScreen <5):
enemiesOnScreen += 1
b = Bandit(player, window_height, window_width, speedAI, observer,spriteGroupAI, spriteGroupWall, enemiesOnScreen)
spriteGroupAI.add(b)
else:
pass;
if not observer.gameWon and not gameLost:
if(enemiesOnScreen <5):
enemiesOnScreen += 1
b = Bandit(player, window_height, window_width, speedAI, observer,spriteGroupAI, spriteGroupWall, enemiesOnScreen)
spriteGroupAI.add(b)
else:
pass;
elif enemiesOnScreen <=0 and not gameLost:
winText = font.render("GAME WON", True, (0,0,0))
screen.blit(winText, (350,350))
#-------------------------------------------------------------
#COLLISIONS
......@@ -204,7 +190,8 @@ while run is True:
observer.notify_enemy_died()
enemiesOnScreen -=1
if(player.health <=0):
run = False
gameLost = True
#run = False
for b in spriteGroupAI:
......@@ -213,23 +200,6 @@ while run is True:
b.kill()
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
bulletHitBandit = pygame.sprite.groupcollide(spriteGroupBullet, spriteGroupAI, True, True)
if bulletHitBandit:
......@@ -248,17 +218,26 @@ while run is True:
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()
spriteGroupBullet.update()
spriteGroup.draw(screen)
spriteGroupAI.draw(screen)
if not gameLost:
spriteGroup.update(window_width, window_height) #calls all the update functions in all sprites
spriteGroupAI.update()
spriteGroup.draw(screen)
spriteGroupAI.draw(screen)
spriteGroupWall.draw(screen)
spriteGroupBullet.draw(screen)
screen.blit(enemiesLeftText, (5,5))
screen.blit(healthText, (575,3))
if gameLost:
lostText = font.render("YOU LOSE", True, (0,0,0))
screen.blit(lostText, (350,350))
pygame.display.flip()
......@@ -4,10 +4,13 @@ class ai_observer():
def __init__(self, maxBandits):
self.enemiesRemaining = maxBandits
self.gameWon = False
def notify_enemy_died(self):
self.enemiesRemaining -=1
print("enemies remaining:", self.enemiesRemaining)
if self.enemiesRemaining <= 0:
game.run == False
self.gameWon = True
else:
self.enemiesRemaining -=1
print("enemies remaining:", self.enemiesRemaining)
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