Esempio n. 1
0
    def newgame(self):
        self.game = Game((156, 104, 128))
        user = Player(self.game.world)
        
        for i in range(20):
            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            self.game.world.space.maketree((x,y,
                                            self.game.world.space.groundlevel(x,y)))

        kind = (Goblin,Tortoise,SmallSpider)

        for i in range(20):
            race = choice(kind)
            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            creature = race(None, (x,y,self.game.world.space.groundlevel(x,y)))
            self.game.schedule(creature)

        for i in range(7):
            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            creature = Dwarf(user, (x,y,self.game.world.space.groundlevel(x,y)))
            self.game.schedule(creature)

            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            loc = x, y, self.game.world.space.groundlevel(x,y)
            handle = Handle(choice(Wood.__subclasses__()), loc)
            blade = PickaxHead(choice(Metal.__subclasses__()), loc)
            self.game.world.additem(handle)
            self.game.world.additem(blade)

            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            loc = x, y, self.game.world.space.groundlevel(x,y)
            handle = Handle(choice(Wood.__subclasses__()), loc)
            blade = AxHead(choice(Metal.__subclasses__()), loc)
            self.game.world.additem(Ax(loc, handle, blade))
                                       

            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            self.game.world.additem(Workbench((x,y,
                                            self.game.world.space.groundlevel(x,y)),
                                           choice(Wood.__subclasses__())))

        for i in range(10):
            x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)]
            self.game.world.additem(Barrel((x,y,
                                            self.game.world.space.groundlevel(x,y)),
                                           choice(Wood.__subclasses__())))

        self.child = Renderer(self.game, user, self.zoom)

        user.foundsettlement('the fortress')
Esempio n. 2
0
def main():
    n = 200000
    m = 200
    
    print 'How fast can a world with {0} items and {1} creatures run.'.format(n, m)

    pygame.init()
    
    game = Game((256,256,128))
    user = Player(game.world)

    for i in range(n):
        game.world.additem(Pickax((randint(0,255),randint(0,255),64),
                                  choice(Metal.__subclasses__()),
                                  choice(Wood.__subclasses__())))

    for i in range(m):
        game.schedule(Dwarf(user, (randint(0,255),randint(0,255),64)))

    display.set_mode((1400,800), HWSURFACE | RESIZABLE)

    renderers = [Renderer(game, user, DisplayOptions('FreeMono.ttf', False, 16, 18))]
    
    game_acc = 0
    render_acc = 0

    last = time()

    while renderers:
        current = time()
        delta = min(0.125, max(0, current - last))

        renderer = renderers[-1]   
        
        if renderer.game:
            game_acc += delta
            while game_acc > renderer.game.dt:
                renderer.game.step()
                game_acc -= renderer.game.dt
            rest = renderer.game.dt - game_acc
        else:
            rest = float('inf')
        
        render_acc += delta
        if render_acc > renderer.dt:
            child = renderer.step()
            if child != renderer:
                if child:
                    renderers.append(child)
                else:
                    renderers = renderers[:-1]
            render_acc = 0

        last = current

        sleep(min(rest, renderers[-1].dt if renderers else 0))
Esempio n. 3
0
 def maketree(self, loc):
     tree = Tree(loc, choice(Wood.__subclasses__()), Leaf)
     
     surround = self.pathing.adjacent_xy(loc[0:2])
     height = randint(6,18)
     branch = None
     for i in range(height):
         trunk = (loc[0], loc[1], loc[2] + i)
         tile = TreeTrunk(tree)
         tree.trunk.append(trunk)
         self.cache[trunk] = tile
         color = tile.color
         if i > 3:
             branch = choice([b for b in surround if b != branch] + [None])
             if branch is not None:
                 varient = -1
                 if branch[0] == loc[0]:
                     if branch[1] == loc[1] - 1:
                         varient = 1 # N
                     else:
                         varient = 0 # S
                 elif branch[0] < loc[0]:
                     if branch[1] == loc[1] + (loc[0]&1):
                         varient = 2 # SW
                     else:
                         varient = 4 # NW
                 else:
                     if branch[1] == loc[1] + (loc[0]&1):
                         varient = 3 # SE
                     else:
                         varient = 5 # NE
                 self.cache[branch + (loc[2]+i,)] = Branch(tree, varient)
                 tree.branches.append(branch + (loc[2]+i,))
         if i > 2:
             available = [s for s in surround
                          if s + (loc[2]+i,) not in self.cache]
             leaves = sample(available, len(available)-1)
             for leaf in leaves:
                 self.cache[leaf + (loc[2]+i,)] = Leaves(tree)
                 tree.leaves.append(leaf + (loc[2]+i,))
     self.cache[loc[0:2] + (loc[2]+height,)] = Leaves(tree)
     tree.leaves.append(loc[0:2] + (loc[2]+height,))