Ejemplo n.º 1
0
    def setUp(self):
        """
        This is the code that will get executed before every test.
   
        Resets the state for each test case, which in turn decouples
        tests from each other.
        """
        shape = rectangle(Point(0, 0), Point(100, 100))
        img = Image("mock_raw_image", shape)
        self.object = GameObject(img)
        self.base_rect = self.object.rect

        # Non-overlapping rectangles
        x_offset = self.object.rect.width
        y_offset = self.object.rect.height
        self.rect_above = self.base_rect.shifted(y_shift=-(10 + y_offset))
        self.rect_below = self.base_rect.shifted(y_shift=10 + y_offset)
        self.rect_left = self.base_rect.shifted(x_shift=-(10 + x_offset))
        self.rect_right = self.base_rect.shifted(x_shift=10 + x_offset)
Ejemplo n.º 2
0
 def __init__(self, x=0, y=0, width=5):
     shape = rectangle(
         Point(0, 0),
         Point(width, width * 1.5))
     img = image.Image.create(shape, color = Colors.MAGENTA)
     super().__init__(x=x, y=y, v_y0=-12, image=img)
Ejemplo n.º 3
0
def rect_in_corner(width, height):
    top_left = Point(0, 0)
    bottom_right = Point(width, height)
    return rectangle(top_left, bottom_right)
 def setUp(self):
     shape = rectangle(Point(0, 0), Point(100, 100))
     img = Image("mock_raw_image", shape)
     self.object = MovingObject(img)
     self.base_rect = self.object.rect
Ejemplo n.º 5
0
from unittest import TestCase

from silnik.rendering.point import Point
from silnik.rendering.shape import rectangle

from bounce.camera import Camera

screen_width = 400
screen_height = 300
screen_center_x = screen_width / 2
screen_center_y = screen_height / 2

screen = rectangle(
    Point(0, 0),
    Point(screen_width, screen_height))

# The player is in the center of the screen
base_player = rectangle(
    Point(screen_center_x - 10, screen_center_y - 10),
    Point(screen_center_x + 10, screen_center_y + 10))

class TestAdjustX(TestCase):
    def test_does_nothing_if_player_in_the_center(self):
        camera = Camera()
        camera.adjust_x(screen, base_player)
        self.assertEqual(camera.x, 0)

    def test_increases_x_if_player_on_the_right(self):
        camera = Camera()
        player = base_player.shifted(x_shift=screen_width)
        camera.adjust_x(screen, player)