Exemplo n.º 1
0
    def dobounce(self, line):
        moveline = Line(self, Point2D(self.nextx,self.nexty))
        intersection = moveline.collide(line) # lines do not HAVE to intersect!
        if not intersection:
            print "lines are parallel"
            return False

        normale = line.getNormal()
        if (abs(winkelabstand(normale+math.pi,self.direction)) >
                abs(winkelabstand(normale,self.direction))):
            normale += math.pi

        einfall = winkelabstand(normale, self.direction+math.pi)
        ausfall = normale + einfall
        self.direction = ausfall;
Exemplo n.º 2
0
    def moveBounce(self, end, new):
        """
        O = old point -> moved batend
        N = new point -> new position
        F = fixpoint  -> other bat-end
        """

        F = self.ends[0]
        O = self.ends[1]
        if (end != O):
            (F,O) = (O,F)
        N = new
        T = Triangle(F, O, N)
        if isinstance(self.game.curState, PlayingState):
            ball = self.game.curState.ball
            if T.contains(ball):
                self.__playSound(N)
#               if Line(F,N).getAngle()-Line(F,O).getAngle()<0.05:
#                   return
#               print "triangle: %s, ball=%s" % (T,ball)
                moveline = Line(O,N)
                newdir = moveline.getAngle() + 0.01
                ball.direction = newdir
                ball.updateNext()
                newbat = Line(F, N)
                movevect = Point2D(ball.nextx, ball.nexty) - ball
                futurepos = ball + 100 * movevect
                ballmove = Line(ball, futurepos)
                newpos = newbat.collide(ballmove)
#               print "%s and %s collide at %s" % (newbat,moveline,newpos)
                if (newpos): #XXX
                    ball.goto(newpos.x,newpos.y)
                else:
                    print "warning: no newpos!"
                Clash(self.game, pos=ball)
                ball.hitSpeedup(self.getLength()/(config.MAX_BAT_LENGTH*2))
                ball.update()