コード例 #1
0
ファイル: Train.py プロジェクト: Occy88/TrainSimulator
    def draw(self, canvas, cam, node_dict):
        # line.drawNodeList(canvas, cam, node_dict, self.node_list)
        # line.drawNode(canvas,cam,node_dict,self.nextNode,'Green')
        # line.drawNode(canvas,cam,node_dict,self.nextStop,'Red')
        # self.particle.draw(canvas, cam)
        distance = cam.origin.copy().subtract(self.particle.pos)
        if distance.getX() < 0:
            distance.x *= -1
        if distance.getY() < 0:
            distance.y *= -1

        if distance.getX() < cam.dim.getX() and distance.getY() < cam.dim.getY(
        ):
            pos3 = self.particle.pos.copy().transformToCam(cam).getP()

            currentNode = node_dict[self.currentNode]
            nextNode = node_dict[self.nextNode]
            directVector = Vector(nextNode['x'], nextNode['y']).subtract(
                Vector(currentNode['x'], currentNode['y']))
            if directVector.length() != 0:
                directVector.normalize().negate()
                rad = self.particle.radius
                ratio = cam.ratioToCam()
                length = rad * ratio.getX()
                pos1 = directVector.copy().rotate(30)
                pos2 = directVector.copy().rotate(-30)
                pos1.multiply(length).add(self.particle.pos)
                pos2.multiply(length).add(self.particle.pos)

                canvas.draw_polygon([
                    pos1.transformToCam(cam).getP(),
                    pos2.transformToCam(cam).getP(), pos3
                ], 2, 'red', self.color)
コード例 #2
0
    def setLine(self, relation_dict, line_dict, way_dict, node_dict,
                line_name):
        self.way_list = line_dict[
            line_name]  # make sure this is a list of ways by id's
        wayId = self.way_list[0]
        way = way_dict[wayId]
        self.node_list = way['nodes']

        self.stop_list = line.getStopListFromLineName(relation_dict, way_dict,
                                                      line_name)
        self.reachedEnd = False

        self.wayIndex = 0
        self.nodeIndex = 1
        self.stopIndex = 0

        self.currentWay = self.way_list[self.wayIndex]
        self.currentStop = self.stop_list[self.stopIndex]
        self.nextStop = self.stop_list[self.stopIndex]
        self.currentNode = self.node_list[self.nodeIndex - 1]
        self.nextNode = self.node_list[self.nodeIndex]
        nodeCurrent = node_dict[self.currentNode]
        nodeNext = node_dict[self.nextNode]
        self.acceleration = 0

        vel = Vector(nodeNext['x'], nodeNext['y']).subtract(
            Vector(nodeCurrent['x'], nodeCurrent['y']))
        if vel.length() != 0:
            vel.normalize()
        self.directionVect = vel
        self.cooldown = nodeCurrent['delay']
        self.currentTime = time.time()
コード例 #3
0
ファイル: Train.py プロジェクト: Occy88/TrainSimulator
    def __init__(self, maxVel, maxAcceleration, lineName1, lineName2,
                 relation_dict, line_dict, way_dict, node_dict, angle, radius,
                 spriteKey, spriteDictionary, spriteFps, idObject, numRows,
                 numColumns, startRow, startColumn, endRow, endColumn, color):

        self.line1 = lineName1
        self.line2 = lineName2
        self.line1Bool = True

        self.way_list = line_dict[
            self.line1]  #make sure this is a list of ways by id's
        wayId = self.way_list[0]
        way = way_dict[wayId]
        self.node_list = way['nodes']

        self.stop_list = line.getStopListFromLineName(relation_dict, way_dict,
                                                      self.line1)

        self.traverseForward = True

        self.reachedEnd = False
        self.wayIndex = 0
        self.nodeIndex = 1
        self.stopIndex = 0

        self.color = color
        self.send = True
        self.remove = False
        self.currentWay = self.way_list[self.wayIndex]
        self.currentStop = self.stop_list[self.stopIndex]
        self.nextStop = self.stop_list[self.stopIndex]
        self.currentNode = self.node_list[self.nodeIndex - 1]
        self.nextNode = self.node_list[self.nodeIndex]
        nodeCurrent = node_dict[self.currentNode]
        nodeNext = node_dict[self.nextNode]
        self.acceleration = 0
        self.maxVel = maxVel
        self.maxAcceleration = maxAcceleration

        vel = Vector(nodeNext['x'], nodeNext['y']).subtract(
            Vector(nodeCurrent['x'], nodeCurrent['y']))
        if vel.length() != 0:
            vel.normalize()

        self.directionVect = vel
        self.cooldown = nodeCurrent['delay']
        if self.maxVel == 50:
            self.cooldown = 10

        self.currentTime = time.time()
        self.idObject = idObject
        self.particle = Particle(True,
                                 Vector(nodeCurrent['x'], nodeCurrent['y']),
                                 Vector(0, 0), radius, angle, spriteKey,
                                 spriteDictionary, spriteFps, False, False,
                                 self.idObject, numRows, numColumns, startRow,
                                 startColumn, endRow, endColumn)