Esempio n. 1
0
    def on_mouse_release(self, x, y, button, modifiers):
        if button == 4:
            # Right click
            col, row = self.pixel_to_index_coordinates(x, y)
            tile = self.map[row,col]
            position = vecrec.Vector(col, row)

            if tile.terrain == 'land':
                printf('Building City at index {}', position)
                #message = messages.CreateCity(self.gui.player, position)

            else:
                printf('Cannot build city in the {}', tile.terrain)
Esempio n. 2
0
    def draw_map(self):
        for row in range(self.map.rows - 1):
            for col in range(self.map.columns - 1):
                terrains = (
                    self.map.tiles[row + 0, col + 0].terrain, # top left
                    self.map.tiles[row + 1, col + 0].terrain, # bottom left
                    self.map.tiles[row + 1, col + 1].terrain, # bottom right
                    self.map.tiles[row + 0, col + 1].terrain, # top right
                )

                # 4 land

                if terrains == ('land', 'land', 'land', 'land'):
                            # empty, flower,  grass,  grass,  grass
                    indices = (4,1), (4,10), (4,11), (5,10), (5,11)
                    weights =    80,      0,      1,      1,      1
                    index = kxg.tools.weighted_choice(indices, weights)

                # 3 land, 1 sea

                elif terrains == ('land', 'land', 'land', 'sea'):
                    index = 4, 3

                elif terrains == ('land', 'land', 'sea', 'land'):
                    index = 5, 3

                elif terrains == ('land', 'sea', 'land', 'land'):
                    index = 5, 4

                elif terrains == ('sea', 'land', 'land', 'land'):
                    index = 4, 4

                # 2 land, 2 sea

                elif terrains == ('land', 'land', 'sea', 'sea'):
                    index = 4, 2

                elif terrains == ('land', 'sea', 'sea', 'land'):
                    index = 3, 1

                elif terrains == ('sea', 'sea', 'land', 'land'):
                    index = 4, 0

                elif terrains == ('sea', 'land', 'land', 'sea'):
                    index = 5, 1

                # 1 land, 3 sea

                elif terrains == ('land', 'sea', 'sea', 'sea'):
                    index = 3, 2

                elif terrains == ('sea', 'sea', 'sea', 'land'):
                    index = 3, 0

                elif terrains == ('sea', 'sea', 'land', 'sea'):
                    index = 5, 0

                elif terrains == ('sea', 'land', 'sea', 'sea'):
                    index = 5, 2

                # 4 sea

                elif terrains == ('sea', 'sea', 'sea', 'sea'):
                    index = 3, 3

                # Diagonal combinations of 2 land and 2 sea are not supported.  

                else:
                    printf('Unsupported tile at {}x{}', row, col)
                    continue

                x, y = self.get_pixel_coords(col, row)

                # It seems like I have to keep references to all my sprites in 
                # order to keep them from getting garbage collected.

                image = self.tileset[index]
                sprite = pyglet.sprite.Sprite(
                        image, x, y, batch=self.batch, group=self.group)
                self.sprites.append(sprite)