def lost(self): self.game_over = True self.lives = " NO LIVES" if android: self.text_messages.append( widgets.TextMessage( self.screen_getter(), " Play again? Y/n", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2 - 120), duration=9999999, size=32, initialdelay=9999990)) android.show_keyboard() else: self.text_messages.append( widgets.TextMessage(self.screen_getter(), " Play again? Y/n", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=9999999, size=32, initialdelay=9999990)) self.add_to_highscore()
def create_powerup(self, pos): available_powerups = [ ExtraLife(self.extralife_image_getter, pos, ResourceCapsule(self.resource_manager, "fn_add_life")), ExtraPoint( self.extrapoint_image_getter, pos, ResourceCapsule(self.resource_manager, "fn_add_extrapoint")), ExtraBall(self.extraball_image_getter, pos, ResourceCapsule(self.resource_manager, "fn_add_ball")), TimeDistortionField( self.time_distortion_powerup_image_getter, pos, ResourceCapsule(self.resource_manager, "fn_activate_time_distortion_field")), DoubleDamage( self.double_damage_image_getter, pos, ResourceCapsule(self.resource_manager, "fn_double_damage")) ] chosen_powerup = random.choice(available_powerups) self.powerups.add(chosen_powerup) self.text_messages.append( widgets.TextMessage(self.screen_getter(), chosen_powerup.name + " spawned!", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1200, size=32, initialdelay=1100))
def __init__(self, screen, game, init_position=None, init_direction=(1, 1)): Creep.__init__(self, screen, game, init_position, init_direction) self.name = "Armored Zombie Boss" self.health_init *= 40 self.health *= 40 self.speed = random.randint(63, 64)/1000. self.gold = 6*40 self.damage = 5 self.game.text_messages.append(widgets.TextMessage(self.game.screen, "A boss has spawned!", vec2d(self.game.screen.get_width() / 2, self.screen.get_height() / 2), duration=3800, size=32, initialdelay=800, color=Color("darkgreen")))
def level_complete(self): self.waiting_for_level = True self.collect_all_score() if self.level < self.available_levels: pygame.time.set_timer(self.WAIT_NEW_LEVEL, 1800) self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Level Complete!", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1800, size=32, initialdelay=800)) else: if android: self.text_messages.append( widgets.TextMessage( self.screen_getter(), "Congratulations! You beat all " + str(self.available_levels) + " levels. Play again? Y/n", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2 - 120), duration=9999999, size=24, initialdelay=9999990)) android.show_keyboard() else: self.text_messages.append( widgets.TextMessage( self.screen_getter(), "Congratulations! You beat all " + str(self.available_levels) + " levels. Play again? Y/n", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=9999999, size=24, initialdelay=9999990)) self.add_to_highscore() self.game_over = True
def add_extrapoint(self): for ball in self.balls: ball.combo += 100 self.text_messages.append( widgets.TextMessage(self.screen_getter(), "You got 100 XP!", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1800, size=32, initialdelay=800))
def add_life(self): if (self.lives < 5): self.lives += 1 self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Extra Life Added!", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1800, size=32, initialdelay=800)) self.lives_surface_getter = ResourceCapsule( self.resource_manager, "livesfont_" + str(self.lives)) else: self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Max Lives Allowed!", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1800, size=32, initialdelay=800))
def sell(self): sellamount = int(round(0.75 * self.cost)) self.game.money += sellamount self.game.text_messages.append( widgets.TextMessage(self.game.screen, 'Sold! ' + '+' + str(sellamount), vec2d(self.pos[0], self.pos[1] - 22), duration=3100, size=23, initialdelay=800)) self.game.selection_info_active = False for extra_tile_y in range(int( self.heightbycoord)): #Block all occupied tiles for extra_tile_x in range(int(self.widthbycoord)): self.game.gridpath.set_blocked( (self.coordx_topleft + extra_tile_x, self.coordy_topleft + extra_tile_y), blocked=False) self.kill()
def dropped_balls(self): self.erase_rect( self.screen_getter(), Rect((168, 88, self.livesfont_getter().size(str(self.lives))[0], self.livesfont_getter().size(str(self.lives))[1]))) self.lives -= 1 if self.lives > 0: self.add_ball() self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Press SPACE to begin", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1800, size=32, initialdelay=800)) else: self.lost() self.lives_surface_getter = ResourceCapsule( self.resource_manager, "livesfont_" + str(self.lives))
def _compute_direction(self, time_passed): """ Finds out where to go """ coord = self.game.xy2coord(self.pos) if self.game.is_goal_coord(coord): self._slaycitizen() #Removes a life and dies else: x_mid, y_mid = self.game.coord2xy_mid(coord) if ((x_mid - self.pos.x) * (x_mid - self.prev_pos.x) < 0 or (y_mid - self.pos.y) * (y_mid - self.prev_pos.y) < 0): success = False for n in range(0, 900): try: next_coord = self.game.next_on_path(coord) self.direction = vec2d( next_coord[1] - coord[1], next_coord[0] - coord[0]).normalized() break #PATH okay! except: self.game.lookup_tower(self.game.last_placed_tower_id - n).sell() self.game.text_messages.append(widgets.TextMessage(self.game.screen, "Don't entirely block the path!", vec2d(self.game.screen.get_width() / 2, self.game.screen.get_height() / 2), duration=3800, size=32, initialdelay=1000, color=Color("red")))
def _slaycitizen(self): self.game.text_messages.append(widgets.TextMessage(self.screen, "Leak!", self.pos, duration=2000, size=14, initialdelay=400, color=(245,15,15))) self.game.leaks += self.damage self.game.lives -= self.damage self.kill()
def _die(self): self.state = Creep.DEAD self.game.kills += 1 self.game.money += self.gold self.game.text_messages.append(widgets.TextMessage(self.game.screen, '+'+str(self.gold), vec2d(self.pos[0], self.pos[1]-22), duration=1100, size=15)) self.kill()
def load_level(self, level): self.time_passed_this_level = 0 b = len(self.balls) if b > 0: remaining_balls = b else: remaining_balls = 1 self.balls.empty() self.powerups.empty() self.blocks.empty() self.invulnerable_blocks.empty() self.balls_on_paddle = 0 for ball in range(remaining_balls): self.add_ball() if android: self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Touch to begin level " + str(level), Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=2800, size=24, initialdelay=1200)) else: self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Press SPACE to begin level " + str(level), Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=2800, size=24, initialdelay=1200)) if level <= self.available_levels: self.level = level level_data = open(os.path.join('levels', str(level) + ".lvl"), 'r') i = 0 for row in level_data: row = row.split() for j in range(25): if self.is_int(row[j]): if int(row[j]) != 0: self.blocks.add( Block((LEFT_BOUND + BLOCK_SIZE[0] * j, BLOCK_SIZE[1] * i), abs(int(row[j])), ResourceCapsule(self.resource_manager, "fn_create_powerup"), self.resource_manager, invisible=int(row[j]) < 0)) elif row[j] == "*" or row[j] == "-*": #invulnerable block! self.invulnerable_blocks.add( Block((LEFT_BOUND + BLOCK_SIZE[0] * j, BLOCK_SIZE[1] * i), 1, ResourceCapsule(self.resource_manager, "fn_create_powerup"), self.resource_manager, invulnerable=True, invisible=row[j][0] == "-")) i += 1 level_data.close() else: self.load_level(level - 1)