예제 #1
0
    def _Build_Tile(self, x, y, layer, tileType):
        """This is where we are adding a single tile in relation to its position within the chunk to our VertexArray _mesh."""
        #Calculates the position inside of our window where the tile will be placed
        tileXPos = (self._window_Position[0] * config.TILE_SIZE *
                    config.CHUNK_TILES_WIDE) + (config.TILE_SIZE * x)
        tileYPos = (self._window_Position[1] * config.TILE_SIZE *
                    config.CHUNK_TILES_HIGH) + (config.TILE_SIZE * y)

        #Determine the coordinates of the tileType for our tile atlas (TILE_ATLAS_SIZE^2 possible tileTypes) (not working with pixel coords yet)
        textXPos = (tileType - 1) % config.TILE_ATLAS_SIZE
        textYPos = (tileType - 1 - textXPos) / config.TILE_ATLAS_SIZE

        #Normalize the texture positions!
        textXPos *= config.TILE_SIZE
        textYPos *= config.TILE_SIZE

        #Puts the four vertices inside of our vertex Array (represents a single tile quad.)
        self._mesh[layer].append(
            sf.Vertex((tileXPos, tileYPos), sf.Color.WHITE,
                      (textXPos, textYPos)))
        self._mesh[layer].append(
            sf.Vertex((tileXPos, tileYPos + config.TILE_SIZE), sf.Color.WHITE,
                      (textXPos, textYPos + config.TILE_SIZE)))
        self._mesh[layer].append(
            sf.Vertex(
                (tileXPos + config.TILE_SIZE, tileYPos + config.TILE_SIZE),
                sf.Color.WHITE,
                (textXPos + config.TILE_SIZE, textYPos + config.TILE_SIZE)))
        self._mesh[layer].append(
            sf.Vertex((tileXPos + config.TILE_SIZE, tileYPos), sf.Color.WHITE,
                      (textXPos + config.TILE_SIZE, textYPos)))
예제 #2
0
 def draw(self, target, states):
     vertices = [
         sf.Vertex((200, 150), sf.Color.BLACK),
         sf.Vertex((400, 150), sf.Color.RED),
         sf.Vertex((400, 350), sf.Color.BLUE),
         sf.Vertex((200, 350), sf.Color.MAGENTA)
     ]
     target.draw(vertices, sf.TRIANGLES_FAN)
예제 #3
0
 def check_angle_and_range(self):
     ret = False
     own_point = sf.Vertex()
     own_point.position = self.position
     far_point = sf.Vertex()
     far_point.position = (cos(self.rotation) * 100, sin(self.rotation) * 100)
     if check_sight(own_point.position, far_point.position, self.target):
         ret = True
     return ret
예제 #4
0
def Build_Meshes(chunkEntity):
    """We create a mesh here using a VertexArray for a chunk that's on the screen. This only is meant to be for chunk's in relation to their position on the screen.
    Chunks off the screen don't need to have their meshes updated for no reason, but they can still have their data loaded before getting onto the screen."""
    #Makes sure that we have an empty vertex array to add to
    chunkEntity._Get_Component(MESH)._Clear_Meshes()

    windowPos = chunkEntity._Get_Component(CWINDOW_POS)._Get_Position()

    #Handles the building of the tiles within the chunk
    for j in xrange(config.VIEW_TILE_HEIGHT):
        for i in xrange(config.VIEW_TILE_WIDTH):
            #This assumes that depth 0 is the very front of the screen.
            for k in xrange(config.CHUNK_LAYERS):

                if chunkEntity._Get_Component(TILES)[j][i][k]._Get_Is_Active():

                    #Calculates the position inside of our window where the tile will be placed
                    tileXPos = (windowPos[0] + i) * config.TILE_SIZE
                    tileYPos = (windowPos[1] + j) * config.TILE_SIZE

                    #Determine the coordinates of the tileType for our tile atlas (TILE_ATLAS_SIZE^2 possible tileTypes) (not working with pixel coords yet)
                    textXPos = (chunkEntity._Get_Component(TILES)[j][i][k].
                                _Get_Tile_ID() - 1) % config.TILE_ATLAS_SIZE
                    textYPos = (chunkEntity._Get_Component(
                        TILES)[j][i][k]._Get_Tile_ID() - 1 -
                                textXPos) / config.TILE_ATLAS_SIZE

                    #Normalize the texture positions!
                    textXPos *= config.TILE_SIZE
                    textYPos *= config.TILE_SIZE

                    chunkEntity._Get_Component(MESH)._Add_To_Mesh(k, [sf.Vertex( (tileXPos, tileYPos), sf.Color.WHITE, (textXPos, textYPos) ),  \
                                                                      sf.Vertex( (tileXPos, tileYPos+config.TILE_SIZE), sf.Color.WHITE, (textXPos, textYPos+config.TILE_SIZE) ),    \
                                                                      sf.Vertex( (tileXPos+config.TILE_SIZE, tileYPos+config.TILE_SIZE), sf.Color.WHITE, (textXPos+config.TILE_SIZE, textYPos+config.TILE_SIZE) ),  \
                                                                      sf.Vertex( (tileXPos+config.TILE_SIZE, tileYPos), sf.Color.WHITE, (textXPos+config.TILE_SIZE, textYPos) )])

                    ##                    #Puts the four vertices inside of our vertex Array (represents a single tile quad.)
                    ##                    chunkEntity._Get_Component(MESH)._Add_To_Mesh(k, [sf.Vertex( (tileXPos, tileYPos), sf.Color.WHITE), \
                    ##                                                                      sf.Vertex( (tileXPos, tileYPos+config.TILE_SIZE), sf.Color.WHITE),    \
                    ##                                                                      sf.Vertex( (tileXPos+config.TILE_SIZE, tileYPos+config.TILE_SIZE), sf.Color.WHITE),   \
                    ##                                                                      sf.Vertex( (tileXPos+config.TILE_SIZE, tileYPos), sf.Color.WHITE)])
                    ##
                    print "ActiveTile!", tileXPos, tileYPos
                    #If this tile isn't partially see-through, then all tiles behind it are occluded and we don't need to add them to their meshes.
                    if chunkEntity._Get_Component(
                            TILES)[j][i][k]._Get_Is_Solid():
                        #This is confirmed to correctly break out of ONLY the CHUNK_LAYERS loop and still allow the other loops to continue.
                        break
