Example #1
0
    def test_getAngle(self):
        a = Line((0,0),(3,4))
        self.assert_(floatEqual(a.getAngle(), 0.9272952180016123))

        a = Line((5,0),(3,3))
        self.assert_(floatEqual(a.getAngle(), 2.158798930342464))

        a = Line((4,3),(0,0))
        self.assert_(floatEqual(a.getAngle(), 3.7850937623830774))

        a = Line((3,3),(5,5))
        self.assert_(floatEqual(a.getAngle(), 0.78539816339744817))

        try:
            Line((1,2),(1,2)).getAngle()
        except:
            self.fail("zero length Line.getAngle() threw an exception")
Example #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()