Esempio n. 1
0
class Player(GameObject):
    def __init__(self, x, y):
        super().__init__(x, y)
        self.sprite = Sprite("engineer.jpg")
        self.keyboard = Keyboard()

    def update(self, time_elapsed):
        if (self.keyboard.is_key_pressed(Keyboard.RIGHT)):
            self.velocity = Vec2(100, 0)

        if (self.keyboard.is_key_pressed(Keyboard.LEFT)):
            self.velocity = Vec2(-100, 0)

        if (self.keyboard.is_key_pressed(Keyboard.DOWN)):
            self.velocity = Vec2(0, 100)

        if (self.keyboard.is_key_pressed(Keyboard.UP)):
            self.velocity = Vec2(0, -100)

    def draw(self, graphics):
        self.sprite.set_x(self.position.x)
        self.sprite.set_y(self.position.y)
        graphics.add(self.sprite)
Esempio n. 2
0
class PongBar(RigidBody):
    def __init__(self, position, control):
        super().__init__(position, 0, BoxCollider(position, (71, 296)), 5)
        self.sprite = Sprite(conf.ASSETS + 'bar.jpg')
        self.keyboard = Keyboard()
        self.control = control

    def update(self, time_elapsed):
        new_position = self.control() * time_elapsed
        self.position += new_position

        height = self.sprite.height
        middle_height = self.sprite.height / 2

        if new_position.y < 0 and self.position.y < 3 + middle_height:
            self.position -= new_position
        elif new_position.y > 0 and self.position.y + height > 597 + middle_height:
            self.position -= new_position
        else:
            pass

    def draw(self, graphics):
        self.sprite.draw(graphics, self.position.x, self.position.y)
Esempio n. 3
0
class SpriteTest(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.filename = "engineer.jpg"
        self.sprite = Sprite(self.filename)

    def test_rezise(self):
        current_width = self.sprite.width
        current_height = self.sprite.height

        self.sprite.resize(2 * current_width, 2 * current_height)

        new_width = self.sprite.width
        new_height = self.sprite.height

        self.assertEqual(new_width, 2 * current_width)
        self.assertEqual(new_height, 2 * current_height)

    def test_set_x(self):
        self.sprite.x = 100

        self.assertEqual(self.sprite.x, 100)

    def test_get_x(self):
        self.sprite.x = 100

        self.assertEqual(self.sprite.x, 99.5)

    def test_set_y(self):
        self.sprite.y = 200

        self.assertEqual(self.sprite.y, 200)

    def test_get_y(self):
        self.sprite.y = 200

        self.assertEqual(self.sprite.y, 199.5)
Esempio n. 4
0
 def __init__(self, position):
     super().__init__(position, 1, BoxCollider(position, (27, 26)), 1.2)
     self.keyboard = Keyboard()
     self.sprite = Sprite(conf.ASSETS + 'ball.png')
     self.moving = False
Esempio n. 5
0
 def __init__(self, position, control):
     super().__init__(position, 0, BoxCollider(position, (71, 296)), 5)
     self.sprite = Sprite(conf.ASSETS + 'bar.jpg')
     self.keyboard = Keyboard()
     self.control = control
Esempio n. 6
0
 def __init__(self, x, y):
     super().__init__(x, y)
     self.sprite = Sprite("engineer.jpg")
     self.keyboard = Keyboard()
Esempio n. 7
0
 def __init__(self, position):
     super().__init__(position, 0, BoxCollider(position, (296, 71)), 5)
     self.sprite = Sprite(conf.ASSETS + 'bar2.jpg')
     self.keyboard = Keyboard()
Esempio n. 8
0
 def setUpClass(self):
     self.filename = "engineer.jpg"
     self.sprite = Sprite(self.filename)