예제 #5
0
    def update(self, sight_blockers):
        # split out pathfinding and sighting functions
        # if player can be seen, and is in range, stop and fire
        # else move towards player along path
        for blocker in sight_blockers:
            while not check_sight(self[0].position, self[1].position, blocker):
                # set old dist as current dist
                olddist = get_distance(self[0].position, self[1].position)
                tx = int(self[1].position.x)
                ty = int(self[1].position.y)

                # setup points to check
                for x in [tx - 5, tx, tx + 5]:
                    for y in [ty - 5, ty, ty + 5]:
                        if not point_rect_intersect(sf.Vector2(x, y),
                                                    blocker.global_bounds):
                            newdist = get_distance(self[0].position,
                                                   sf.Vector2(x, y))
                            if newdist < olddist:
                                olddist = newdist
                                newpos = x, y

                # add newpos to vertex array
                v = sf.Vertex()
                v.position = sf.Vector2(newpos[0], newpos[1])
                v.color = sf.Color.RED

                self.append(self[1])
                self[1] = v

                for i in range(len(self)):
                    print "Point #" + str(i) + ": " + str(
                        self[i].position.x), str(self[i].position.y)
예제 #6
0
def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480), 'SFML vertices example')
    window.framerate_limit = 60
    running = True
    vertices = [
        sf.Vertex((200, 150), sf.Color.RED),
        sf.Vertex((200, 350), sf.Color.BLUE),
        sf.Vertex((400, 350), sf.Color.GREEN),
        sf.Vertex((400, 150), sf.Color.YELLOW)
    ]

    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False

        window.clear(sf.Color.WHITE)
        window.draw(vertices, sf.TRIANGLES)
        window.display()

    window.close()
예제 #7
0
def buildSquare(x, y, w, h, angle, rgb):
    vertices = []

    vertices.append(
        sf.Vertex(
            ((-w / 2) * cos(angle) - (-h / 2) * sin(angle) + x + (w / 2),
             (-h / 2) * cos(angle) + (-w / 2) * sin(angle) + y + (h / 2)),
            sf.Color(rgb[0], rgb[1], rgb[2])))
    vertices.append(
        sf.Vertex(((-w / 2) * cos(angle) - (h / 2) * sin(angle) + x + (w / 2),
                   (h / 2) * cos(angle) + (-w / 2) * sin(angle) + y + (h / 2)),
                  sf.Color(rgb[0], rgb[1], rgb[2])))
    vertices.append(
        sf.Vertex(((w / 2) * cos(angle) - (h / 2) * sin(angle) + x + (w / 2),
                   (h / 2) * cos(angle) + (w / 2) * sin(angle) + y + (h / 2)),
                  sf.Color(rgb[0], rgb[1], rgb[2])))
    vertices.append(
        sf.Vertex(((w / 2) * cos(angle) - (-h / 2) * sin(angle) + x + (w / 2),
                   (-h / 2) * cos(angle) + (w / 2) * sin(angle) + y + (h / 2)),
                  sf.Color(rgb[0], rgb[1], rgb[2])))

    return vertices
예제 #8
0
    def update(self, sight_blockers):
        # split out pathfinding and sighting functions
        # if player can be seen, and is in range, stop and fire
        # else move towards player along path
        for blocker in sight_blockers:
            while not check_sight(self[0].position, self[1].position, blocker):
                # set old dist as current dist
                # olddist = get_distance(self[0].position, self[1].position)
                # bad idea, what if next point is further away?  Still gotta pick it!
                #   Maybe measure line length rather than straight line distance?  If it makes the movement path shorter
                #   move along it
                olddist = None
                tx = int(self[1].position.x)
                ty = int(self[1].position.y)
                pointpos = []
                for v in self:
                    pointpos.append([v.position.x, v.position.y])

                # setup points to check
                for x in [tx - self.step, tx, tx + self.step]:
                    for y in [ty - self.step, ty, ty + self.step]:
                        if x == tx and y == ty or [x, y] in pointpos:
                            continue
                        else:
                            if not point_rect_intersect(
                                    sf.Vector2(x, y), blocker.global_bounds):
                                newdist = get_distance(self[0].position,
                                                       sf.Vector2(x, y))
                                if newdist < olddist or not olddist:
                                    olddist = newdist
                                    newpos = x, y

                # add newpos to vertex array
                v = sf.Vertex()
                v.position = sf.Vector2(newpos[0], newpos[1])
                v.color = sf.Color.RED

                self.append(self[1])
                self[1] = v
예제 #9
0
 def set_end_point(self, p):
     self[1] = sf.Vertex((p.x, p.y), self.color)
예제 #10
0
 def set_start_point(self, p):
     self[0] = sf.Vertex((p.x, p.y), self.color)