Esempio n. 1
0
 def test_add(self):
     """Vectors can be added."""
     a = Vector(1, 2)
     b = Vector(3, 4)
     c = a + b
     assert c.x == 4
     assert c.y == 6
Esempio n. 2
0
 def test_multiply_vec(self):
     """Vectors can be multiplied by Vectors."""
     a = Vector(1, 2)
     b = Vector(3, 4)
     c = a * b
     assert c.x == 3
     assert c.y == 8
Esempio n. 3
0
 def test_set_xy(self):
     """x and y attributes can be set."""
     a = Vector(1, 2)
     a.x = 3
     a.y = 4
     assert a.x == 3
     assert a.y == 4
Esempio n. 4
0
 def test_equal(self):
     '''Vectors can be compared for equality'''
     a = Vector(1, 0)
     b = Vector(0, 1)
     c = Vector(1, 0)
     assert a == c
     assert a != b
Esempio n. 5
0
 def test_set_xy(self):
     """x and y attributes can be set."""
     a = Vector(1, 2)
     a.x = 3
     a.y = 4
     assert a.x == 3
     assert a.y == 4
Esempio n. 6
0
 def test_add_tuple(self):
     """Tuples can be added to Vectors."""
     a = Vector(1, 2)
     b = (3, 4)
     c = a + b
     assert c.x == 4
     assert c.y == 6
Esempio n. 7
0
 def __init__(self, game, pos, direction, speed=4):
     Sprite.__init__(self)
     self.game = game
     self.image = game.get_tile_surface('b.dot')
     self.mask = mask.from_surface(self.image)
     self.pos = Vector(pos)
     self.direction = direction
     self.speed = speed
Esempio n. 8
0
 def draw(self):
     """Draws the highscore list."""
     self.image.draw()
     i = 0
     for score, name in self.highscores.scores:
         y_offset = i * 30
         text = "%8i - %s" % (score, name)
         self.frame.print_text(text, self.textpos + Vector(0, y_offset),
                 config.DEMIBOLD_BIG, config.BLUE)
         i += 1
     if self.entering:
         self.frame.print_text("High Score! Please enter your name:",
                 self.textpos + Vector(0, y_offset + 50),
                 config.DEMIBOLD_BIG, config.BLUE)
         self.frame.print_text(self.name,
                 self.textpos + Vector(0, y_offset + 80),
                 config.DEMIBOLD_BIG, config.BLUE)
Esempio n. 9
0
 def test_animation(self, tile_factory, frame):
     """Animation of five colorful blocks"""
     ani = AnimatedTile("abcde", tile_factory, frame, Vector(4, 4), delay=3)
     while not ani.finished:
         ani.draw()
         pygame.display.update()
         time.sleep(config.SHORT_DELAY)
         ani.move()
Esempio n. 10
0
 def __init__(self, game):
     Sprite.__init__(self)
     self.game = game
     self.image = game.get_tile_surface('rot.hoch')
     self.mask = mask.from_surface(self.image)
     self.g = Group(self)
     self.pos = Vector(300, 510)
     self.speed = 4
     self.direction = RIGHT
Esempio n. 11
0
 def __init__(self, frame, tile, start_vector=None, direction=None, steps=0, when_finished=None):
     self.frame = frame
     self.tile = tile
     self.start_vector = start_vector or Vector(0, 0)
     self.steps = steps
     self.direction = direction or RIGHT
     self.current_vector = start_vector
     self.finished = False
     self.callback = when_finished
Esempio n. 12
0
 def get_dropped_bricks(self):
     moves = []
     for x in range(self.tmap.size.x):
         pos = Vector(x, self.tmap.size.y - 1)
         while pos.y > 0:
             pos_above = pos + UP
             if self.tmap.at(pos) == '.' and self.tmap.at(pos_above) != '.':
                 moves.append(MapMove(self.tmap, pos_above, DOWN, speed=4))
             pos = pos_above
     return MoveGroup(moves)
Esempio n. 13
0
 def find_multiplets(self):
     """Returns a list of multiplet positions"""
     multiplets = FruitMultiplets()
     taboo = []
     for x in range(1, self.tmap.size.x - 1):
         for y in range(self.tmap.size.y):
             pos = Vector(x, y)
             if self.tmap.at(pos) in ('.', '#'):
                 continue
             found = set()
             char = self.tmap.at(pos)
             self.trace_multiplets(pos, found, char, taboo)
             if len(found) >= 4:
                 multiplets.add_multiplet(found)
                 taboo.extend(found)
     return multiplets
