Exemplo n.º 1
0
                   friction=0.3,
                   categoryBits=0x0004,
                   maskBits=0x0002)
box.filter.groupIndex = -2
body = world.CreateDynamicBody(position=(25, 20), fixtures=box)

timeStep = 1.0 / 60
vel_iters, pos_iters = 10, 10

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    Graphics.BackDrop(dif, land, window)

    x1, y1 = joint1.GetReactionForce(1 / timeStep)
    x2, y2 = joint2.GetReactionForce(1 / timeStep)
    x3, y3 = joint3.GetReactionForce(1 / timeStep)
    x4, y4 = joint4.GetReactionForce(1 / timeStep)
    x5, y5 = joint5.GetReactionForce(1 / timeStep)
    x6, y6 = joint6.GetReactionForce(1 / timeStep)
    x7, y7 = joint7.GetReactionForce(1 / timeStep)
    x8, y8 = joint8.GetReactionForce(1 / timeStep)
    x9, y9 = joint9.GetReactionForce(1 / timeStep)
    x10, y10 = joint10.GetReactionForce(1 / timeStep)
    x11, y11 = joint11.GetReactionForce(1 / timeStep)
    x12, y12 = joint12.GetReactionForce(1 / timeStep)
    x13, y13 = joint13.GetReactionForce(1 / timeStep)
    x14, y14 = joint14.GetReactionForce(1 / timeStep)
Exemplo n.º 2
0
def Main(info, window):
    world = b2World()
    materialStack, jointList, dif, land = loadBridge(info['bridgeID'], world)
    clock = pygame.time.Clock()
    timeStep = 1.0 / 25
    vel_iters, pos_iters = 7, 7
    frameCount = 0

    font = pygame.font.SysFont(None, 90)
    text1 = font.render('Loading', True, (255, 255, 255), None)
    text1Rect = text1.get_rect()
    text1Rect.centerx = window.get_rect().centerx
    text1Rect.centery = window.get_rect().centery
    text2 = font.render('Loading', True, (0, 0, 0), None)
    text2Rect = text2.get_rect()
    text2Rect.centerx = window.get_rect().centerx - 5
    text2Rect.centery = window.get_rect().centery - 5

    buttons = {
        'quit': Classes.Button('        Quit         ', 150, 50),
        'edit': Classes.Button('        Edit         ', 400, 50)
    }

    if info['vehicle'] == "car":
        vehicle = Classes.car()
    elif info['vehicle'] == "bike":
        vehicle = Classes.bike()
    elif info['vehicle'] == "truck":
        vehicle = Classes.truck()

    if land == 1:
        height = 10
    elif land == 2:
        height = 13
    elif land == 3:
        height = 8

    vehicle.create(world, height)

    forward, back, click = False, False, False

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                click = True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d:
                    if back == False:
                        forward = True
                elif event.key == pygame.K_a:
                    if forward == False:
                        back = True
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_d:
                    forward = False
                elif event.key == pygame.K_a:
                    back = False

        frameCount += 1

        if frameCount % 5 == 0 and frameCount > 100:
            for material in materialStack:
                material.ifBreak(world, timeStep)

        Graphics.BackDrop(dif, land, window)

        for material in materialStack:
            material.testDraw(window)

        vehicle.Draw(window)

        if frameCount > 100:
            if forward:
                vehicle.forward()
            elif back:
                vehicle.back()
            elif (forward == False and back != True) or (back == False
                                                         and forward != True):
                vehicle.stop()
        else:
            window.blit(text2, text2Rect)
            window.blit(text1, text1Rect)

        buttons['quit'].create(window)
        buttons['edit'].create(window)

        if click:
            if buttons['quit'].ifClick():
                info['test'] = False
                info2 = ["sec", info]
                return info2
            elif buttons['edit'].ifClick():
                info['test'] = False
                info['loadBridge'] = True
                info['build'] = True
                info2 = ["build", info]
                return info2

        world.Step(timeStep, vel_iters, pos_iters)

        world.ClearForces()

        #clock.tick()
        #print(clock.get_fps())

        pygame.display.update()
        pygame.time.wait(5)
