예제 #1
0
    frame_count = 0
    epoch = time()
    while True:
        delta = Uhr.tick(120)

        frame_count += 1
        if time() - epoch > 10:
            server_fps = int(frame_count / (time() - epoch))
            com.send_all("root", "server-fps", fps=server_fps)
            frame_count = 0
            epoch = time()

        # receaving and player init
        for client in com.clients:
            if client.player is None:
                client.player = Player(Vector(), 0)
                client.player.client = client
                world.add(client.player)
                client.player.world = world

            while client.has_message():
                message = client.pop()
                if message['request'] == 'test':
                    print("test-message: " + str(message['value']))
                if message['target'] == "client":
                    client.handle_event(**message)
                if message["target"] == "root":
                    client.handle_event(**message)

        world.update(delta, com)
예제 #2
0
    ln1 = TestGameObject([Vector(x, y) for x, y in ((-2, 10), (10, -2))])
    ln2 = TestGameObject([Vector(x, y) for x, y in ((10, 10), (-10, -10))])
    ta1 = TestGameObject(
        [Vector(x, y) for x, y in ((3, -1), (2, -4), (4, -4))])
    ta2 = TestGameObject(
        [Vector(x, y) for x, y in ((1, -2), (5, -3), (5, -1))])
    print("sq1 / sq2:", sq1.colliding(sq2), sq2.colliding(sq1))
    print("sq1 / sq3:", sq1.colliding(sq3), sq3.colliding(sq1))
    print("sq2 / sq3:", sq2.colliding(sq3), sq3.colliding(sq2))
    print("sq1 / ln1:", sq1.colliding(ln1), ln1.colliding(sq1))
    print("ln1 / ln2:", ln1.colliding(ln2), ln2.colliding(ln1))
    print("ln1 / ln1:", ln1.colliding(ln1), ln1.colliding(ln1))
    print("ta1 / ta2:", ta1.colliding(ta2), ta2.colliding(ta1))
    print()

    pl1 = Player(Vector(), 0, Vector(2, 4))
    pl2 = Player(Vector(-1, 0.5), math.pi * 3 / 8, Vector(2, 4))
    pl3 = Player(Vector(500, 0), -0.5 * math.pi, Vector(2, 4))
    print("pl1 / pl2:", pl1.colliding(pl2), pl2.colliding(pl1))
    print("pl1 / pl3:", pl1.colliding(pl3), pl3.colliding(pl1))
    print("pl2 / pl3:", pl2.colliding(pl3), pl3.colliding(pl2))
    print()

    me1 = Meadow(Vector())
    me2 = Meadow(Vector(1, 0))
    me3 = Meadow(Vector(1, 1), 2)
    ho1 = House(Vector(0, 1))
    ho2 = House(Vector(500, 500))
    ho3 = House(Vector(0.5, 0.5))
    print("me1 / me1:", me1.colliding(me1))
    print("me1 / me2:", me1.colliding(me2), me2.colliding(me1))