Esempio n. 1
0
File: hero.py Progetto: sabren/blaze
 def setUp(self):
     from roomphysics import RoomPhysics
     self.r = room.Room()
     self.bird = Bird(self.r, (50.0, 50.0))
     self.bird.SPEED = 1000
     self.rp = RoomPhysics(self.r, self.bird.geom.getBody())
     self.steps = 100 # steps to take
Esempio n. 2
0
File: hero.py Progetto: sabren/blaze
class BirdTest(unittest.TestCase):
    """
    We're going to flip the Bird, er I mean, test it.
    """
    def setUp(self):
        from roomphysics import RoomPhysics
        self.r = room.Room()
        self.bird = Bird(self.r, (50.0, 50.0))
        self.bird.SPEED = 1000
        self.rp = RoomPhysics(self.r, self.bird.geom.getBody())
        self.steps = 100 # steps to take

    def testBirdGravity(self):
        """
        The kiwi bird in the sky keeps on falling:
        """
        oldx, oldy = self.bird.getPosition()
        for x in range(self.steps):
            self.rp.step()
        newx, newy = self.bird.getPosition()
        self.assertEqual(oldx, newx)
        assert newy > oldy # down is ++
    
    def testBirdMoveRight(self):
        """
        Can the bird move right?
        """
        oldposition = self.bird.getPosition()[0]
        self.bird.move((30,0))
        self.rp.step()
        newposition = self.bird.getPosition()[0]
        #print "Was at: %s, now at: %s" % (oldposition, newposition)
        assert newposition > oldposition

    def testBirdMoveLeft(self):
        """
        Can the bird move left?
        """
        oldposition = self.bird.getPosition()[0]
        self.bird.move((-30,0))
        self.rp.step()
        newposition = self.bird.getPosition()[0]
        print "Was at: %s, now at: %s" % (oldposition, newposition)
        assert newposition < oldposition


    def testBirdWalkRight(self):
        """
        Take a step to the right.
        """
        oldposition = self.bird.getPosition()[0]
        print "WALK RIGHT - Was at: %s" % oldposition
        self.bird.walk(1)
        for x in range(self.steps):
            self.rp.step()
            newposition = self.bird.getPosition()[0]
            #print "Now at: %s" % newposition
        assert newposition > oldposition

    def testBirdWalkLeft(self):
        """
        Take a step to the left.
        """
        oldposition = self.bird.getPosition()[0]
        self.bird.walk(-1)
        for x in range(self.steps):
            self.rp.step()
        newposition = self.bird.getPosition()[0]
        print "Was at: %s, now at: %s" % (oldposition, newposition)
        assert newposition < oldposition
        
    def testBirdRun(self):
	# This test should be scrapped most likely
        """
        Run, kiwi, run!
        """
        oldposition = self.bird.getPosition()
        self.bird.run(1)
        self.rp.step(self.bird.body)
        newposition = self.bird.getPosition()
        self.assertNotEqual(oldposition, newposition)
        self.bird.run((-1))
        self.rp.step(self.bird.body)
        newerposition = self.bird.getPosition()
        #self.assertNotEqual(newposition, newerposition)
        
    def testBirdJump(self):
        """
        JUMP!!!!
        """
        oldposition = self.bird.getPosition()
        self.bird.jump()
        self.rp.step(self.bird.body)
        newposition = self.bird.getPosition()
        self.assertNotEqual(oldposition, newposition)


    def testBirdMass(self):
        """
        Bird should gain mass when it eats.

        What is the mass of an unladen kiwi?
        """
        initialmass = self.bird.body.getMass().mass
        food = health.Food(0,100, self.bird.room, (50,50))
        self.bird.metabolism.eat(food)
        self.bird.updateMass()
        newmass = self.bird.body.getMass().mass
        self.assertNotEqual(initialmass, newmass)