コード例 #1
0
ファイル: enemy.py プロジェクト: krp/pynasour
    def update(self):
        if Player.getState() == "IDLE":
            return
        # update pos, velocity, interval
        self.updateVelAndIntrvl()
        if pyxel.frame_count % 2:
            for i in range(len(self.pos)):
                self.pos[i] = Vec(self.pos[i].x + self.velocity.x,
                                  self.pos[i].y)

        # 左端についたら右端に戻す
        for i in range(self.ENEMY_NUM):
            if self.pos[i].x < -50:
                # reset pos
                interval = random.randrange(self.MIN_INTERVAL,
                                            self.MAX_INTERVAL)
                spawn_x = max(self.pos[i - 1].x, self.SPAWN_POS)
                self.pos[i] = Vec(spawn_x + interval, self.GND_HEIGHT)

                # select cactus or ptera at random
                if random.random() < self.PTERA_SPAWN_RATIO:  # ptera
                    self.cur_anim[i] = Enemy.PTERA_ANIMs[0]
                    self.pos[i].y -= 40 * random.randrange(0, 2)
                else:  # cactus
                    self.cur_anim[i] = Enemy.CACTUS_ANIMs[random.randrange(
                        0, 2)]

        if self.collideWithPlayer():
            Player.beGameover()
