Beispiel #1
0
 def __init__(self, acceleration, max_speed, normalize=True, flip=True):
     super().__init__()
     self.velocity = Vector2()
     self.direction = Vector2()
     self.acceleration = acceleration
     self.max_speed = max_speed
     self.entity = None
     self.normalize = normalize
     self.flip = flip
Beispiel #2
0
    def start():
        pygame.init()
        pygame.display.set_caption('PyDungeon')
        size = width, height = (640, 480)
        game = Game()
        game.setup_default_components(size)
        scene = game.scene

        tilemap = Entity()
        scene.add_entity(tilemap)
        tilemap.add_component(NameComponent("tilemap"))

        tilemap.add_component(TransformComponent(Vector2(0, 0)))

        ts = TileSet()
        ts.load("assets/tileset.png", "assets/tileinfo.info")
        tm = TileMap(ts, size)
        mp = [[["floor_" + str(random.randrange(1, 8))] for _ in range(24)]
              for _ in range(24)]
        PyDungeons.build_wall_rect(mp, pygame.Rect(2, 2, 10, 10))
        tm.load_letters(mp)
        tilemap.add_component(tm)
        tilemap.add_component(
            TileMapCollider(
                tm, ["wall_mid", "wall_side_mid_right", "wall_side_mid_left"]))
        tilemap.add_component(RendererComponent(TileMapRenderer(), size))

        player = Entity()
        scene.add_entity(player)
        player.add_component(NameComponent("player"))

        key_bindings = [[pygame.K_a], [pygame.K_d], [pygame.K_w], [pygame.K_s]]

        player.add_component(MoveComponent(1, 2))
        player.add_component(KeyControlComponent(key_bindings))
        #player.add_component(ScreenBoundsCollisionHandler(pygame.Rect(0, 0, width, height)))
        player.add_component(TransformComponent(Vector2(100, 100)))
        player.add_component(BoxCollider((16 * 2, 22 * 2), Vector2(0, 12)))
        player.add_component(
            RendererComponent(TileRenderer(ts.tiles["knight_f_idle_anim"], ts),
                              (16 * 2, 28 * 2)))
        #player.add_component(RendererComponent(ImageRenderer("assets/tileset.png"), (1000, 1000)))

        game.add_component(ExitOnEscape())

        game.run()
def test_intersect_line5():
    line = LineSegment(Vector2(0, 5), Vector2(13, 5))
    rect = Rect(5, 0, 11, 11)
    assert rect.intersect_line(line) == Vector2(5, 5)
def test_intersect_line4():
    line = LineSegment(Vector2(0, 0), Vector2(-5, -5))
    rect = Rect(-5, -5, 11, 11)
    assert rect.intersect_line(line) == Vector2(-5, -5)
def test_intersect_line3():
    line = LineSegment(Vector2(0, 0), Vector2(3, 3))
    rect = Rect(5, 5, 11, 11)
    assert rect.intersect_line(line) is None
def test_intersect_line():
    line = LineSegment(Vector2(0, 0), Vector2(10, 10))
    rect = Rect(5, 5, 11, 11)
    assert rect.intersect_line(line) == Vector2(5, 5)
def test_equation():
    l = LineSegment(Vector2(0, 0), Vector2(1, 1))
    assert l.equation() == (1, 0)
Beispiel #8
0
 def __init__(self, size, offset=None):
     super().__init__()
     self.size = size
     self.entity = None
     self.offset = Vector2(0, 0) if offset is None else offset
def test_intersection3():
    l = LineSegment(Vector2(0, 5), Vector2(1, 5))
    l2 = LineSegment(Vector2(10, 0), Vector2(10, 10))
    assert l.intersection_point(l2) is None
def test_intersection2():
    l = LineSegment(Vector2(0, 5), Vector2(12, 5))
    l2 = LineSegment(Vector2(10, 0), Vector2(10, 10))
    assert l.intersection_point(l2) == Vector2(10, 5)
def test_intersection_false():
    l = LineSegment(Vector2(0, 0), Vector2(0, 100))
    l2 = LineSegment(Vector2(10, 0), Vector2(10, 1))
    assert l.intersection_point(l2) is None
def test_intersection_par():
    l = LineSegment(Vector2(0, 0), Vector2(1, 1))
    l2 = LineSegment(Vector2(1, 1), Vector2(2, 2))
    assert l.intersection_point(l2) is None
def test_intersection_real():
    l = LineSegment(Vector2(0., 0.), Vector2(1., 1.))
    l2 = LineSegment(Vector2(0., 1.), Vector2(1., 0.))
    assert l.intersection_point(l2) == Vector2(0.5, 0.5)
def test_equation2():
    l = LineSegment(Vector2(1, 0), Vector2(1, 5))
    assert l.equation() is not None
Beispiel #15
0
 def set_direction(self, x, y):
     self.direction = Vector2(x, y)
Beispiel #16
0
 def add_direction(self, x, y):
     self.direction += Vector2(x, y)
def test_compare():
    l = LineSegment(Vector2(0, 0), Vector2(100, 100))
    l2 = LineSegment(Vector2(0, 0), Vector2(100, 100))
    assert l == l2