def __animateUp(self): #print("ANIMATING UP") print("CurrentIndex: ", self.currentFrameIndex, " TotalFrames: ", len( self.frames ) ) if (self.currentFrameIndex < len( self.frames ) - 1 ): self.currentFrameIndex += 1 print("New Index", self.currentFrameIndex) def __animateDown(self): #print("ANIMATING DOwn") if (self.currentFrameIndex > 0 ): self.currentFrameIndex -=1 def __updateAnimationState(self): #print("UPDATE ANIMATION STATE") if( self.currentFrameIndex == 0 ): self.status = self.INACTIVE elif( self.currentFrameIndex >= len( self.frames )-1 ): self.status = self.GOING_DOWN if __name__ == "__main__": import scene from scene import Scene from Girl import Girl game = Scene() buford = Buford() buford.setImage("buford.gif") girl = Girl() girl.setImage("girl.png"); game.sprites = [buford, girl] game.start()
class BufordSave(Scene): def __init__(self): Scene.__init__(self) self.screne = pygame.display.set_mode((450, 480)) self.background.fill( (210,210,210) ) background = Grass() self.girl = Girl() self.girl.setImage("girl.png") self.girl.x = 20 self.girl.y = 25 self.buford = Buford() self.buford.setImage("buford.gif") self.buford.x = self.girl.x + self.girl.width + 20 self.buford.y = self.girl.y + self.girl.height + 28 self.girl.setFollowingSprite(self.buford) self.sprites = [background, self.girl, self.buford] neebCount = 4 self.neebSprites = [] change= 50 for x in range(neebCount): print("Making a neeb", change) self.neebSprites.append( ChasingNeeb() ) self.neebSprites[x].setImage("neeb_still.gif") self.neebSprites[x].x = 0 + change self.neebSprites[x].y = 0 self.sprites.append(self.neebSprites[x]) change += 10 self.neebGroup = Scene.makeSpriteGroup( self, self.neebSprites ) #print( gameShared.distance(self.girl.x, self.girl.y, self.neebSprites[0].x, self.neebSprites[0].y) ) self.girlScareDistance = 190 self.neebScareDistance = 100 def update(self): #print("UPDATING") isScared = False for neebSprite in self.neebSprites: # Handles the neeb walking towards the girl neebSprite.walkTimer+= 1 if neebSprite.walkTimer >= neebSprite.walkSpeed_: neebSprite.walkTowardsGirl(self.girl) neebSprite.walkTimer = 0 # Upadtes the girl if the neebs get too close if( self.isNeebNearGirl(neebSprite) ): isScared = True # Handles the case when buford gets close to a neeb isBufordClose = self.isNeebCloseToBufford(neebSprite) neebSprite.setIsBufordClose(isBufordClose) if isBufordClose: print("HE IS CLOSE!!!!") self.buford.status = self.buford.CHASING neebSprite.runAwayFromBuford(self.buford) #Update the girl if she is scared self.girl.setScared(isScared) def isNeebNearGirl(self, neeb): distance = shared.distance(self.girl.x, self.girl.y, neeb.x, neeb.y) #print("Current Distance: ", distance) return ( distance < self.girlScareDistance ) def isNeebCloseToBufford(self, neeb): distance = shared.distance(self.buford.x, self.buford.y, neeb.x, neeb.y) return ( distance < self.neebScareDistance )