hexbattle /

#!/usr/bin/env python
# encoding: utf-8

"""Unit definitions for hexbattle scenes."""

# standard imports
from os.path import join
from random import choice
from time import time, sleep

# pyglet imports
from pyglet import image, resource, gl
from pyglet.sprite import Sprite as pyglet_sprite

# own stuff
from rpg_1d6.char import Char
# hex functions
from hexgrid import *
from core import Sprite

class Hexfield(Sprite):
    """A simple hexfield element which adheres to the grid.

    TODO: add show_info() which shows an information overlay in the hexfield."""
    def __init__(self, model, image_path=join("graphics", "hex-overlay.png"), x=0, y=0, *args, **kwds): 
        ## Sprite image
        self.model = model
	super(Hexfield, self).__init__(image_path=image_path, x=x, y=y, *args, **kwds)

    def update(self):

    def to_grid_position(self, grid_x, grid_y):
        """Move to a certain place in the grid."""
        self.x, self.y = hexgrid_to_coordinate(grid_x, grid_y)

    def move(self, x, y):
        """Move to the place in the grid which contains the coordinate."""
        grid_x, grid_y = coordinate_to_hexgrid(x, y)
        self.to_grid_position(grid_x, grid_y)

    def move_to_hex(self, x, y):
        self.x, self.y = hexgrid_to_coordinate(x, y)

    def show(self):
        """Become visible."""
        if not self in self.model.visible:

    def hide(self):
        """Become invisible."""
        try: self.model.visible.remove(self)
        except ValueError: pass # not in the visible list.

    def distance(self, sx, sy, tx, ty):
        """Get the distance between this hex and the target."""
        return hexgrid_distance(sx, sy, tx, ty)
    def distance_to(self, target):
        """Get the distance between this hex and the target."""
        return self.distance(self.hex_x, self.hex_y, target.hex_x, target_hex_y)

if __name__ == "__main__":
    # there’s only one reason for calling this file: doctests
    from doctest import testmod
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.