Exemple #1
0
    def __init__(self, graphic, pos, name, details=None):
        GraphicPositioned.__init__(self, graphic, (0, 0))
        self.pos = pos
        self.graphic = graphic
        self.name = name
        self.details = details

        self.moving = False
        self.dest = None
        self.increments = 10
        self.increments_moved = 1
        self.pixel_increment = self.TILE_OFFSET[0] / self.increments, self.TILE_OFFSET[1] / self.increments
        self.path = None
        self.visible = True

        self.begin_turn_function = None
        self.end_turn_function = None
Exemple #2
0
    def __init__(self, graphic, pos, name, details=None):
        GraphicPositioned.__init__(self, graphic, (0,0))
        self.pos = pos
        self.graphic = graphic
        self.name = name
        self.details = details

        self.moving = False
        self.dest = None
        self.increments = 10
        self.increments_moved = 1
        self.pixel_increment = self.TILE_OFFSET[0]/self.increments, self.TILE_OFFSET[1]/self.increments
        self.path = None
        self.visible = True

        self.begin_turn_function = None
        self.end_turn_function = None
 def setup_ground(self):
     self.ground = Repeated((self.w, self.h), self.TILE_OFFSET,
                            self.ground_tile)
     self.ground = GraphicPositioned(self.ground, (0, 0))
     self.ground.make_visible()
class TouhouMap:
    TILE_OFFSET = (45.0, 30.0)
    TILE_DIMENSIONS = (90.0, 60.0)
    TILE_DATA = (TILE_OFFSET, TILE_DIMENSIONS)

    def __init__(self, size):
        self.obj_list = {}
        self.grid = []
        self.setup_map(size)
        self.ground = None
        self.load_graphics()
        self.generate_constants()

    # Must be called in-game to load data into gpu.
    def load_graphics(self):
        self.ground_tile = Graphic(texture="./content/gfx/sprites/grass.png")
        self.setup_ground()
        for obj in self.obj_list:
            pos = self.obj_list[obj]
            animation = Animated("./content/gfx/sprites/" + obj + ".png",
                                 "./content/metadata/" + obj + ".spr")
            self.place_object(animation, pos, obj)

    def set_ground_tile(self, tile):
        self.ground_tile = tile
        self.setup_ground()

    def setup_ground(self):
        self.ground = Repeated((self.w, self.h), self.TILE_OFFSET,
                               self.ground_tile)
        self.ground = GraphicPositioned(self.ground, (0, 0))
        self.ground.make_visible()

    def setup_map(self, size):
        self.w, self.h = size
        for y in xrange(self.h):
            temp = []
            for x in xrange(self.w):
                temp += [None]
            self.grid += [temp]

    def update_objects(self, e):
        for obj in self.obj_list:
            x, y = self.obj_list[obj]
            self.grid[x][y].update(e)

    def frame_update(self, e):
        for obj in self.obj_list:
            x, y = self.obj_list[obj]
            self.grid[x][y].frame_update(e)

    def draw_ground(self):
        temp = GraphicList()
        temp.add(self.ground)
        return temp

    def draw_sprites(self):
        temp = GraphicList()
        for x in xrange(self.w):
            for y in xrange(self.h):
                if self.grid[self.w - x - 1][self.h - y - 1]:
                    temp.add(self.grid[self.w - x - 1][self.h - y - 1])
        return temp

    def place_object(self, obj, pos, name, details=None):
        temp = MapGraphic(obj, pos, name, details)
        self.grid[pos[0]][pos[1]] = temp
        self.obj_list[name] = pos

    def remove_object(self, target):
        x, y = self.obj_list[target]
        self.grid[x][y] = None
        del self.obj_list[target]

    def update_obj_pos(self, obj):
        x, y = obj.pos
        old_x, old_y = self.obj_list[obj.name]
        self.grid[x][y] = self.grid[old_x][old_y]
        self.grid[old_x][old_y] = None
        self.obj_list[obj.name] = (x, y)

    # Constants we need to calculate mouse position and hovering highlight
    def generate_constants(self):
        off_x, off_y = self.TILE_OFFSET[0], self.TILE_OFFSET[1]
        off_x = float(off_x)
        off_y = float(off_y)
        self.theta_x = atan(off_x / off_y)
        self.theta_y = atan(off_y / off_x)

        #dirty adjustment for highlight precision
        self.hyp = hypot(off_x - 3, off_y - 3)

        self.max_x, self.max_y = self.w * self.hyp, self.h * self.hyp

    def get_square(self, mouse_coords, map_offset):
        x = mouse_coords[0] - map_offset[0] - self.TILE_OFFSET[0]
        y = mouse_coords[1] - map_offset[1]

        new_x = x * cos(self.theta_x) + y * sin(self.theta_x)
        new_y = -x * sin(self.theta_y) + y * cos(self.theta_y)

        if 0 < new_x < self.max_x and 0 < new_y < self.max_y:
            hov_x = int(new_x / self.hyp)
            hov_y = int(new_y / self.hyp)
            return hov_x, hov_y
