def get_rect(self, world_dim, surface):
     r = randint(20, 25)
     w, h = r * 2, r
     if random_sign() == -1:
         left = world_dim[0] // 2 - randint(world_dim[0] // 6 + w,
                                            world_dim[0] // 2)
     else:
         left = world_dim[0] // 2 + randint(world_dim[0] // 6,
                                            world_dim[0] // 2 - w)
     return Rect(left, surface[left] - h, w, h)
Beispiel #2
0
 def on_break(self, pos):
     data = game_vars.get_block_data(pos)
     if data:
         inv = Inventory((1, 1))
         inv.load(data)
         item = inv.get_item(0, 0)
         if item.is_item:
             game_vars.drop_item(DroppedItem(item), c.random_sign(),
                                 [p * BLOCK_W for p in pos])
     game_vars.write_block_data(pos, None)
     return True
Beispiel #3
0
 def on_break(self, pos):
     data = game_vars.get_block_data(pos)
     # There is an item in the pedestal
     if data:
         item = ItemInfo(int.from_bytes(data[:2], byteorder),
                         1,
                         data=data[2:])
         game_vars.drop_item(DroppedItem(item), c.random_sign(), [
             p * BLOCK_W + d * BLOCK_W // 2 for p, d in zip(pos, self.dim)
         ])
         game_vars.write_block_data(pos, None)
     return True
Beispiel #4
0
def fly_random(entity):
    if entity.collisions[1] == 1:
        # Launch off
        entity.a = [0, 0]
        entity.v[1] = -entity.stats.get_stat("jump_speed")
        entity.time = .5
    else:
        if entity.time > 0:
            entity.time -= game_vars.dt
        if entity.time <= 0:
            # Random y acceleration, more likely to go down
            entity.a[1] = entity.stats.get_stat("acceleration") * (
                -1 if randint(1, 5) >= 4 else 1)
            # Random x acceleration
            entity.a[0] = entity.stats.get_stat("acceleration") * random_sign()
            entity.time = uniform(.7, 1.4)
Beispiel #5
0
def jump(entity, follow):
    # If we are on the ground, progress our timer and make sure we aren't moving
    if entity.collisions[1] == 1:
        entity.a[0], entity.v[0] = 0, 0
        entity.time -= game_vars.dt
        # If we are done waiting, jump
        if entity.time <= 0:
            if follow:
                entity.a[0] = math.copysign(
                    entity.stats.get_stat("acceleration"),
                    game_vars.player_pos()[0] - entity.rect.centerx)
            else:
                entity.a[0] = entity.stats.get_stat(
                    "acceleration") * random_sign()
            entity.v[0] = math.copysign(entity.stats.get_stat("max_speedx"),
                                        entity.a[0])
            entity.v[1] = -randint(5, entity.stats.get_stat("jump_speed"))
            entity.time = uniform(1, 2)
 def generate_caves(self, world, rect):
     w, h = world.dim
     num_caves = rect.w * rect.h // self.cave_freq
     # Caves
     for i in range(num_caves):
         x, y = randint(rect.left,
                        rect.right), randint(rect.top, rect.bottom)
         r_x, r_y = randint(*self.cave_w_range), randint(*self.cave_h_range)
         while r_x > 0 and r_y > 0:
             for dx in range(max(-x, -r_x), min(w - x, r_x)):
                 dy = int(math.sqrt(1 - (dx * dx / r_x / r_x)) * r_y)
                 min_y, max_y = y - dy - randint(-1, 1), y + dy + randint(
                     -1, 1)
                 fill_chunk(world.blocks, x + dx, 1, min_y, max_y - min_y,
                            tiles.AIR)
             x += random_sign() * r_x // randint(1, 2)
             y += r_y // randint(1, 2)
             r_x //= 2
             r_y //= 2
Beispiel #7
0
def random_movement(entity):
    entity.time -= game_vars.dt
    # Check if we are standing on the ground
    if entity.collisions[1] == 1:
        # Check if we are ready to start/stop moving
        if entity.time <= 0:
            # We were stopped
            if entity.drag:
                entity.a[0] = entity.stats.get_stat(
                    "acceleration") * random_sign()
                entity.drag = False
                entity.time = uniform(2.5, 5)
            # We were moving
            else:
                entity.a[0] = 0
                entity.drag = True
                entity.time = uniform(1, 3)
        # Check if we need to jump
        if entity.collisions[0] != 0:
            entity.v[1] = -entity.stats.get_stat("jump_speed")
            entity.time = uniform(1, 3)
Beispiel #8
0
 def activate(self, pos):
     item = game_vars.player_inventory().get_current_item()
     data = game_vars.get_block_data(pos)
     # There is an item in the pedestal
     if data and (not item.is_item or item.item_id != i.MAGIC_WAND):
         item = ItemInfo(int.from_bytes(data[:2], byteorder),
                         1,
                         data=data[2:])
         game_vars.drop_item(DroppedItem(item), c.random_sign(), [
             p * BLOCK_W + d * BLOCK_W // 2 for p, d in zip(pos, self.dim)
         ])
         game_vars.write_block_data(pos, None)
         game_vars.player.use_time = .3
         return True
     # There is no item in the pedestal, Make sure we clicked with a magic container item
     elif item.is_item and isinstance(game_vars.items[item.item_id],
                                      ItemTypes.MagicContainer):
         game_vars.write_block_data(
             pos,
             item.item_id.to_bytes(2, byteorder) + item.data)
         item.amnt -= 1
         game_vars.player.use_time = .3
         return True
     return False
Beispiel #9
0
 def on_break(self, pos):
     game_vars.spawn_entity(mobs.Dragon(), [
         p + randint(10, 20) * BLOCK_W * c.random_sign()
         for p in game_vars.player_pos()
     ])
     return False