Beispiel #1
0
 def rotation_vector(self):
     if self.rotation == "left":
         return utils.Vector(-1, 0)
     elif self.rotation == "right":
         return utils.Vector(1, 0)
     elif self.rotation == "up":
         return utils.Vector(0, -1)
     elif self.rotation == "down":
         return utils.Vector(0, 1)
Beispiel #2
0
 def __init__(self, starting_pos, velocity, filename, direction):
     Thing.__init__(self)
     self.image, self.rect = mediahandler.load_image(
         filename, "projectiles", -1)
     self.rect.topleft = starting_pos
     self.position = pygame.rect.Rect(self.rect)
     self.desired_position = pygame.rect.Rect(self.position)
     self.velocity = utils.Vector(
         velocity if direction != "down" else 0,
         abs(velocity * 1.5) if direction == "down" else 0)
     self.acceleration = utils.Vector(
         0, constants.GRAVITY if direction == "down" else 0)
Beispiel #3
0
 def positions_to_dig(self, coords):
     center = utils.Vector(coords.x, coords.y - 1, coords.z)
     for x in xrange(-5, 6):
         for y in xrange(-5, 6):
             for z in xrange(-5, 6):
                 spow = x**2 + y**2 + z**2
                 if spow > 25:
                     continue
                 state = self.get_state(center.x + x, center.y + y,
                                        center.z + z)
                 if state.can_stand:
                     yield utils.Vector(center.x + x, center.y + y,
                                        center.z + z)
Beispiel #4
0
 def flow_vector(self):
     v = utils.Vector(0, 0, 0)
     this_efd = self.effective_flow_decay
     for i, j in utils.cross:
         blk = self.grid.get_block(self.x + i, self.y, self.z + j)
         efd = blk.effective_flow_decay
         if efd < 0:
             if not blk.material.blocks_movement:
                 blk = self.grid.get_block(self.x + i, self.y - 1,
                                           self.z + j)
                 efd = blk.effective_flow_decay
                 if efd >= 0:
                     va = efd - (this_efd - 8)
                     v = utils.Vector(i * va, 0, j * va)
         elif efd >= 0:
             va = efd - this_efd
             v = utils.Vector(i * va, 0, j * va)
     if self.meta >= 8:
         t = False
         if t or self.is_solid_block(
                 self.grid.get_block(self.x, self.y, self.z - 1), 2):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x, self.y, self.z + 1), 3):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x - 1, self.y, self.z), 4):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x + 1, self.y, self.z), 5):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x, self.y + 1, self.z - 1), 2):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x, self.y + 1, self.z + 1), 3):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x - 1, self.y + 1, self.z), 4):
             t = True
         if t or self.is_solid_block(
                 self.grid.get_block(self.x + 1, self.y + 1, self.z), 5):
             t = True
         if t:
             v.normalize()
             v.y = v.y - 6.0
     v.normalize()
     return v
Beispiel #5
0
 def update(self):
     if self.moving:
         self.xbuf += self.velx
         self.ybuf += self.vely
         self.rect.x, self.rect.y = self.xbuf, self.ybuf
     else:
         self.simple_deal_damage()
     if self.reason is None:
         if self.charged and random.uniform(
                 0, 1) <= self.charged_particle_chance:
             p = particles.Particle.from_sprite(self, 3,
                                                utils.Vector.uniform(1),
                                                50, Color.lBlue)
             self.level.particles.append(p)
     elif random.uniform(0, 1) <= self.particle_chance:
         norm = self.norm_vector
         spread = self.particle_spread
         source_sprite = self
         if self.reason == projectiles.DestroyReason.Collision:
             vel = utils.Vector.random_spread(
                 norm, spread).opposite() * self.particle_speed
         elif self.reason == projectiles.DestroyReason.DamageDeal:
             vel = utils.Vector.uniform(self.particle_speed)
             source_sprite = self.last_attacked_sprite
         else:
             vel = utils.Vector(0, 0)
         p = particles.Particle.from_sprite(source_sprite, 4, vel, 40,
                                            Color.lBlue)
         self.level.particles.append(p)
