def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): self.mx,self.my = mouse_position if 1 in buttons: self.buttonon = True else: self.buttonon = False self.onrect = False clock = pygame.time.Clock() self.milliseconds = clock.tick(dynamicConfig.fps) # milliseconds passed since last frame self.seconds = self.milliseconds / 1000.0 self.time -= self.seconds*10 self.time2 -= self.seconds*2 if self.time2 <= 0: self.blonde.x = random.randint(50,630) self.blonde.y = random.randint (20, 200) self.time2 = 1 if self.time <= 0: dynamicConfig.whatGame = dynamicConfig.randGame() dynamicConfig.health -= 1 pygame.mouse.set_visible(True) CON.runGame() if self.blonde.health <=0: dynamicConfig.whatGame = dynamicConfig.randGame() dynamicConfig.score += 50 pygame.mouse.set_visible(True) dynamicConfig.completedGames += 1 CON.runGame() return
def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if pygame.K_a in keys: self.player.moveLeft() if pygame.K_d in keys: self.player.moveRight() if self.player.health <= 0: dynamicConfig.health -= 1 dynamicConfig.whatGame = dynamicConfig.randGame() CON.runGame() clock = pygame.time.Clock() self.milliseconds = clock.tick(dynamicConfig.fps) # milliseconds passed since last frame self.seconds = self.milliseconds / 1000.0 self.player.tick(self.height, self.fieldwidth) if self.milliseconds % 4 == 0 or self.milliseconds % 3 == 0: self.addDrop() self.time -= self.seconds*10 if self.time <= 0: dynamicConfig.whatGame = dynamicConfig.randGame() dynamicConfig.completedGames += 1 dynamicConfig.score += 50* self.player.health self.time = 0.1 CON.runGame() for drop in self.drops: drop.tick(self.height-50) for drop in self.drops: if not drop.alive: continue x,y,h,w = self.player.getDimensions() drop.hitObject(x,y,h,w) if drop.hit == True: drop.setAlive(False) self.player.health -= 1 live_drops = [] for drop in self.drops: if drop.alive: live_drops.append(drop) self.drops = live_drops return
def drawPaused(self,surface): pygame.mouse.set_visible(True) rect = pygame.Surface((self.width,self.height), pygame.SRCALPHA, 32) rect.fill((0, 0, 0, 200)) surface.blit(rect, (0,0)) rect = pygame.Surface((self.width/3,self.height/3+200), pygame.SRCALPHA, 32) rect.fill((0, 0, 0, 200)) surface.blit(rect, (self.width/2-200,150)) label = self.font.render(("Paused"), 1, (255, 255, 0)) surface.blit(label, (self.width/2-100,self.height/3)) rect = pygame.Surface((120,60), pygame.SRCALPHA, 32) if self.hover(self.width/2-105,300,100,50): rect.fill((55, 55, 55, 200)) else: rect.fill((255, 255, 255, 200)) if self.button(self.width/2-105,300,100,50): rect.fill((0, 0, 0, 200)) CON.reset() dynamicConfig.whatGame = 0 dynamicConfig.paused = False CON.runGame() surface.blit(rect, (self.width/2-105,300)) label = self.font.render(("Restart"), 1, (0, 0, 0)) surface.blit(label, (self.width/2-100,self.height/2)) rect = pygame.Surface((120,50), pygame.SRCALPHA, 32) if self.hover(self.width/2-105,400,100,50): rect.fill((55, 55, 55, 200)) else: rect.fill((255, 255, 255, 200)) if self.button(self.width/2-105,400,100,50): rect.fill((0, 0, 0, 200)) dynamicConfig.paused = False surface.blit(rect, (self.width/2-105,400)) label = self.font.render(("Resume"), 1, (0, 0, 0)) surface.blit(label, (self.width/2-100,self.height/2+100)) return
def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((55,55,55),rect ) label = self.font.render("Games Completed: "+str(dynamicConfig.completedGames), 1, (255, 255, 0)) surface.blit(label, (self.width/2-200,self.height/3)) label = self.font.render("Score: "+str(dynamicConfig.score), 1, (255, 255, 0)) surface.blit(label, (self.width/2-100,self.height/2)) rect= pygame.Rect(self.width/2-50,self.height/2+100,80,60) x,y,w,h = rect if self.hover(x,y,w,h)==True: surface.fill((100,100,100),rect ) else: surface.fill((155,155,155),rect ) if self.button(x, y, w, h): dynamicConfig.whatGame = dynamicConfig.randGame() CON.reset() CON.runGame() return
def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if 1 in newbuttons: self.buttonon = True else: self.buttonon = False if dynamicConfig.whatGame != 0: if pygame.K_ESCAPE in newkeys: dynamicConfig.paused = not dynamicConfig.paused if pygame.K_1 in newkeys: dynamicConfig.whatGame = 0 CON.runGame() if pygame.K_2 in newkeys: dynamicConfig.whatGame = 1 CON.runGame() if pygame.K_3 in newkeys: dynamicConfig.whatGame = 2 CON.runGame() if pygame.K_4 in newkeys: dynamicConfig.whatGame = 3 CON.runGame() if dynamicConfig.health <= 0: dynamicConfig.whatGame = 99 dynamicConfig.health = .1 CON.runGame() clock = pygame.time.Clock() milliseconds = clock.tick(dynamicConfig.fps) # milliseconds passed since last frame seconds = milliseconds / 1000.0 dynamicConfig.fps = CON.FPS + dynamicConfig.completedGames return
def draw(self, surface): background = pygame.image.load("starsbackground.png").convert() surface.blit(background, (0, 0)) myfont = self.font lable = myfont.render("Code Camp Stories", 1, (255, 255, 0)) surface.blit(lable, (370, 155)) button = pygame.image.load("Pressedplaybutton.png").convert() button2 = pygame.image.load("Playbutton.png").convert() rect = pygame.Rect(450, 350, 100, 50) surface.fill((255, 255, 255), rect) mx, my = pygame.mouse.get_pos() x, y, w, h = rect if self.hover(mx, my, x, y, w, h): surface.blit(button, (x, y)) else: surface.blit(button2, (x, y)) if self.button(mx, my, x, y, w, h) == True: dynamicConfig.whatGame = dynamicConfig.randGame() CON.runGame() return