コード例 #2
0
ファイル: enemy.py プロジェクト: krp/pynasour
    def initialize(self):
        self.cloud_velocity = Vec(self.INIT_VELOCITY_X // 4, 0)
        self.gnd_velocity = Vec(self.INIT_VELOCITY_X,
                                0)  # same with enemy's velocity
        # cloud pos(list)
        self.cloud_pos = deepcopy(self.CLOUD_INIT_POS)

        # ground pos(list)
        self.gnd_pos = deepcopy(self.GND_INIT_POS)
コード例 #3
0
ファイル: hall_traps.py プロジェクト: DrakDragon/mcdungeon
 def __init__(self, parent, position, size, length, direction):
     self.parent = parent
     self.position = position
     self.size = size
     self.length = length
     self.direction = direction
     # Set delta width and length vectors based on halleasy direction.
     if direction == dirs.E:
         self.dl = Vec(1, 0, 0)
         self.dw = Vec(0, 0, 1)
     else:
         self.dl = Vec(0, 0, 1)
         self.dw = Vec(1, 0, 0)
コード例 #4
0
ファイル: enemy.py プロジェクト: krp/pynasour
 def updateVelAndIntrvl(self):
     # TODO: adjast the coefs
     dif = (Score.getScore() // 100)
     vel_x = self.INIT_VELOCITY_X - dif
     self.velocity = Vec(vel_x, 0)
     self.MIN_INTERVAL = 85 + 15 * dif
     self.MAX_INTERVAL = 150 + 15 * dif
コード例 #5
0
ファイル: enemy.py プロジェクト: krp/pynasour
    def initialize(self):
        self.velocity = Vec(Enemy.INIT_VELOCITY_X, 0)
        interval = random.randrange(self.MIN_INTERVAL, self.MAX_INTERVAL)
        self.INIT_POS = [
            Vec(self.SPAWN_POS + i * self.MAX_INTERVAL + interval,
                self.GND_HEIGHT) for i in range(self.ENEMY_NUM)
        ]

        self.cur_anim = [None] * self.ENEMY_NUM
        self.pos = deepcopy(self.INIT_POS)
        # enemy is cactus or ptera
        for i in range(self.ENEMY_NUM):
            if random.random() < self.PTERA_SPAWN_RATIO:  # ptera
                self.cur_anim[i] = Enemy.PTERA_ANIMs[0]
                self.pos[i].y -= 40 * random.randrange(0, 2)
            else:  # big or small Cactus
                self.cur_anim[i] = Enemy.CACTUS_ANIMs[random.randrange(0, 2)]
コード例 #6
0
ファイル: hall_traps.py プロジェクト: DrakDragon/mcdungeon
 def apply_template(self, tmpl, cmds, mat, reps, pos):
     '''
     Apply a template.
     tmpl = the actual template
     mat = materials lookup
     reps for each template row
     pos = starting position
     '''
     for l in xrange(len(tmpl[0])):
         for rl in xrange(reps['l'][l]):
             for d in xrange(len(tmpl)):
                 repw = 0
                 for w in xrange(len(tmpl[d][l])):
                     for rw in xrange(reps['w'][w]):
                         q = pos + self.dw * repw \
                                 + Vec(0, -1, 0) * d
                         repw += 1
                         if tmpl[d][l][w] == 'XX':
                             continue
                         elif tmpl[d][l][w] == '~T':
                             if random.randint(1, 100) <= 90:
                                 self.parent.setblock(
                                     q,
                                     materials.RedstoneWire,
                                     hide=True
                                 )
                             else:
                                 self.parent.setblock(
                                     q,
                                     materials.TNT,
                                     hide=True
                                 )
                             continue
                         elif (
                             tmpl[d][l][w][0] == '~' and
                             random.randint(1, 100) <= 50
                         ):
                             continue
                         self.parent.setblock(
                             q,
                             mat[tmpl[d][l][w]][0],
                             mat[tmpl[d][l][w]][1],
                             hide=True
                         )
                         if tmpl[d][l][w] in cmds:
                             self.parent.addtileentity(
                                 get_tile_entity_tags(
                                     eid='Control',
                                     Pos=q,
                                     Command=cmds[tmpl[d][l][w]]
                                 )
                             )
             pos += self.dl
コード例 #7
0
ファイル: enemy.py プロジェクト: krp/pynasour
    def update(self):
        if Player.getState() == "IDLE":
            return
        # update velocity, pos
        self.updateVel()
        if pyxel.frame_count % 2:
            for i in range(len(self.cloud_pos)):
                self.cloud_pos[i] = Vec(
                    self.cloud_pos[i].x + self.cloud_velocity.x,
                    self.cloud_pos[i].y)
            for i in range(len(self.gnd_pos)):
                self.gnd_pos[i] = Vec(self.gnd_pos[i].x + self.gnd_velocity.x,
                                      self.gnd_pos[i].y)

        # 左端についたら右端に戻す
        # lastに合わせて距離を保つ
        for i in range(len(self.cloud_pos)):
            if self.cloud_pos[i].x < -50:
                self.cloud_pos[i] = Vec(self.CLOUD_INIT_POS[-1].x,
                                        self.cloud_pos[i].y)
        for i in range(len(self.gnd_pos)):
            if self.gnd_pos[i].x < -120:
                self.gnd_pos[i] = Vec(self.GND_INIT_POS[-1].x,
                                      self.gnd_pos[i].y)
コード例 #8
0
ファイル: mapstore.py プロジェクト: zangles/mcdungeon
    def generate_map(self, dungeon, level):
        '''Generate a new map, save it to disk, flush the cache, and return a
        map item NBT with the appropriate map ID.'''

        dungeon_key = '%s,%s' % (dungeon.position.x, dungeon.position.z)
        if dungeon_key not in self.mapcache['used']:
            self.mapcache['used'][dungeon_key] = set([])

        # Find a map id. Look in the available list for old mcdungeon maps
        # that can be reused. If not, bump up the idcount and use that.
        if len(self.mapcache['available']) == 0:
            # Initialize the map count if it doesn't exist.
            if 'map' not in self.idcounts:
                self.idcounts['map'] = nbt.TAG_Short(-1)

            self.idcounts['map'].value += 1
            mapid = self.idcounts['map'].value
            self.mapcache['used'][dungeon_key].add(mapid)
        else:
            mapid = self.mapcache['available'].pop()
            self.mapcache['used'][dungeon_key].add(mapid)
        filename = os.path.join(self.mapstore, 'map_%d.dat' % (mapid))

        # Setup the defaults.
        # Offset will be way off somewhere were players are unlikely to go
        # to avoid the maps from being overwritten. Nothing else really
        # matters.
        tags = nbt.TAG_Compound()
        tags['data'] = nbt.TAG_Compound()
        tags['data']['scale'] = nbt.TAG_Byte(0)
        tags['data']['xCenter'] = nbt.TAG_Int(-12500000)
        tags['data']['zCenter'] = nbt.TAG_Int(-12500000)
        tags['data']['height'] = nbt.TAG_Short(128)
        tags['data']['width'] = nbt.TAG_Short(128)
        tags['data']['dimension'] = nbt.TAG_Byte(0)
        tags['data']['colors'] = nbt.TAG_Byte_Array(zeros(16384, uint8))

        # Generate the map.
        blocks = dungeon.blocks
        colors = tags['data']['colors'].value
        y = level * dungeon.room_height - 3
        # Scale the map. We only scale up, not down since scaling
        # looks terrible.
        max_dungeon = max(dungeon.xsize * dungeon.room_size,
                          dungeon.zsize * dungeon.room_size)
        max_dungeon = max(128, max_dungeon)

        # If the size is less than 8, try to center it.
        xoffset = 0
        zoffset = 0
        if dungeon.xsize * dungeon.room_size < 128:
            xoffset = (128 - dungeon.xsize * dungeon.room_size) / 2
        if dungeon.zsize * dungeon.room_size < 128:
            zoffset = (128 - dungeon.zsize * dungeon.room_size) / 2

        # Draw pixels on the map corresponding to blocks just above
        # floor level. Color chests and spawners. Hide things that should be
        # hidden.
        for x in xrange(128):
            for z in xrange(128):
                block = Vec(x * max_dungeon / 128 - xoffset, y,
                            z * max_dungeon / 128 - zoffset)
                if block in blocks:
                    mat = blocks[block].material
                    if mat == materials.StonePressurePlate:
                        colors[x + z * 128] = 10
                    elif blocks[block].hide is True:
                        colors[x + z * 128] = 0
                    elif blocks[block].blank is True:
                        colors[x + z * 128] = 0
                    elif mat == materials.Air:
                        colors[x + z * 128] = 10
                    elif mat == materials.Spawner:
                        colors[x + z * 128] = 48
                    elif (mat == materials.Chest
                          or mat == materials.TrappedChest):
                        colors[x + z * 128] = 42
                    else:
                        colors[x + z * 128] = 54
                else:
                    colors[x + z * 128] = 0

        # Draw the level number in the corner
        digits = [[0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0],
                  [0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1],
                  [1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1],
                  [1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0],
                  [1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1],
                  [1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1],
                  [0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1],
                  [1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0],
                  [1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1],
                  [1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1]]
        sx = 120
        if level < 10:
            sx = 124
        sz = 123
        for d in str(level):
            for x in xrange(3):
                for z in xrange(5):
                    if digits[int(d)][x + z * 3] == 1:
                        colors[x + sx + (z + sz) * 128] = 16
            sx += 4

        # Save the map file, cache, and idcount.dat
        tags.save(filename)
        self.update_mapstore()

        # Return a map item
        item = nbt.TAG_Compound()
        item['id'] = nbt.TAG_String(items.byName('map').id)
        item['Damage'] = nbt.TAG_Short(mapid)
        item['Count'] = nbt.TAG_Byte(1)
        item['tag'] = nbt.TAG_Compound()
        item['tag']['display'] = nbt.TAG_Compound()
        name = dungeon.dungeon_name + ' Lv {l}'
        item['tag']['display']['Name'] = nbt.TAG_String(name.format(l=level))
        item['tag']['display']['MapColor'] = nbt.TAG_Int(self.mapcolor)
        print item['tag']['display']['Name'].value

        return item
コード例 #9
0
ファイル: hall_traps.py プロジェクト: DrakDragon/mcdungeon
import inspect
import random
import sys

import cfg
import materials
from utils import (
    Vec,
    enum,
    iterate_cube,
    get_tile_entity_tags,
    weighted_choice
)

dv = [
    Vec(0, -1, 0),
    Vec(1, 0, 0),
    Vec(0, 1, 0),
    Vec(-1, 0, 0)
]
dirs = enum('N', 'E', 'S', 'W')


class Blank(object):
    _name = 'blank'
    _min_width = 0
    _max_width = 32
    _min_length = 0
    _max_length = 32

    def __init__(self, parent, position, size, length, direction):
コード例 #10
0
treasure_SpawnMaxNearbyEntities = 0
treasure_SpawnMinDelay = 0
treasure_SpawnMaxDelay = 0
treasure_SpawnRequiredPlayerRange = 0
chest_traps = '3'
sand_traps = '40'
skeleton_balconies = '25'
fill_caves = 'False'
torches_position = 3
hall_piston_traps = 75
resetting_hall_pistons = 'True'
secret_rooms = '75'
silverfish = '0'
maps = '0'
mapstore = ''
portal_exit = Vec(0, 0, 0)
dungeon_name = None
river_biomes = [7, 11]
ocean_biomes = [0, 10, 24]

master_halls = []
master_hall_traps = []
master_rooms = []
master_srooms = []
master_features = []
master_stairwells = []
master_floors = []
master_ruins = [('blank', 1)]
default_entrances = []
master_entrances = {}
master_treasure = [('pitwitharchers', 1)]
コード例 #11
0
 def __init__(self):
     self.loc = Vec(0, 0, 0)
     self.material = None
     self.direction = 0
     self.doors = []
コード例 #12
0
    def render(self):
        if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4):
            return
        color_profile = random.choice(self.colors)

        min_x = utils.floor(min([p.x for p in self.parent.canvas]))
        max_x = utils.ceil(max([p.x for p in self.parent.canvas]))
        min_z = utils.floor(min([p.z for p in self.parent.canvas]))
        max_z = utils.ceil(max([p.z for p in self.parent.canvas]))
        min_y = utils.floor(min([p.y for p in self.parent.canvas]))

        # Cut the canvas into quarters and fill one quarter with colors.
        # Then, copy that quarter into the other three quarters.
        width = utils.floor(((max_x - min_x + 1) + 1) / 2)
        depth = utils.floor(((max_z - min_z + 1) + 1) / 2)

        points = [[-1 for j in xrange(depth)] for i in xrange(width)]
        points_left = []
        for i in xrange(width):
            for j in xrange(depth):
                points_left.append((i, j))
        bounds = utils.Box(Vec(0, 0, 0), width, 1, depth)
        p = Vec(0, 0, 0)
        color_num = 0
        prev_dir = random.randint(0, 3)
        next_dir = random.randint(0, 3)
        while len(points_left) > 0:
            # pick random starting point and walk around the matrix
            point_index = random.randint(0, len(points_left) - 1)
            p = Vec(points_left[point_index][0], 0,
                    points_left[point_index][1])

            while (bounds.containsPoint(p) and points[p.x][p.z] == -1
                   and len(points_left) > 0):
                points[p.x][p.z] = color_num
                points_left.remove((p.x, p.z))

                # pick random direction to walk, try to keep walking same
                # direction
                if random.randint(0, self._walk_weight) != 0:
                    next_dir = prev_dir
                else:
                    while next_dir == prev_dir:
                        next_dir = random.randint(0, 3)
                if next_dir == 0:  # right
                    p += Vec(1, 0, 0)
                elif next_dir == 1:  # down
                    p += Vec(0, 0, 1)
                elif next_dir == 2:  # left
                    p += Vec(-1, 0, 0)
                else:  # up
                    p += Vec(0, 0, -1)
                prev_dir = next_dir
            color_num = (color_num + 1) % len(color_profile)

        for j in xrange(max_z - min_z + 1):
            for i in xrange(max_x - min_x + 1):
                p = self.parent.loc + Vec(min_x + i, min_y, min_z + j)
                self.parent.parent.setblock(p, self.mat)
                if i < width:
                    i_adj = i
                else:
                    i_adj = 2 * width - 1 - i
                if j < depth:
                    j_adj = j
                else:
                    j_adj = 2 * depth - 1 - j
                self.parent.parent.blocks[p].data = \
                    color_profile[points[i_adj][j_adj]]
        # Ruined
        if (self.ruin):
            self.ruinrender()
コード例 #13
0
ファイル: enemy.py プロジェクト: krp/pynasour
 def updateVel(self):
     # TODO: adjast the coefs
     dif = (Score.getScore() // 100)
     vel_x = self.INIT_VELOCITY_X - dif
     self.velocity = Vec(vel_x, 0)
コード例 #14
0
ファイル: enemy.py プロジェクト: krp/pynasour
class BackGround:
    # === CLASS VARIABLES ===
    IMG_ID = 0
    # cloud
    CLOUD_W, CLOUD_H = 48, 16
    CLOUD_normal = Rect(0, 80, CLOUD_W, CLOUD_H, COLKEY)
    CLOUD_INIT_POS = [Vec(280, 26), Vec(400, 16), Vec(550, 30)]

    # Ground
    GND_W, GND_H = 128, 16
    GND_normal = Rect(0, 128, GND_W, GND_H)
    GND_INIT_POS = [Vec(0, 88), Vec(GND_W, 88), Vec(2 * GND_W, 88)]

    INIT_VELOCITY_X = -4

    def __init__(self):
        self.initialize()
        self.showInfo()

    def initialize(self):
        self.cloud_velocity = Vec(self.INIT_VELOCITY_X // 4, 0)
        self.gnd_velocity = Vec(self.INIT_VELOCITY_X,
                                0)  # same with enemy's velocity
        # cloud pos(list)
        self.cloud_pos = deepcopy(self.CLOUD_INIT_POS)

        # ground pos(list)
        self.gnd_pos = deepcopy(self.GND_INIT_POS)

    def showInfo(self):
        pass

    def update(self):
        if Player.getState() == "IDLE":
            return
        # update velocity, pos
        self.updateVel()
        if pyxel.frame_count % 2:
            for i in range(len(self.cloud_pos)):
                self.cloud_pos[i] = Vec(
                    self.cloud_pos[i].x + self.cloud_velocity.x,
                    self.cloud_pos[i].y)
            for i in range(len(self.gnd_pos)):
                self.gnd_pos[i] = Vec(self.gnd_pos[i].x + self.gnd_velocity.x,
                                      self.gnd_pos[i].y)

        # 左端についたら右端に戻す
        # lastに合わせて距離を保つ
        for i in range(len(self.cloud_pos)):
            if self.cloud_pos[i].x < -50:
                self.cloud_pos[i] = Vec(self.CLOUD_INIT_POS[-1].x,
                                        self.cloud_pos[i].y)
        for i in range(len(self.gnd_pos)):
            if self.gnd_pos[i].x < -120:
                self.gnd_pos[i] = Vec(self.GND_INIT_POS[-1].x,
                                      self.gnd_pos[i].y)

    def blt(self):
        for i, pos in enumerate(self.cloud_pos):
            pyxel.blt(pos.x, pos.y, BackGround.IMG_ID,
                      *BackGround.CLOUD_normal.getRect())
        for i, pos in enumerate(self.gnd_pos):
            pyxel.blt(pos.x, pos.y, BackGround.IMG_ID,
                      *BackGround.GND_normal.getRect())

    def updateVel(self):
        # TODO: adjast the coefs
        dif = (Score.getScore() // 100)
        vel_x = self.INIT_VELOCITY_X - dif
        self.velocity = Vec(vel_x, 0)
コード例 #15
0
    def render(self):
        if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4):
            return
        color_profile = random.choice(self.colors)

        min_x = utils.floor(min([p.x for p in self.parent.canvas]))
        max_x = utils.ceil(max([p.x for p in self.parent.canvas]))
        min_z = utils.floor(min([p.z for p in self.parent.canvas]))
        max_z = utils.ceil(max([p.z for p in self.parent.canvas]))
        min_y = utils.floor(min([p.y for p in self.parent.canvas]))

        # Cut the canvas into quarters and fill one quarter with colors.
        # Then, copy that quarter into the other three quarters.
        width = utils.floor(((max_x - min_x + 1) + 1) / 2)
        depth = utils.floor(((max_z - min_z + 1) + 1) / 2)

        points = [[-1 for j in xrange(depth)] for i in xrange(width)]
        points_left = []
        for i in xrange(width):
            for j in xrange(depth):
                points_left.append((i, j))
        bounds = utils.Box(Vec(0, 0, 0), width, 1, depth)
        p = Vec(0, 0, 0)
        color_num = 0
        prev_dir = random.randint(0, 3)
        next_dir = random.randint(0, 3)
        while len(points_left) > 0:
            # pick random starting point and walk around the matrix
            point_index = random.randint(0, len(points_left) - 1)
            p = Vec(points_left[point_index][0], 0,
                    points_left[point_index][1])

            while (bounds.containsPoint(p) and points[p.x][p.z] == -1
                   and len(points_left) > 0):
                points[p.x][p.z] = color_num
                points_left.remove((p.x, p.z))

                # pick random direction to walk, try to keep walking same
                # direction
                if random.randint(0, self._walk_weight) != 0:
                    next_dir = prev_dir
                else:
                    while next_dir == prev_dir:
                        next_dir = random.randint(0, 3)
                if next_dir == 0:  # right
                    p += Vec(1, 0, 0)
                elif next_dir == 1:  # down
                    p += Vec(0, 0, 1)
                elif next_dir == 2:  # left
                    p += Vec(-1, 0, 0)
                else:  # up
                    p += Vec(0, 0, -1)
                prev_dir = next_dir
            color_num = (color_num + 1) % len(color_profile)

        for j in xrange(max_z - min_z + 1):
            for i in xrange(max_x - min_x + 1):
                p = self.parent.loc + Vec(min_x + i, min_y, min_z + j)
                self.parent.parent.setblock(p, self.mat)
                if i < width:
                    i_adj = i
                else:
                    i_adj = 2 * width - 1 - i
                if j < depth:
                    j_adj = j
                else:
                    j_adj = 2 * depth - 1 - j
                self.parent.parent.blocks[p].data = \
                    color_profile[points[i_adj][j_adj]]

        if not self.ruin:
            return
        # this chunk of code is copied from CheckerRug's render() method
        pn = perlin.SimplexNoise(256)
        c = self.parent.canvasCenter()
        y = self.parent.canvasHeight()
        r = random.randint(1, 1000)
        maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength())
        for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
            p = x + self.parent.loc
            d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
            n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
            if (n < d):
                self.parent.parent.setblock(p, materials._floor)
                self.parent.parent.blocks[p].data = 0
コード例 #16
0
 def render(self):
     pn = perlin.SimplexNoise(256)
     # Find all the valid halls. These are halls with a size > 0.
     # We'll store a random position within the range of the hall.
     halls = [0, 0, 0, 0]
     hallcount = 0
     wires = set()
     #wirehooks = set()
     for h in xrange(4):
         if (self.parent.halls[h].size > 0):
             halls[h] = \
                 self.parent.halls[h].offset + 1 + \
                 random.randint(0, self.parent.halls[h].size - 3)
             hallcount += 1
     # We won't draw just half a bridge, unless this is a sandpit. (yet)
     if (hallcount < 2 and self.sandpit is False):
         return
     midpoint = self.parent.parent.room_size / 2
     y = self.parent.canvasHeight()
     offset = self.parent.loc
     # Look for the X bounds between halls.
     if (halls[0] != 0 and halls[2] != 0):
         x1 = halls[0]
         x2 = halls[2]
     elif (halls[0] != 0):
         x1 = halls[0]
         x2 = x1
     elif (halls[2] != 0):
         x2 = halls[2]
         x1 = x2
     else:
         x1 = midpoint
         x2 = midpoint
     # Look for the Z bounds between halls.
     if (halls[1] != 0 and halls[3] != 0):
         z1 = halls[1]
         z2 = halls[3]
     elif (halls[1] != 0):
         z1 = halls[1]
         z2 = z1
     elif (halls[3] != 0):
         z2 = halls[3]
         z1 = z2
     else:
         z1 = midpoint
         z2 = midpoint
     # Now construct our points.
     # c1-4 are the corners of the connecting
     # box. h0-3 are the start points of the halls.
     c1 = Vec(x1, y, z1)
     c2 = Vec(x2, y, z1)
     c3 = Vec(x2, y, z2)
     c4 = Vec(x1, y, z2)
     h0 = Vec(x1, y, self.parent.hallLength[0])
     h1 = Vec(self.parent.parent.room_size - self.parent.hallLength[1] - 1,
              y, z1)
     h2 = Vec(x2, y,
              self.parent.parent.room_size - self.parent.hallLength[2] - 1)
     h3 = Vec(self.parent.hallLength[3], y, z2)
     # Sandpit?
     mat = random.choice(self.slabtypes)
     if (self.sandpit is True):
         # Draw the false sand floor
         mat = materials.Sand
         c = self.parent.canvasCenter()
         y = self.parent.canvasHeight()
         r = random.randint(1, 1000)
         maxd = max(1, self.parent.canvasWidth(),
                    self.parent.canvasLength())
         for x in utils.iterate_points_inside_flat_poly(
                 *self.parent.canvas):
             p = x + self.parent.loc
             d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
             n = (pn.noise3(
                 (p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
             if (n >= d + .10):
                 self.parent.parent.setblock(p, materials.Sand)
             elif (n >= d):
                 self.parent.parent.setblock(p, materials.Gravel)
             else:
                 self.parent.parent.setblock(p, materials._floor)
         # Find wire locations
         # h0
         # Cool fact: in 12w30c tripwires will trigger sand without hooks.
         if (halls[0] != 0):
             for x in xrange(1, self.parent.halls[0].size - 1):
                 p = Vec(self.parent.halls[0].offset + x, y - 1,
                         self.parent.hallLength[0])
                 # if x == 0:
                 #    wirehooks.add((p, 4+3))
                 # elif x == self.parent.halls[0].size-1:
                 #    wirehooks.add((p, 4+1))
                 # else:
                 #    wires.add(p)
                 wires.add(p)
         # h1
         if (halls[1] != 0):
             for x in xrange(1, self.parent.halls[1].size - 1):
                 wires.add(
                     Vec((self.parent.parent.room_size -
                          self.parent.hallLength[1] - 1), y - 1,
                         self.parent.halls[1].offset + x))
         # h2
         if (halls[2] != 0):
             for x in xrange(1, self.parent.halls[2].size - 1):
                 wires.add(
                     Vec(self.parent.halls[2].offset + x, y - 1,
                         (self.parent.parent.room_size -
                          self.parent.hallLength[2] - 1)))
         # h3
         if (halls[3] != 0):
             for x in xrange(1, self.parent.halls[3].size - 1):
                 wires.add(
                     Vec(self.parent.hallLength[3], y - 1,
                         self.parent.halls[3].offset + x))
         for p in wires:
             self.parent.parent.setblock(offset + p.down(1),
                                         materials.Gravel,
                                         lock=True)
             self.parent.parent.setblock(offset + p,
                                         materials.Tripwire,
                                         hide=True)
         # for p in wirehooks:
         #    self.parent.parent.setblock(offset+p[0].down(1), mat)
         #    self.parent.parent.setblock(offset+p[0],
         #                                materials.TripwireHook, p[1])
     # Draw the bridges, if a hallway exists.
     # h0 -> c1
     # h1 -> c2
     # h2 -> c3
     # h3 -> c4
     if (halls[0] != 0):
         for p in utils.iterate_cube(offset + h0, offset + c1):
             self.parent.parent.setblock(p, mat)
     if (halls[1] != 0):
         for p in utils.iterate_cube(offset + h1, offset + c2):
             self.parent.parent.setblock(p, mat)
     if (halls[2] != 0):
         for p in utils.iterate_cube(offset + h2, offset + c3):
             self.parent.parent.setblock(p, mat)
     if (halls[3] != 0):
         for p in utils.iterate_cube(offset + h3, offset + c4):
             self.parent.parent.setblock(p, mat)
     # Draw the connecting bridges.
     # c1 -> c2
     # c2 -> c3
     # c3 -> c4
     for p in utils.iterate_cube(offset + c1, offset + c2):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c2, offset + c3):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c3, offset + c4):
         self.parent.parent.setblock(p, mat)
コード例 #17
0
import inspect
import random
import sys

import cfg
import materials
from utils import (Vec, enum, iterate_cube, get_tile_entity_tags,
                   weighted_choice)

dv = [Vec(0, -1, 0), Vec(1, 0, 0), Vec(0, 1, 0), Vec(-1, 0, 0)]
dirs = enum('N', 'E', 'S', 'W')


class Blank(object):
    _name = 'blank'
    _min_width = 0
    _max_width = 32
    _min_length = 0
    _max_length = 32

    def __init__(self, parent, position, size, length, direction):
        self.parent = parent
        self.position = position
        self.size = size
        self.length = length
        self.direction = direction
        # Set delta width and length vectors based on halleasy direction.
        if direction == dirs.E:
            self.dl = Vec(1, 0, 0)
            self.dw = Vec(0, 0, 1)
        else: