예제 #1
0
def cast_fireball(caster, T_damage_radius_range):

    damage, internal_radius, max_range = T_damage_radius_range
    player_locat = (caster.x, caster.y)

    tile_selected = menu.menu_target_select(coords_origin=player_locat,
                                            range=max_range,
                                            pen_walls=False,
                                            pen_creature=False,
                                            radius=internal_radius)

    tiles_to_damage = maps.map_find_radius(tile_selected, internal_radius)

    creature_hit = False

    for (x, y) in tiles_to_damage:
        creature_to_dmg = maps.map_check_for_creatures(x, y)
        if creature_to_dmg:
            creature_to_dmg.creature.take_damage(damage)
            if creature_to_dmg is not globalvars.PLAYER:
                creature_hit = True

    if creature_hit:
        game.game_message("The fireball f***s shit up hardcore!",
                          constants.COLOR_RED)
예제 #2
0
def cast_confusion(caster, effect_length):
    tile_selected = menu.menu_target_select()
    if tile_selected:
        x, y = tile_selected
        target = maps.map_check_for_creatures(x, y)
        if target:
            oldai = target.ai
            target.ai = ai.ai_Confuse(old_ai=oldai, num_turns=effect_length)
            target.ai.owner = target
            game.game_message(target.display_name + " is confused",
                              constants.COLOR_RED)
예제 #3
0
    def move(self, dx, dy):

        tile_is_wall = (globalvars.GAME.current_map[self.owner.x +
                                                    dx][self.owner.y +
                                                        dy].block_path == True)

        target = maps.map_check_for_creatures(self.owner.x + dx,
                                              self.owner.y + dy, self.owner)

        if target:
            self.attack(target)

        if not tile_is_wall and target is None:
            self.owner.x += dx
            self.owner.y += dy
예제 #4
0
def cast_lightning(caster, T_damage_range):

    player_locat = (caster.x, caster.y)

    damage, m_range = T_damage_range

    tile_selected = menu.menu_target_select(coords_origin=player_locat,
                                            range=m_range,
                                            pen_walls=False)
    if tile_selected:
        list_of_tiles = maps.map_find_line(player_locat, tile_selected)

        for i, (x, y) in enumerate(list_of_tiles):
            target = maps.map_check_for_creatures(x, y)
            if target:
                target.creature.take_damage(damage)
예제 #5
0
def menu_target_select(coords_origin=None,
                       range=None,
                       pen_walls=True,
                       pen_creature=True,
                       radius=None):
    '''This menu lets the player select a tile.

    This function pauses, the game, produces an on screen square and when the player presses the left MB, will return map address.
    '''
    menu_close = False
    while not menu_close:

        mouse_x, mouse_y = pygame.mouse.get_pos()
        events_list = pygame.event.get()

        mapx_pixel, mapy_pixel = globalvars.CAMERA.win_to_map(
            (mouse_x, mouse_y))
        mouse_x_rel = mapx_pixel // constants.CELL_WIDTH
        mouse_y_rel = mapy_pixel // constants.CELL_HEIGHT

        valid_tiles = []
        if coords_origin:
            list_of_tiles = maps.map_find_line(coords_origin,
                                               (mouse_x_rel, mouse_y_rel))
            for i, (x, y) in enumerate(list_of_tiles):
                valid_tiles.append((x, y))
                if range and i == range - 1:
                    break
                if pen_walls == False:
                    if globalvars.GAME.current_map[x][y].block_path: break
                if pen_creature == False and maps.map_check_for_creatures(
                        x, y):
                    break
        else:
            valid_tiles = [(mouse_x_rel, mouse_y_rel)]

        for event in events_list:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_l:
                    menu_close = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    return (valid_tiles[-1])

        globalvars.SURFACE_MAIN.fill(constants.BACKGROUND_COLOR)
        globalvars.SURFACE_MAP.fill(constants.COLOR_BLACK)
        globalvars.CAMERA.update()
        draw.draw_map(globalvars.GAME.current_map)

        for obj in sorted(globalvars.GAME.current_objects,
                          key=lambda obj: obj.depth,
                          reverse=True):
            obj.draw()

        for (tile_x, tile_y) in valid_tiles:
            if (tile_x, tile_y) == valid_tiles[-1]:
                draw.draw_tile_rect((tile_x, tile_y), mark='X')
            draw.draw_tile_rect((tile_x, tile_y))
        if radius:
            area_effect = maps.map_find_radius(valid_tiles[-1], radius)
            for (rad_x, rad_y) in area_effect:
                draw.draw_tile_rect((rad_x, rad_y))

        globalvars.SURFACE_MAIN.blit(globalvars.SURFACE_MAP, (0, 0),
                                     globalvars.CAMERA.rect)
        draw.draw_debug()
        draw.draw_messages()
        pygame.display.flip()
        globalvars.CLOCK.tick(constants.GAME_FPS)