Exemplo n.º 1
0
    def __Generate_Quake(self):
        # Make start/finish points first.
        line = extra.Make_Quake_SF_Points(2)

        # Split line, repeatedly, at random locations.
        for i in range(6, 1, -1):
            split = random.randint(0, len(line) - 2)
            (x3, y3) = extra.Partial_Vector(line[split], line[split + 1],
                                            (random.random(), 1.0))
            # New vertex gets moved about a bit.
            x3 += (random.random() * 2.0 * i) - float(i)
            y3 += (random.random() * 2.0 * i) - float(i)
            line.insert(split + 1, (x3, y3))

        # Long segments of the line are reduced into shorter segments.
        # This isn't random.
        i = 0
        while (i <= (len(line) - 2)):
            (x1, y1) = line[i]
            (x2, y2) = line[i + 1]
            sz = math.hypot(x1 - x2, y1 - y2)
            if (sz > 10.0):
                (x3, y3) = extra.Partial_Vector(line[i], line[i + 1],
                                                (0.5, 1.0))
                line.insert(i + 1, (x3, y3))
            else:
                i += 1

        # Line may be reversed.
        if (random.randint(0, 1) == 0):
            line.reverse()

        self.fault_lines = line
Exemplo n.º 2
0
    def __init__(self, net, difficulty):
        self.net = net
        self.difficulty = difficulty
        self.storm_frame = 0

        [a, b] = extra.Make_Quake_SF_Points(5)
        if (random.randint(0, 1) == 0):
            (a,
             b) = (b, a
                   )  # flip - ensures start point is not always on top or left

        (self.pos, dest) = (a, b)

        (sx, sy) = self.pos
        (tx, ty) = dest
        dx = tx - sx
        dy = ty - sy

        speed = ((random.random() * 1.5) + 0.6) * self.difficulty

        # Convert the overall displacement vector (dx,dy) into a velocity.
        distance = math.hypot(dx, dy)
        self.velocity = extra.Partial_Vector((0, 0), (dx, dy),
                                             (speed, distance))

        # How long does this storm live?
        self.countdown = distance / speed
Exemplo n.º 3
0
    def Draw(self,output):
        """Pipe drawn on the given surface in the correct place."""
        pos_a = Grid_To_Scr(self.n1.pos)
        pos_b = Grid_To_Scr(self.n2.pos)
        if self.Needs_Work():
            # Plain red line
            pygame.draw.line(output, RED, pos_a, pos_b, 3)
            self.dot_drawing_offset = 0
            return


        # Backing line colour depends on current limit
        colour = self.Get_Transfer_Colour()
        (r, g, b) = colour
        self.trans_colour = (min(r * 2, 255),
                min(g * 2, 255),
                min(b * 2, 255))

        pygame.draw.line(output, colour, pos_a, pos_b, 3)

        if self.velocity == 0:
            # No dots if no movement
            return

        # The moving-dots feature was not in the game until suggested 
        # by Tom Dalton, though another person did independently
        # contribute a similar patch.
        colour = DOT_COLOUR
        r = Rect(0, 0, 1, 1)

        for interp in xrange(self.dot_drawing_offset, 
                            self.length_fp, DOT_SPACING):
            pos = extra.Partial_Vector(pos_a, pos_b, (interp, self.length_fp)) 
            r.center = pos
            output.fill(colour, r)
Exemplo n.º 4
0
    def Draw(self,output):
        (x1,y1) = Grid_To_Scr(self.n1.pos)
        (x2,y2) = Grid_To_Scr(self.n2.pos)
        if ( self.Needs_Work() ):
            # Plain red line
            pygame.draw.line(output, (255,0,0), (x1,y1), (x2,y2), 3)
            self.dot_drawing_offset = 0
            return


        # Dark green backing line:
        colour = (32,128,20)
        pygame.draw.line(output, colour, (x1,y1), (x2,y2), 3)

        if ( self.current_n1_to_n2 == 0.0 ):
            return

        r = Rect(0,0,1,1)
        for pos in self.dot_positions:
            r.center = pos
            output.fill(colour, r)

        # Thanks to Acidd_UK for the following suggestion.
        dots = int(( self.length * 0.3 ) + 1.0)
        positions = dots * self.SFACTOR

        pos_a = (x1, y1 + 1)
        pos_b = (x2, y2 + 1)
        colour = (0, 255, 0) # brigt green dots

        self.dot_positions = [
            extra.Partial_Vector(pos_a, pos_b, (interp, positions))
            for interp in range(self.dot_drawing_offset, positions,
                    self.SFACTOR) ]

        for pos in self.dot_positions:
            r.center = pos
            output.fill(colour, r)