Ejemplo 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')
Ejemplo 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))