示例#1
0
 def setDirections(self):
     a = utils.angleToRad(self.facingAngle)
     ap = utils.angleToRad(self.facingAngle + FOV)
     am = utils.angleToRad(self.facingAngle - FOV)
     self.facingDirection = Vector2(cos(a), sin(a))
     self.fovRight = Vector2(cos(ap), sin(ap))
     self.fovLeft = Vector2(cos(am), sin(am))
     x, y = self.facingDirection.toTuple()
     self.strafeDirection = Vector2(-y, x)
示例#2
0
 def __init__(self, x, y):
     self.position = Vector2(x, y)
     self.facingAngle = 0  #45*pi/180
     self.movingDirection = Vector2(0, 0)
     self.movingSpeed = 100
     self.turningSpeed = 360 / 1.0  #degrees / second (ex. 1 full rotation in 3 seconds)
     #self.fovAngle = 45 #Field of View angle from the facingAngle direction
     #self.fovAngle_rads = utils.angleToRad(FOV)
     self.fovRight = Vector2()  #Right-edge field of view
     self.fovLeft = Vector2()  #Left-edge field of view
     self.setDirections()
    def getTestSector(self):
        '''From the testsectors file.  Press button 5'''
        L = testsectors.sector5()
        print(L)
        self.segments = []
        for pair in L:
            v1 = Vector2(pair[0])
            v2 = Vector2(pair[1])
            self.segments.append(Segment(v1, v2, name=pair[2]))

        self.bsp = BSP(self.segments)
        self.bsp.createTree()
示例#4
0
    def defineGrid(self):
        '''Defines vertical and horizontal lines'''
        #Define vertical lines
        for i in range(NCOLS):
            self.grid.append(
                Line(Vector2(i * TILEWIDTH, 0),
                     Vector2(i * TILEWIDTH, SCREENHEIGHT), GRAY))

        #Define horizontal lines
        for i in range(NROWS):
            self.grid.append(
                Line(Vector2(0, i * TILEHEIGHT),
                     Vector2(SCREENWIDTH, i * TILEHEIGHT), GRAY))
 def update(self):
     '''Main game loop'''
     #dt = self.clock.tick(30) / 1000.0
     x, y = pygame.mouse.get_pos()
     self.mouseposition = Vector2(x, y)
     self.events.update(self.mouseposition)
     self.render()
示例#6
0
 def getMousePosition(self, position):
     '''Gets the mouse position where we need to place the vertex.  If we are snapping to the grid, then modify the position, otherwise just pass it right through'''
     if self.snapToGrid:
         x = round(float(position.x) / TILEWIDTH) * TILEWIDTH
         y = round(float(position.y) / TILEHEIGHT) * TILEHEIGHT
         position = Vector2(x, y)
     return position
示例#7
0
    def update(self):
        '''Main game loop'''
        x, y = pygame.mouse.get_pos()
        mouseposition = Vector2(x, y)

        self.hoverVertex = None
        for vertex in self.vertices.values():
            if vertex.inbounds(mouseposition):
                self.hoverVertex = vertex

        if self.editMode:
            if self.hoverVertex is not None:
                if self.followMouse:
                    self.hoverVertex.position = mouseposition

        if self.probeMode:
            if self.probe is not None:
                if self.followMouse:
                    self.probe.position = mouseposition

        if self.vertexShadow is not None:
            self.vertexShadow.update(mouseposition)

        if self.connectionLine is not None:
            self.connectionLine.vector1 = mouseposition

        self.events.update(mouseposition)
        self.render()
示例#8
0
def getPointingVectorsFromAngleDict(alpha, D):
    '''Given the players pointing angle alpha and a dictionary of other angles, get the vectors.'''
    alpha = angleToRad(alpha)
    newD = {}
    for key in D.keys():
        values = []
        for item in D[key]:
            newitem = []
            for theta in item:
                newitem.append(Vector2(cos(alpha + theta), sin(alpha + theta)))
                #newitem.append(getAngleFromX(val))
            values.append(newitem)
        newD[key] = values
    return newD
示例#9
0
def clampVector(vector, precision):
    '''Clamp a vector, similar to above.  Return the clamped vector'''
    x = clamp(vector.x, precision)
    y = clamp(vector.y, precision)
    return Vector2(x, y)