def rightLeftHaz(screen,player): global hazardCounter, knifeCycle, game_over, hazardWarningTime, hazardRecedTime if hazardCounter > 0: if hazardCounter < time_bottomUpHaz: depth = screen_width- (((screen_width/2)/time_bottomUpHaz) * hazardCounter) elif hazardCounter <= time_bottomUpHaz + hazardWaitTime: depth = screen_width/2 else: depth = screen_width-(screen_width/2-(((screen_width/2)/time_bottomUpHaz)*hazardRecedTime)) hazardRecedTime +=1 pygame.draw.rect(screen, colors.SOFT_RED, [depth,menu_height,screen_width,screen_height]) if hazardCounter % 10 == 0 and hazardCounter > 0: if player.rect.x+10 > depth: player.kill() game_over = True for sprite in Lists.Enemy_list: if sprite.rect.x > depth: sprite.kill() Lists.startAnimateTimes_list.append(pygame.time.get_ticks()) Lists.pointFade_List.append(sprite.rect.y) Lists.pointFade_List.append(sprite.rect.x) if knifeCycle == 40: knifeCycle =0 else: knifeCycle += 4 knifeSpacing = menu_height -20 while knifeSpacing < menu_height + screen_height: pygame.draw.polygon(screen,colors.SOFT_RED,[[depth-10,knifeSpacing+10+knifeCycle],[depth,knifeSpacing+20+knifeCycle],[depth,knifeSpacing+knifeCycle]]) knifeSpacing += 20 hazardCounter += 1
def leftRightHaz(screen,player): global hazardCounter, knifeCycle, game_over, hazardWarningTime, hazardRecedTime if hazardCounter > 0: if hazardCounter < time_bottomUpHaz: depth = ((screen_width/2)/time_bottomUpHaz) * hazardCounter elif hazardCounter <= time_bottomUpHaz + hazardWaitTime: depth = screen_width/2 else: depth = screen_width/2-(((screen_width/2)/time_bottomUpHaz)*hazardRecedTime) hazardRecedTime +=1 pygame.draw.rect(screen, colors.SOFT_RED, [0,menu_height,depth,screen_height]) if hazardCounter % 10 == 0 and hazardCounter > 0: if player.rect.x < depth: player.kill() game_over = True for sprite in Lists.Enemy_list: if sprite.rect.x < depth: sprite.kill() if knifeCycle == 40: knifeCycle =0 else: knifeCycle += 4 knifeSpacing = menu_height -20 while knifeSpacing < menu_height + screen_height: pygame.draw.polygon(screen,colors.SOFT_RED,[[depth+10,knifeSpacing+10+knifeCycle],[depth,knifeSpacing+20+knifeCycle],[depth,knifeSpacing+knifeCycle]]) knifeSpacing += 20 hazardCounter += 1
def bottomUpHaz(screen,player): global hazardCounter, knifeCycle, game_over, hazardWarningTime, hazardRecedTime if hazardCounter < time_bottomUpHaz: depth = menu_height+screen_height-(((screen_height/2)/time_bottomUpHaz) * hazardCounter) elif hazardCounter <= time_bottomUpHaz + hazardWaitTime: depth = menu_height+screen_height/2 else: depth = menu_height+screen_height/2+(((screen_height/2)/time_bottomUpHaz)*hazardRecedTime) hazardRecedTime +=1 pygame.draw.rect(screen, colors.SOFT_RED, [0,depth,screen_width,menu_height+screen_height/2]) if hazardCounter % 10 == 0 and hazardCounter > 0: if player.rect.y+12 > depth: player.kill() game_over = True for sprite in Lists.Enemy_list: if sprite.rect.y+10 > depth: sprite.kill() hazardCounter += 1 if knifeCycle == 40: knifeCycle =0 else: knifeCycle += 4 knifeSpacing = -40 while knifeSpacing < screen_width: pygame.draw.polygon(screen,colors.SOFT_RED,[[knifeSpacing+10+knifeCycle,depth-10],[knifeSpacing+20+knifeCycle,depth],[knifeSpacing+knifeCycle,depth]]) knifeSpacing += 20
def checkBombKill(self, position): for player in self.players: if (player.reborn == 0 and player.position == position): player.kill() for e in self.enemyGroup: if e.position == position: self.enemyGroup.remove(e) # kill enemy + 1000 return True
def game(score_state): # No sound. :( #pygame.mixer.pre_init(44100,8,4,1024) pygame.init() pygame.font.init() #pygame.mixer.music.set_volume(2.0) # if pygame.mixer.music.get_busy(): # pass # else: # musicfile = data.filepath('midi','bumblbee.mid') # pygame.mixer.music.load(musicfile) # pygame.mixer.music.play(-1) screen = pygame.display.set_mode(SCREENRECT.size) clock = pygame.time.Clock() background = pygame.image.load(data.filepath('images/new_background.png')).convert() level = Level() tornadoes = pygame.sprite.Group() houses = pygame.sprite.Group() player = pygame.sprite.Group() rays = pygame.sprite.Group() lightnings = pygame.sprite.Group() all = pygame.sprite.OrderedUpdates() titles = pygame.sprite.Group() statuses = pygame.sprite.Group() scores = pygame.sprite.Group() sparks = pygame.sprite.Group() start_new_game = False Score.containers = all Status.containers = all Title.containers = all Tornado.containers = tornadoes,all House.containers = houses,all Ray.containers = rays,all Lightning.containers = lightnings,all Score.containers = all Spark.containers = all Status.containers = all Player.containers = all screen.blit(background,(0,0)) pygame.display.flip() # Title Screen score = Score(score_state) status_pause = 0 first_time = True while start_new_game == False: status_pause = status_pause + 1 if (first_time): title_text = "Twisted Twister!" Title(title_text,(0,0,0)) Title(title_text,(255,0,0)) Title(title_text,(0,255,255)) Title(title_text,(0,255,0)) Title(title_text,(0,0,255)) first_time = False for event in pygame.event.get(): if event.type == QUIT: sys.exit() if event.type == MOUSEBUTTONDOWN: start_new_game = True if event.type == KEYDOWN: if event.key == K_ESCAPE: sys.exit() else: start_new_game = True if status_pause > 100: Status ("Press any key to start...") status_pause = 0 all.clear(screen,background) all.update() dirty = all.draw(screen) pygame.display.update(dirty) clock.tick(30) kill_objects(all) house_container = [] # Stuff to do to start the game #for i in range(100,800,150): for i in range(0,5): house_container.append(House(((i*150)+100,500))) # Reset the level level.start() # Start the scoreboard score = Score(score_state) # Populate the screen with the actors fujita = start_game(level) player = Player((400,550)) # Lights! Camera! Silence on the set! playing = True bonus_house = 0 last_bonus = 0 bonus_at = 10000 # Cameras rolling... # 3...2...1... Action! while playing: active = True lightning_counter = 0 Status("Level %d, %s spotted!" % (level.get_level(), 'F' + str(fujita) + 's')) if (bonus_house > 0): for t in range(0,5): if (house_container[t].is_alive() == False): if (bonus_house >= 1): house_container[t].set_alive() bonus_house = bonus_house - 1 while active: lightning_counter = lightning_counter + 1 if lightning_counter > min(300,10000 - (level.get_level() * 200)): Lightning(player.get_position()) lightning_counter = 0 for event in pygame.event.get(): if event.type == QUIT: sys.exit() if event.type == KEYDOWN: # Put in an escape key / Q key handler if event.key == K_ESCAPE: active = False playing = False if event.key == K_LEFT: player.left() if event.key == K_RIGHT: player.right() if event.key == K_LCTRL or event.key == K_RCTRL: player.fire() if event.type == KEYUP: if event.key == K_LEFT: player.stop() if event.key == K_RIGHT: player.stop() pass tornado_house_collide = pygame.sprite.groupcollide(houses,tornadoes,False,False) if (tornado_house_collide): for house in (tornado_house_collide): for tornado in (tornado_house_collide[house]): if (house.is_alive()): tornado.rise() house.rise(tornado.get_fujita()) tornado_ray_collide = pygame.sprite.groupcollide(tornadoes,rays,False,False) if (tornado_ray_collide): for tornado in (tornado_ray_collide): tornado.hit(score) if (not tornadoes.sprites()): active = False lightning_player_collide = pygame.sprite.spritecollide(player,lightnings,False) if (lightning_player_collide): player.hit() Spark(player.get_midtop_position()) if (score.get_score() >= (last_bonus + bonus_at)): bonus_house = bonus_house + 1 # Should return the last score at 10,000 increments last_bonus = (score.get_score() / 1000) * 1000 Status("Bonus!") all.clear(screen,background) all.update() dirty = all.draw(screen) pygame.display.update(dirty) clock.tick(30) # Reset for the next level if playing: level.next_level() player.kill() fujita = start_game(level) player = Player((400,550)) lightning_counter = 0 houses_alive = False for i in range(0,5): house_container[i].restoration() houses_alive = houses_alive or house_container[i].is_alive() if (houses_alive or bonus_house > 0): playing = True active = True else: active = False playing = False score_state = score.get_score_state() kill_objects(all) return (score_state)
def start(min, max): global running global space global player global text global countdown global sprites global round_text global count_up global round_count global max_vel global timer while (running == True): #---adds the background and user to the screen--- screen.blit(space, (0, 0)) screen.blit(letters.render(text, True, (255, 255, 255)), (32, 48)) screen.blit(font.render(round_text, True, (255, 255, 255)), (width / 2, 48)) for event in pygame.event.get(): #---this will end the game--- if event.type == KEYDOWN: if event.key == K_ESCAPE: running = False if event.key == new_lazer: pew = lazer.lazer() pew.rect = pew.surf.get_rect(center=(player.rect.left + 40, player.rect.top)) lazers.add(pew) sprites.add(pew) if event.type == pygame.QUIT: running = False pygame.quit() #---countdown--- if event.type == pygame.USEREVENT: temp = countdown countdown -= 1 text = (str(countdown).rjust(3)) count_up += 1 #---every ten seconds, the asteroidsas speed up--- if countdown == 0: round_count = round_count + 1 temp = str(round_count) round_text = (str('Round: ' + temp).rjust(3)) min = min * 1.25 max = max * 1.5 countdown = 10 #---Create the new asteroid peroidically--- elif event.type == new_asteroid: new_enemy = asteroid.asteroid() new_enemy.speed = random.randint(int(min), int(max)) asteroids.add(new_enemy) sprites.add(new_enemy) #---checks which key is pressed and performs a task--- keys = pygame.key.get_pressed() player.movePlayer(keys) #---Runs and adds objects to the screen--- for things in sprites: screen.blit(things.surf, things.rect) for lz in lazers: screen.blit(lz.surf, lz.rect) #---when a player and asteroids collide the game ends--- if pygame.sprite.spritecollideany(player, asteroids): player.kill() running = False for l in lazers: if pygame.sprite.spritecollideany(l, asteroids): for a in asteroids: if pygame.sprite.spritecollideany(a, lazers): l.kill() a.kill() #---this makes the asteroids move--- asteroids.update() lazers.update() #---updates the screen--- pygame.display.flip() leaderboard(count_up)