Beispiel #6
0
 def __init__(self, grid, x, y, z, meta):
     self.grid = grid
     self.x = x
     self.y = y
     self.z = z
     self.meta = meta
     self.coords = utils.Vector(self.x, self.y, self.z)
Beispiel #7
0
 def new_location(self, x, y, z, stance, grounded, yaw, pitch):
     self.bot_object.set_xyz(x, y, z)
     self.bot_object.stance_diff = stance - y
     self.bot_object.on_ground = grounded
     self.bot_object.yaw = yaw
     self.bot_object.pitch = pitch
     self.bot_object.velocities = utils.Vector(0.0, 0.0, 0.0)
     self.check_location_received = True
     if self.location_received is False:
         self.location_received = True
     if not self.in_complete_chunks(self.bot_object):
         log.msg(
             "Server sent me into incomplete chunks, will wait until they load up."
         )
         self.ready = False
Beispiel #8
0
 def __init__(self):
     self.velocities = utils.Vector(0.0, 0.0, 0.0)
     self.direction = utils.Vector2D(0, 0)
     self._x = 0
     self._y = 0
     self._z = 0
     self.stance_diff = config.PLAYER_EYELEVEL
     self.pitch = None
     self.yaw = None
     self.on_ground = False
     self.is_collided_horizontally = False
     self.horizontally_blocked = False
     self.action = 2  # normal
     self._action = self.action
     self.is_jumping = False
     self.hold_position_flag = True
Beispiel #9
0
 def handle_water_movement(self, b_obj):
     is_in_water = False
     water_current = utils.Vector(0, 0, 0)
     bb = b_obj.aabb.expand(-0.001, -0.401, -0.001)
     top_y = utils.grid_shift(bb.max_y + 1)
     for blk in self.world.grid.blocks_in_aabb(bb):
         if isinstance(blk, blocks.BlockWater):
             if top_y >= (blk.y + 1 - blk.height_percent):
                 is_in_water = True
                 water_current = blk.add_velocity_to(water_current)
     if water_current.size > 0:
         water_current.normalize()
         wconst = 0.014
         water_current = water_current * wconst
         b_obj.velocities = b_obj.velocities + water_current
     return is_in_water
Beispiel #10
0
 def __init__(self, grid, x=None, y=None, z=None, vector=None):
     self.grid = grid
     self.x = x
     self.y = y
     self.z = z
     self.coords = utils.Vector(self.x, self.y, self.z)
     self.block_0 = grid.get_block(self.x, self.y - 1, self.z)
     self.block_1 = grid.get_block(self.x, self.y, self.z)
     self.block_2 = grid.get_block(self.x, self.y + 1, self.z)
     self.can_be = self.block_1.can_fall_through and self.block_2.can_fall_through
     self.can_stand = self.block_0.can_stand_on and self.can_be
     self.can_jump = self.can_stand and self.block_1.is_free and self.block_2.is_free
     self.can_fall = self.can_be and self.block_0.can_fall_through
     self.can_climb = self.can_be and self.block_1.is_climbable
     self.in_fire = self.block_1.is_burning or self.block_2.is_burning
     self.in_water = self.block_1.is_water or self.block_2.is_water
     self.can_hold = self.in_water or self.block_1.is_ladder or (
         self.block_1.is_vine and self.block_1.is_climbable)
     self.platform_y = self.y
     self.center_x = self.x + 0.5
     self.center_z = self.z + 0.5
Beispiel #11
0
 def __init__(self, level, pos, *, centerpos=True, source_sprite, target):
     super().__init__(level,
                      pos,
                      centerpos=centerpos,
                      norm_vector=utils.Vector(0, 0))
     self.source_sprite = source_sprite  # It always comes back!
     self.target = target
     self.dist = utils.dist(self.pos, self.target)
     self.surface = self.base_image
     self.length = self.base_length
     self.curve_points = None
     self.curve = self.new_curve()
     self.time_trans = lambda t: utils.translate_to_zero_to_one_bounds(
         t, (0, self.length))
     self.time = 0
     self.rotation = 0
     self.coming_back = False
     self.coming_back_curve = False
     self.hit = set()
     self.act_damage = self.max_damage
     self.last_source_sprite_pos = self.source_sprite.rect.topleft
     self.last_adist = self.dist
