def timerFired(self, dt): if self.mode == "Play": self.timer += 1 if self.timer % 4 == 0: self.roadTimer += 1 if self.timer % 4 == 0: self.runningManTimer += 1 if not (self.isMerge): self.powerupTimer += 1 #POWERUP TIMING if self.powerupTimer % 700 == 0: powerupChoice = random.choice(["magnet", "invinc"]) self.powerupTime = random.randint(550, 700) if powerupChoice == "magnet": self.isMakingMagnets = True self.isMakingInvincs = False else: self.isMakingMagnets = False self.isMakingInvincs = True #AI TIMING if self.powerupTimer % 1000 == 0: self.AITime = random.randint(900, 1000) #COIN WORK if self.timer > 50: if self.isMakingCoins and not (self.isMerge): if len(self.coins) < 1: self.coinLoc = random.choice( ["middle", "left", "right"]) if self.coinLoc == "middle" and not (self.isMerge): initialX = self.middleApex[0] initialY = self.middleApex[1] + 10 dx = 0 dy = 2 for i in range(5): self.coins.add( Coin(initialX + i * dx, initialY + i * dy)) elif self.coinLoc == "left" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = -1.1547005 dy = 2 numCoins = random.randint(5, 8) for i in range(numCoins): self.coins.add( Coin(initialX + i * dx, initialY + i * dy)) elif self.coinLoc == "right" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = 1.1547005 dy = 2 numCoins = random.randint(5, 8) for i in range(numCoins): self.coins.add( Coin(initialX + i * dx, initialY + i * dy)) #dilate the coins for coin in self.coins: if self.coinLoc == "middle": Coin.dilate(coin, self.middleApex) elif self.coinLoc == "left": Coin.dilate(coin, self.leftApex) elif self.coinLoc == "right": Coin.dilate(coin, self.rightApex) #check if it goes out of bounds if coin.y > self.height: if self.isMagnetic: self.score += 1 self.coins.remove(coin) if not self.man.isJump: #can't collect coins while jumping coinsHit = pygame.sprite.spritecollide(self.playerGroup.sprite, self.coins, True) for coin in coinsHit: self.coinSound.play() self.score += 1 #MAGNET WORK if self.timer > 170: if self.isMakingMagnets and not (self.isMerge): if len(self.magnets) < 1: if self.timer % 700 == self.powerupTime: self.magnetLoc = random.choice(["left", "right"]) if self.magnetLoc == "left" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = -1.1547005 dy = 2 self.magnets.add(Magnet(initialX, initialY)) elif self.magnetLoc == "right" and not ( self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = 1.1547005 dy = 2 self.magnets.add(Magnet(initialX, initialY)) #dilate the magnet for magnet in self.magnets: if self.magnetLoc == "left": Magnet.dilate(magnet, self.leftApex) elif self.magnetLoc == "right": Magnet.dilate(magnet, self.rightApex) #check if it goes out of bounds if magnet.y > self.height: self.magnets.remove(magnet) if not self.man.isJump: #can't collect magnets while jumping magnetsHit = pygame.sprite.spritecollide( self.playerGroup.sprite, self.magnets, True) if len(magnetsHit) == 1: self.magnetSound.play() self.isMagnetic = True self.road.color = (0, 0, 200) #magnetic timer if self.isMagnetic: self.magneticTimer += 1 if self.magneticTimer == 250: self.isMagnetic = False self.magneticTimer = 0 self.road.color = (200, 200, 0) #INVINCIBILITY WORK if self.timer > 250: if self.isMakingInvincs and not (self.isMerge): if len(self.invincs) < 1: if self.powerupTimer % 700 == self.powerupTime: self.invincLoc = random.choice(["left", "right"]) if self.invincLoc == "left" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 self.invincs.add(Invinc(initialX, initialY)) elif self.invincLoc == "right" and not ( self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 self.invincs.add(Invinc(initialX, initialY)) #dilate the invinc for invinc in self.invincs: if self.invincLoc == "left": Invinc.dilate(invinc, self.leftApex) elif self.invincLoc == "right": Invinc.dilate(invinc, self.rightApex) #check if it goes out of bounds if invinc.y > self.height: self.invincs.remove(invinc) if not self.man.isJump: #can't collect invincs while jumping invincsHit = pygame.sprite.spritecollide( self.playerGroup.sprite, self.invincs, True) if len(invincsHit) == 1: self.invincSound.play() self.isInvinc = True self.road.color = (200, 0, 0) #invinc timer if self.isInvinc: print(self.invincTimer) self.invincTimer += 1 if self.invincTimer == 250: self.isInvinc = False self.invincTimer = 0 self.invincTime = None self.road.color = (200, 200, 0) #AI WORK if self.timer > 200: if self.isMakingAIs: if len(self.AIs) < 1: if self.powerupTimer % 1000 == self.AITime: self.AILoc = random.choice(["left", "right"]) if self.AILoc == "left": initialX = 477 initialY = 169.207843193097 + 25 self.AIs.add(AI(initialX, initialY)) elif self.AILoc == "right": initialX = 477 initialY = 169.207843193097 + 25 self.AIs.add(AI(initialX, initialY)) #dilate the AI for ai in self.AIs: if self.AILoc == "left": AI.dilate(ai, self.leftApex) elif self.AILoc == "right": AI.dilate(ai, self.rightApex) #check if it goes out of bounds if ai.y > self.height: self.AIs.remove(ai) if not self.man.isJump: #can't collect AIs while jumping AIsHit = pygame.sprite.spritecollide(self.playerGroup.sprite, self.AIs, True) if len(AIsHit) == 1: self.AISound.play() self.isAI = True self.road.color = (124, 252, 0) #AI timer if self.isAI: self.road.color = (124, 252, 0) self.AITimer += 1 if self.AITimer == 1000: self.isAI = False self.AITimer = 0 self.AITime = None self.road.color = (200, 200, 0) #HOLES #generate a hole if self.timer % 500 == 0: self.holeTime = random.randint(300, 499) if self.timer % 500 == self.holeTime and self.isMakingHoles: self.isHolePresent = True self.holes.append(Hole(412, 250)) #dilate the hole if self.isHolePresent: for hole in self.holes: Hole.dilate(hole, self.middleApex) if hole.centerY - hole.height // 2 > self.height: self.isHolePresent = False self.holes = [] #how to die for hole in self.holes: bottom = hole.centerY + hole.height // 2 if self.isAI: if hole.centerY >= self.man.y - 35: #MAYBE STILL USE BOTTOM if not (self.man.shouldJump): self.man.shouldJump = True self.man.shouldJumpIndex = 0 if hole.centerY >= self.man.y and not (self.isAI) and not ( self.isInvinc) and not ( self.man.isJump): #if there's no merge if not (self.isMerge): self.mode = "GameOverNoJump" self.isMagnetic = False self.isInvinc = False self.isAI = False self.holes = [] pygame.mixer.music.stop() elif self.isMerge: if hole.centerY - self.man.y < 60: self.mode = "GameOverNoJump" self.isMagnetic = False self.isInvinc = False self.isAI = False self.holes = [] pygame.mixer.music.stop() #MAKE MERGE if self.timer % 500 == 0: self.mergeTime = random.randint(300, 499) if self.timer % 500 == self.mergeTime: self.isMerge = True if self.isMerge: self.isMakingCoins = False self.isMakingMagnets = False self.isMakingInvincs = False self.isMakingHoles = False if self.road.k == self.height // 4: if self.man.y < 140: self.mode = "GameOverFell" pygame.mixer.music.stop() #reset self.isMerge = False self.isMakingCoins = True self.isMagnetic = False self.isInvinc = False self.isAI = False self.road.k = 5 self.man.x = self.width // 2 self.man.y = 8 * self.height // 10 self.man.updateRect() powerupChoice = random.choice(["magnet", "invinc"]) Game.pickPowerup(self, powerupChoice) elif self.man.y > self.height // 4 - 50: self.man.y -= 5 self.man.updateRect() elif self.road.k < self.height // 4: self.road.k += 1 #MOVE LEFT AND RIGHT if self.isKeyPressed(pygame.K_LEFT) and self.man.left: self.playerGroup.sprite.moveLeft(self.width) #move left if self.isKeyPressed(pygame.K_RIGHT) and self.man.right: self.playerGroup.sprite.moveRight(self.width) #move left #MAKE JUMP if self.man.isJump and not (self.man.left) and not ( self.man.right ): #GLITCH when you click arrow keys too fast if self.man.jumpIndex < len(self.jumpAdd): self.man.y += self.jumpAdd[self.man.jumpIndex] self.man.updateRect() self.man.jumpIndex += 1 elif self.man.jumpIndex >= len(self.jumpAdd): self.man.isJump = False self.gruntJumpLandSound.play() self.man.jumpIndex = 0 self.man.left = True self.man.right = True #AI WORK if self.isAI: if self.isMerge: if self.man.shouldJump: #DON'T click arrow keys too fast/simultaneously if self.man.shouldJumpIndex < len(self.jumpAdd): self.man.y += self.jumpAdd[ self.man.shouldJumpIndex] self.man.shouldJumpIndex += 1 self.man.updateRect() elif self.man.shouldJumpIndex >= len(self.jumpAdd): self.man.shouldJump = False self.man.shouldJumpIndex = 0 self.man.left = True self.man.right = True #get to the middle if 350 < self.man.y < 566: Player.AIgetCoins(self.man, "middle", self.width) elif 140 < self.man.y < 222: self.resetPlay() self.mode = "Play" elif not (self.isMerge): if self.man.shouldJump: #DON'T click arrow keys too fast/simultaneously if self.man.shouldJumpIndex < len(self.jumpAdd): self.man.y += self.jumpAdd[ self.man.shouldJumpIndex] self.man.shouldJumpIndex += 1 self.man.updateRect() elif self.man.shouldJumpIndex >= len(self.jumpAdd): self.man.shouldJump = False self.man.shouldJumpIndex = 0 self.man.left = True self.man.right = True Player.AIgetCoins(self.man, self.coinLoc, self.width)