def test_is_false_for_line_in_the_bottom_left_corner(self):
        corner = Point(self.object.rect.left, self.object.rect.bottom)

        # Build a line so that the player is on its edge
        line = Polygon([corner + Point(-10, -10), corner + Point(10, 10)])

        self.assertFalse(self.object.is_to_the_right(line))
Exemplo n.º 2
0
    def __init__(self):
        State.__init__(self)
        self.active_state = "Play"
        self.level = 0
        self.score = Score(3)

        self.gameboard = GameBoard(walls=[],
                                   collectables=[],
                                   obstacles=[],
                                   bullets=[])

        # Build a player instance, inject `on_*_collision` handlers to keep track of the score
        self.player = Player(
            speed_unit=8,
            on_obstacle_collision=lambda: self.score.decrease_lives(),
            on_collectable_collision=lambda: self.score.add_points())
        self.player.rect.x = 200
        self.player.rect.bottom = -100

        self.last_wall_y = -390
        self.last_collectable_y = -1000
        self.last_obstacle_y = -400

        self.won_level = False
        self.new_level = True

        # Make the camera focus on the point above the player.
        # Effectively renders the player on the bottom of the screen.
        camera_focus_shift = Point(0, -300)
        self.camera = Camera(camera_focus_shift)
    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)
    def test_calls_handler_on_collision(self):
        distance = self.object.v_x * 0.1  # < self.v_x
        wall_right = self.make_wall(x=distance)

        gameboard = GameBoard([wall_right], [], [], [])

        expected_direction = 'R'
        expected_location = Point(self.base_rect.width + distance - 1, 0)

        with mock.patch.object(self.object,
                               'on_collision_x') as mock_collision:
            self.object.move_x(gameboard)
            mock_collision.assert_called_once_with(wall_right, gameboard)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def rect_in_corner(width, height):
    top_left = Point(0, 0)
    bottom_right = Point(width, height)
    return rectangle(top_left, bottom_right)
Exemplo n.º 7
0
 def __init__(self, focus_shift=None):
     self.x = 0
     self.y = 0
     self.focus_shift = focus_shift or Point(0, 0)
 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
Exemplo n.º 9
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)