Esempio n. 14
0
    def __init__(self, frame, egen, highscores, highscore_image, textpos):
        """
        frame - Frame instance
        egen - EventGenerator instance
        """
        self.frame = frame
        self.egen = egen

        self.textpos = Vector(textpos)
        self.highscores = highscores
        self.image = ImageBox(frame, highscore_image)

        # for entering new entries
        self.entering = False
        self.name = ""
        self.score = 0
Esempio n. 15
0
 def test_autocreate(self):
     """Creating a Vector from a Vector."""
     a = Vector(1, 2)
     b = Vector(a)
     assert b == a
Esempio n. 16
0
            self.steps -= 1
        if self.steps <= 0:
            self.finished = True
            if self.callback:
                self.callback()

    def draw(self):
        self.tile.draw(self.frame, self.current_vector)


def wait_for_move(move, screen=None, draw=None, delay=0.01):
    while not move.finished:
        if screen:
            screen.clear()
        move.move()
        if draw:
            draw()
        move.draw()
        pygame.display.update()
        time.sleep(delay)


if __name__ == '__main__':
    screen = Screen(Vector(800, 520), '../lightsouls/data/background.png')
    frame = Frame(screen, Rect(64, 64, 320, 320))
    tile_factory = TileFactory('../lightsouls/data/tiles.conf')
    pac = tile_factory.get('b.pac_right')
    move = Move(frame, pac, Vector(50, 50), RIGHT * 2, 200)
    wait_for_move(move, screen)
    time.sleep(1)
Esempio n. 17
0
 def test_hashable(self):
     d = {Vector(1, 0): 'a', Vector(0, 1): 'b'}
     assert d[Vector(1, 0)] == 'a'
     assert d[Vector(0, 1)] == 'b'
Esempio n. 18
0
 def test_equal_tuple(self):
     '''Vectors can be compared to tuples'''
     a = Vector(1, 0)
     assert a == (1, 0)
     assert a != (0, 1)
Esempio n. 19
0
 def test_small_tile(self, tile_bitmap):
     """One small tile is displayed"""
     tile = Tile('dummy', Vector(0, 0), Vector(16, 16), tile_bitmap)
     dest = Rect(32, 50, 32, 32)
     tile.draw(TEST_GAME_CONTEXT.screen, dest)
     pygame.display.update()
Esempio n. 20
0
 def test_iter(self):
     """Vectors can be iterated."""
     b = Vector(5, 6)
     assert list(b) == [5, 6]
Esempio n. 21
0
 def test_floordiv(self):
     """Vectors can be divided."""
     a = Vector(3, 5)
     c = a // (1, 2)
     assert c.x == 3
     assert c.y == 2
Esempio n. 22
0
 def create_aliens(self):
     for i in range(4):
         for j in range(20):
             direction = [LEFT, RIGHT][i % 2]
             alien = Alien(self.game, Vector(j * 32 + 32, i * 64), direction)
             self.aliens.add(alien)
Esempio n. 23
0
 def test_multiply_scalar(self):
     """Vectors can be multiplied by numbers."""
     a = Vector(1, 2)
     c = a * 3
     assert c.x == 3
     assert c.y == 6
Esempio n. 24
0
 def test_vector(self):
     """Vector has x and y attributes."""
     a = Vector(1, 2)
     assert a.x == 1
     assert a.y == 2
Esempio n. 25
0
        self.frame.clear()
        self.map.draw()

    def increase(self):
        self.value += 1
        self.redraw()

    def decrease(self):
        if self.value > 0:
            self.value -= 1
        self.redraw()



if __name__ == '__main__':
    screen = Screen(Vector(800,550), '../lightsouls/data/background.png')
    tile_factory = TileFactory('../lightsouls/data/tiles.conf')
    frame = Frame(screen, Rect(96, 64, 640, 32))
    bananas = BarDisplay(frame, tile_factory, 0, 'b', False)
    frame = Frame(screen, Rect(64, 64, 32, 320))
    cherries = BarDisplay(frame, tile_factory, 10, 'c', True)
    for i in range(15):
        pygame.display.update()
        time.sleep(0.1)
        #screen.clear()
        bananas.increase()
        cherries.decrease()
        pygame.display.update()
    for i in range(15):
        pygame.display.update()
        time.sleep(0.1)
Esempio n. 26
0
 def reset_level(self):
     self.pac.sprite.pos = Vector(PAC_START)
     self.create_ghosts()