Exemplo n.º 3
0
def Main(info, window):

    stickButtons = {
        'steel': Classes.stickButton('   Steel   ', 100, 550),
        'wood': Classes.stickButton('   Wood  ', 300, 550),
        'road': Classes.stickButton('Concrete', 500, 550),
        'rope': Classes.stickButton('   Rope   ', 700, 550),
        'cable': Classes.stickButton('   Cable  ', 900, 550),
        'delete': Classes.stickButton('   Delete   ', 900, 50, (223, 12, 12)),
        'quit': Classes.stickButton('   Quit   ', 100, 50, (223, 12, 12)),
        'save': Classes.stickButton('  Save    ', 300, 50, (34, 204, 0)),
        'undo': Classes.stickButton('   Undo   ', 700, 50, (223, 12, 12)),
        'test': Classes.stickButton('   Test   ', 500, 50)
    }

    if info['loadBridge'] == False:
        materialStack = []
        jointList = []
        jointNum = 0
    else:
        materialStack, jointList, jointNum, dif, land = loadBridge(
            info['bridgeID'])
        info['dif'] = dif.strip("'")
        info['land'] = land

    clickStage = "PlaceMaterial1"
    click = False
    clock = pygame.time.Clock()

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                click = True
            elif event.type == pygame.MOUSEBUTTONUP:
                release = True

        Graphics.BackDrop(info['dif'], info['land'], window, True)

        Material = buttonOn(stickButtons)
        if Material == "delete":
            clickStage = "Delete"
        elif Material == "quit":
            clickStage = "Quit"
            click = True
        elif Material == "save":
            clickStage = "Save"
            click = True
        elif Material == "undo":
            clickStage = "Undo"
            click = True
        elif Material == "test":
            clickStage = "Test"
            click = True

        for material in materialStack:
            material.Draw(window)
        for material in jointList:
            Graphics.drawJoint(window, material['point'])

        if clickStage == "PlaceMaterial1":
            for button in stickButtons:
                stickButtons[button].create(window)
        elif clickStage == "PlaceMaterial2":
            item.updateLocation(dotX, dotY)
            item.checkPlacement()
            allowConnect(materialStack, item, dotX, dotY)
            item.Draw(window)

        if Material != "":
            if Material == "delete":
                dotX, dotY = Graphics.drawDot(window, info['dif'],
                                              info['land'], (233, 12, 12))
            else:
                dotX, dotY = Graphics.drawDot(window, info['dif'],
                                              info['land'], (255, 255, 255))

        if click:
            if clickStage == "PlaceMaterial1":
                if Material != "" and stckbtnclk(stickButtons) == "":
                    if Material == "steel":
                        item = Classes.Steel()
                    elif Material == "wood":
                        item = Classes.Wood()
                    elif Material == "road":
                        item = Classes.Road()
                    elif Material == "rope":
                        item = Classes.Rope()
                    elif Material == "cable":
                        item = Classes.Cable()
                    item.setCo1(dotX, dotY)
                    clickStage = "PlaceMaterial2"
                    jointPoints = []
                    for joint in jointList:
                        jointPoints.append(joint['point'])
                    if (dotX, dotY) not in jointPoints:
                        jointNum += 1
                        jointList.append({
                            'index': jointNum,
                            'point': (dotX, dotY)
                        })
                    for joint in jointList:
                        if joint['point'] == (dotX, dotY):
                            item.setjoint1(joint['index'])
                else:
                    turnOn(stckbtnclk(stickButtons), stickButtons)
            elif clickStage == "PlaceMaterial2":
                if item.getError() == False:
                    jointPoints = []
                    for joint in jointList:
                        jointPoints.append(joint['point'])
                    if (dotX, dotY) not in jointPoints:
                        jointNum += 1
                        jointList.append({
                            'index': jointNum,
                            'point': (dotX, dotY)
                        })
                    for joint in jointList:
                        if joint['point'] == (dotX, dotY):
                            item.setjoint2(joint['index'])
                    materialStack.append(item)
                    clickStage = "PlaceMaterial1"
            elif clickStage == "Delete":
                jointClicked = jointClick(jointList, dotX, dotY)
                jointCount = 0
                cap = False
                toDelete = []
                if jointClicked != 0:
                    for joint in jointList:
                        if joint['index'] == jointClicked:
                            cap = True
                        if cap == False:
                            jointCount += 1
                    del jointList[jointCount]
                    for material in materialStack:
                        if material.getJoint1(
                        ) == jointClicked or material.getJoint2(
                        ) == jointClicked:
                            toDelete.append(material)
                    for material in toDelete:
                        materialStack.remove(material)
                    deleteExcessJoint(jointList, materialStack)
                clickStage = "PlaceMaterial1"
                stickButtons['delete'].turnOff()
            elif clickStage == "Quit":
                info['build'] = False
                return ["sec", info]
            elif clickStage == "Save":
                if len(materialStack) != 0:
                    Save.Main(window, jointList, materialStack, info)
                clickStage = "PlaceMaterial1"
                stickButtons['save'].turnOff()
            elif clickStage == "Undo":
                if len(materialStack) != 0:
                    del materialStack[-1]
                clickStage = "PlaceMaterial1"
                stickButtons['undo'].turnOff()
                deleteExcessJoint(jointList, materialStack)
            elif clickStage == "Test":
                if len(materialStack) != 0:
                    Save.Main(window, jointList, materialStack, info)
                    info['build'] = False
                    return ["chooseVehicle", info]
                clickStage = "PlaceMaterial1"
                stickButtons['test'].turnOff()
            click = False
        clock.tick()
        fps = clock.get_fps()
        #print(fps)
        pygame.display.update()