Exemple #5
0
 def setup_ground(self):
     self.ground = Repeated((self.w, self.h),self.TILE_OFFSET, self.ground_tile)
     self.ground = GraphicPositioned(self.ground, (0,0))
     self.ground.make_visible()
Exemple #6
0
class TouhouMap:
    TILE_OFFSET = (45.0,30.0)
    TILE_DIMENSIONS = (90.0,60.0)
    TILE_DATA = (TILE_OFFSET, TILE_DIMENSIONS)
    def __init__(self, size):
        self.obj_list = {}
        self.grid = []
        self.setup_map(size)
        self.ground = None
        self.load_graphics()
        self.generate_constants()

    # Must be called in-game to load data into gpu.
    def load_graphics(self):
        self.ground_tile = Graphic(texture="./content/gfx/sprites/grass.png")
        self.setup_ground()
        for obj in self.obj_list:
            pos = self.obj_list[obj]
            animation = Animated("./content/gfx/sprites/" + obj + ".png", "./content/metadata/" + obj + ".spr")
            self.place_object(animation, pos, obj)

    def set_ground_tile(self, tile):
        self.ground_tile = tile
        self.setup_ground()

    def setup_ground(self):
        self.ground = Repeated((self.w, self.h),self.TILE_OFFSET, self.ground_tile)
        self.ground = GraphicPositioned(self.ground, (0,0))
        self.ground.make_visible()

    def setup_map(self, size):
        self.w, self.h = size
        for y in xrange(self.h):
            temp = []
            for x in xrange(self.w):
                temp += [None]
            self.grid += [temp]

    def update_objects(self,e):
        for obj in self.obj_list:
            x,y = self.obj_list[obj]
            self.grid[x][y].update(e)

    def frame_update(self, e):
        for obj in self.obj_list:
            x,y = self.obj_list[obj]
            self.grid[x][y].frame_update(e)

    def draw_ground(self):
        temp = GraphicList()
        temp.add(self.ground)
        return temp

    def draw_sprites(self):
        temp = GraphicList()
        for x in xrange(self.w):
            for y in xrange(self.h):
                if self.grid[self.w-x-1][self.h-y-1]:
                    temp.add(self.grid[self.w-x-1][self.h-y-1])
        return temp

    def place_object(self, obj, pos, name, details=None):
        temp = MapGraphic(obj,pos,name,details)
        self.grid[pos[0]][pos[1]] = temp
        self.obj_list[name] = pos

    def remove_object(self, target):
        x, y = self.obj_list[target]
        self.grid[x][y] = None
        del self.obj_list[target]

    def update_obj_pos(self, obj):
        x,y = obj.pos
        old_x,old_y=self.obj_list[obj.name]
        self.grid[x][y] = self.grid[old_x][old_y]
        self.grid[old_x][old_y] = None
        self.obj_list[obj.name] = (x,y)

    # Constants we need to calculate mouse position and hovering highlight
    def generate_constants(self):
        off_x, off_y = self.TILE_OFFSET[0], self.TILE_OFFSET[1]
        off_x = float(off_x)
        off_y = float(off_y)
        self.theta_x = atan(off_x/off_y)
        self.theta_y = atan(off_y/off_x)

        #dirty adjustment for highlight precision
        self.hyp = hypot(off_x-3, off_y-3)

        self.max_x, self.max_y = self.w*self.hyp, self.h*self.hyp

    def get_square(self, mouse_coords, map_offset):
        x = mouse_coords[0]-map_offset[0] - self.TILE_OFFSET[0]
        y = mouse_coords[1]-map_offset[1]

        new_x = x*cos(self.theta_x) + y*sin(self.theta_x)
        new_y = -x*sin(self.theta_y) + y*cos(self.theta_y)

        if 0 < new_x < self.max_x and 0 < new_y < self.max_y:
            hov_x = int(new_x/self.hyp)
            hov_y = int(new_y/self.hyp)
            return hov_x, hov_y