Beispiel #12
0
 def update_sign(self, x, y, z, line1, line2, line3, line4):
     sign = Sign(utils.Vector(x, y, z), line1, line2, line3, line4)
     if sign.is_waypoint:
         self.new(sign)
Beispiel #13
0
def render_image(args: Namespace, msg_send: bool = False) -> Tuple[Union[None, str], dict, list, utils.Vector]:
    size = utils.Vector(args.width, args.height)

    starting_point = args.starting_point
    if starting_point is not None:
        # For the user to use the coordinate indexing starting at one
        starting_point = utils.Vector(*[x - 1 for x in args.starting_point])

    color_background = tuple(args.color_background)

    nebula = Nebula(
        size,
        args.max_count,
        args.reproduce_chance,
        quadratic=args.quadratic,
        starting_point=starting_point
    )
    nebula.develop(min_percent=args.min_percent, max_percent=args.max_percent)

    colors = config_colors()

    if args.random_colors:
        colors = utils.random_colors(args.colors_number)
        gradient = utils.gradient(nebula.current_generation, colors)
    elif len(colors) > 1:
        gradient = utils.gradient(nebula.current_generation, colors)

    if args.opaque:
        for color in colors:
            color[3] = 255

    print(c.NOTIFICATION_MSG_BEFORE_RENDERING)
    sleep(1)

    image = Image.new('RGBA', (size.x, size.y))
    draw = ImageDraw.Draw(image)

    for x in range(size.x + 1):
        print(f'[{datetime.now().time()}]', 'Image drawing:', '{:.5f}'.format(x / size.x * 100) + ' %', sep='\t')
        for y in range(size.y + 1):
            if nebula.squares[x][y]:
                if len(colors) == 1:
                    max_gen = nebula.current_generation
                    gen = nebula.squares[x][y].gen

                    alpha = round((1 - gen / max_gen) * 255)
                    if args.fade_in:
                        alpha = round(gen / max_gen * 255)

                    colors[0][3] = alpha

                    draw.point([x, y], fill=tuple(colors[0]))
                else:
                    gen = nebula.squares[x][y].gen - 1
                    draw.point([x, y], fill=gradient[gen])
            else:
                draw.point([x, y], fill=color_background)

    image_name = f'{size.x}x{size.y}_{args.reproduce_chance}_{utils.generate_filename()}.png'
    image_path = None
    if args.save or msg_send:
        if args.path:
            image.save(args.path + image_name, format='PNG', optimize=True, quality=1)
            image_path = args.path + image_name
        elif msg_send:
            image.save(c.TELEGRAM_IMAGES_SAVE_PATH + c.TELERGAM_IMAGE_PREFIX + image_name, 'PNG')
            image_path = c.TELEGRAM_IMAGES_SAVE_PATH + c.TELERGAM_IMAGE_PREFIX + image_name
        else:
            image.save(image_name, 'PNG')
            image_path = image_name
    if args.dont_show_image:
        image.show()

    return image_path, vars(args), colors, nebula.starting_point
Beispiel #14
0
 def position_eyelevel(self):
     return utils.Vector(self.x, self.y_eyelevel, self.z)
Beispiel #15
0
 def position_grid(self):
     return utils.Vector(self.grid_x, self.grid_y, self.grid_z)
Beispiel #16
0
 def position(self):
     return utils.Vector(self.x, self.y, self.z)
Beispiel #17
0
 def position_eyelevel(self):
     return utils.Vector(self.x / 32.0, self.y / 32.0 + config.PLAYER_EYELEVEL, self.z / 32.0)