Esempio n. 1
0
    def __init__(self, player_id, screen, is_first_player=True):
        self.player_id = player_id
        self.paddle_height = 3
        self.surface = pymlgame.Surface(1, self.paddle_height)
        self.surface.draw_line((0, 0), (0, 2), pymlgame.RED)
        self.is_first_player = is_first_player
        self.screen = screen

        self.reset()
Esempio n. 2
0
    def test_blit(self):
        surface = pymlgame.Surface(TEST_WIDTH - 2, TEST_HEIGHT - 2)
        surface.fill(pymlgame.WHITE)
        self.screen.blit(surface, (1, 1))

        for x in range(TEST_WIDTH):
            for y in range(TEST_HEIGHT):
                if 0 < x < TEST_WIDTH - 1 and 0 < y < TEST_HEIGHT - 1:
                    self.assertEqual(self.screen.matrix[x][y], pymlgame.WHITE)
                else:
                    self.assertEqual(self.screen.matrix[x][y], pymlgame.BLACK)
Esempio n. 3
0
 def reset(self):
     part = (int(self.screen.width / 2), int(self.screen.height / 2))
     self.snake = Snake([(part[0] - 2, part[1]),
                         (part[0] - 1, part[1]), part], RIGHT,
                        (self.screen.width, self.screen.height))
     self.gameover = False
     self.apple = self.generate_apple()
     self.apple_surface = pymlgame.Surface(1, 1)
     self.apple_surface.draw_dot((0, 0), pymlgame.GREEN)
     self.oldapple = self.apple
     self.score = 0
     self.highscore = self.get_highscore()
Esempio n. 4
0
    def test_reset(self):
        surface = pymlgame.Surface(TEST_WIDTH, TEST_HEIGHT)
        surface.fill(pymlgame.MAGENTA)
        self.screen.blit(surface, (0, 0))

        for _ in range(10):
            x = random.randint(0, TEST_WIDTH - 1)
            y = random.randint(0, TEST_HEIGHT - 1)
            self.assertEqual(self.screen.matrix[x][y], pymlgame.MAGENTA)

        self.screen.reset()

        for _ in range(10):
            x = random.randint(0, TEST_WIDTH - 1)
            y = random.randint(0, TEST_HEIGHT - 1)
            self.assertEqual(self.screen.matrix[x][y], pymlgame.BLACK)
Esempio n. 5
0
    def render(self):
        p0_color = pymlgame.GREEN if len(self.game.players) > 0 \
            else pymlgame.GREY5
        p1_color = pymlgame.GREEN if len(self.game.players) > 1 \
            else pymlgame.GREY5

        surface = pymlgame.Surface(self.game.screen.width,
                                   self.game.screen.height)
        # note(hrantzsch): this works for our default screen size only
        player0 = PygameSurfaceDecorator(
            self.font.render("P0", False, p0_color, pymlgame.BLACK))
        surface.blit(player0, Point(0, 2))

        player1 = PygameSurfaceDecorator(
            self.font.render("P1", False, p1_color, pymlgame.BLACK))
        surface.blit(player1, Point(8, 2))

        self.game.screen.blit(surface)
Esempio n. 6
0
    def render(self):
        """
        Send the current screen content to Mate Light.
        """
        self.screen.reset()

        # draw snake
        surface = pymlgame.Surface(self.screen.width, self.screen.height)
        for part in self.snake.parts:
            surface.draw_dot(part, pymlgame.RED)
        self.screen.blit(surface)

        # draw apple
        self.screen.blit(self.apple_surface, self.apple)

        if self.snake.parts[0] == self.oldapple:
            self.snake.grow = True
            self.oldapple = None

        self.screen.update()

        #TODO: accelerate every 5 points by 1 fps
        self.clock.tick()
Esempio n. 7
0
 def __init__(self, position, velocity):
     self.position = position
     self.velocity = velocity
     self.surface = pymlgame.Surface(1, 1)
     self.surface.draw_dot((0, 0), pymlgame.GREEN)
Esempio n. 8
0
 def setUp(self):
     self.surface = pymlgame.Surface(TEST_WIDTH, TEST_HEIGHT)