Ejemplo n.º 1
0
def on_event(id, event):
    global ITEM_SPACING
    if (event.GetType() == "ContainerInputEvent"):
        if (event.mContainerID == id):
            audio = fge.GetAudio(id)
            audio.Load("GameDeliver01.mp3", False)
            audio.Play()
            audio.Volume(0.1)
            playerHands = fge.GetCarrier(event.mPlayerID)
            heldItems = playerHands.GetItems()
            inputItems = heldItems[:event.mNumItems]
            dropEvent = fge.GetPlayerDropEvent()
            dropEvent.mPlayerID = event.mPlayerID
            fge.SendEvent(dropEvent, event.mPlayerID)
            processorContainer = fge.GetCarrier(id)
            for itemID in inputItems:
                itemBody = fge.GetBody(itemID)
                itemBody.mConstrainX = True
                itemBody.mConstrainY = True
                itemBody.mConstrainZ = True
                containerLen = len(processorContainer.GetItems())
                processorContainer.AddItem(itemID)
                itemCollider = fge.GetCollider(itemID)
                itemCollider.mIsTrigger = True
                itemTransform = fge.GetTransform(itemID)
                if (containerLen % 2) == 0:
                    itemTransform.SetLocalPosition(
                        0, 1.25,
                        math.ceil(containerLen / 2.0) * ITEM_SPACING)
                else:
                    itemTransform.SetLocalPosition(
                        0, 1.25,
                        -1 * math.ceil(containerLen / 2.0) * ITEM_SPACING)
Ejemplo n.º 2
0
def on_event(id, event):
    global ITEM_SPACING
    if (event.GetType() == "ContainerInputEvent"):
        if (event.mContainerID == id):
            #audio = fge.GetAudio(id)
            #audio.Load("GameDeliver01.mp3", False)
            #audio.Play()
            #audio.Volume(0.1)
            playerHands = fge.GetCarrier(event.mPlayerID)
            heldItems = playerHands.GetItems()
            inputItems = heldItems[:event.mNumItems]
            dropEvent = fge.GetPlayerDropEvent()
            dropEvent.mPlayerID = event.mPlayerID
            fge.SendEvent(dropEvent, event.mPlayerID)
            blockContainer = fge.GetCarrier(id)
            for itemID in inputItems:
                itemBody = fge.GetBody(itemID)
                itemBody.mConstrainX = True
                itemBody.mConstrainY = True
                itemBody.mConstrainZ = True
                blockContainer.AddItem(itemID)
                itemCollider = fge.GetCollider(itemID)
                itemCollider.mIsTrigger = True
                itemTransform = fge.GetTransform(itemID)
                itemScale = itemTransform.GetLocalScale()
                itemTransform.SetLocalPosition(0.0, 0.5 + 0.5 * itemScale[1],
                                               0.0)
Ejemplo n.º 3
0
def on_event(id,event):
    global GRID_ID
    if(event.GetType() == "SetCellEvent"):
        GRID_ID = event.mGridID
    if(event.GetType() == "ContainerInputEvent"):
        if(event.mContainerID == id):	
            playerHands = fge.GetCarrier(event.mPlayerID)	
            heldItems = playerHands.GetItems()
            inputItems = heldItems[:event.mNumItems]
            dropEvent = fge.GetPlayerDropEvent()
            dropEvent.mPlayerID = event.mPlayerID
            fge.SendEvent(dropEvent, event.mPlayerID)
            cellContainer = fge.GetCarrier(id)
            cellTransform = fge.GetTransform(id)
            cellPosition = cellTransform.GetPosition()
            cellScale = cellTransform.GetScale()
            for itemID in inputItems:
                itemBody = fge.GetBody(itemID)
                itemBody.mConstrainX = True
                itemBody.mConstrainY = True
                itemBody.mConstrainZ = True
                containerLen = len(cellContainer.GetItems())
                cellContainer.AddItem(itemID)
                itemCollider = fge.GetCollider(itemID)
                itemCollider.mIsTrigger = True
                itemTransform = fge.GetTransform(itemID)
                itemScale = itemTransform.GetScale()
                itemTransform.SetPosition(cellPosition[0], cellPosition[1] + 0.5 * itemScale[1] + 0.5 * cellScale[1], cellPosition[2])
            ob = fge.GetObserver(id)
            resource = fge.DecodeResource(int(ob.GetValue("resource")))
            if len(inputItems) > 0:
                if resource == fge.GetType(inputItems[0]):
                    itemTransform = fge.GetTransform(inputItems[0])
                    itemScale = itemTransform.GetScale()
                    itemTransform.SetPosition(cellPosition[0], cellPosition[1] + 0.5 * itemScale[1]  + 0.5 * cellScale[1] + 1.0, cellPosition[2])
                    cellUpdateEvent = fge.GetCellUpdateEvent()
                    cellUpdateEvent.mMatch = True
                    cellUpdateEvent.mCellID = id
                    cellUpdateEvent.mPlayerID = event.mPlayerID
                    fge.SendEvent(cellUpdateEvent, GRID_ID)
                    audio = fge.GetAudio(id)
                    audio.Load("GameDeliver01.mp3", False)
                    audio.Play()	
                    audio.Volume(0.1)
                    EntityManager.GetInstance().ToggleEntityEnable(id, False)
Ejemplo n.º 4
0
def on_event(id,event):
    if(event.GetType() == "ContainerInputEvent"):
        if(event.mContainerID == id):
            playerHands = fge.GetCarrier(event.mPlayerID)		
            heldItems = playerHands.GetItems()
            inputItems = heldItems[:event.mNumItems]
            dropEvent = fge.GetPlayerDropEvent()
            dropEvent.mPlayerID = event.mPlayerID
            fge.SendEvent(dropEvent, event.mPlayerID)
            container = fge.GetCarrier(id)
            for itemID in inputItems:
                itemBody = fge.GetBody(itemID)
                itemBody.mConstrainX = True
                itemBody.mConstrainY = True
                itemBody.mConstrainZ = True
                container.AddItem(itemID)
                itemCollider = fge.GetCollider(itemID)
                itemCollider.mIsTrigger = True
                itemTransform = fge.GetTransform(itemID)
                itemTransform.SetLocalPosition(0, -4, 0)
Ejemplo n.º 5
0
def on_update(id, dt):
    con = fge.GetController(id)
    player = fge.GetPlayer(id)
    #update the player
    speed = 8.0
    x = y = 0
    rot_num = 0
    rot = 0
    particles = fge.GetParticles(id)
    if (con.IsPressed("up")):
        rot += 180
        rot_num += 1
        y -= speed
    elif (con.IsPressed("down")):
        rot += 0
        rot_num += 1
        y += speed
    if (con.IsPressed("left")):
        if (con.IsPressed("up")):
            rot += 270
        else:
            rot += -90
        rot_num += 1
        x -= speed
    elif (con.IsPressed("right")):
        rot += 90
        rot_num += 1
        x += speed
    if (rot_num >= 1):
        player.Rotate(rot / rot_num)
    if (x != 0 or y != 0):
        playerTransform = fge.GetTransform(id)
        playerPos = playerTransform.GetPosition()
        playerScale = playerTransform.GetScale()
        #particles.SetPosition(playerPos[0], playerPos[1], playerPos[2])
        particles.SetRunning(True)
        sprint = con.IsTriggered("Sprint")
        if (sprint):
            x = 2 * x
            y = 2 * y
        player.Move(x, y, sprint)
    else:
        particles.SetRunning(False)
    playerHands = fge.GetCarrier(id)
    heldItems = playerHands.GetItems()
    lenHeldItems = len(heldItems)
    pickupAreaIDs = fge.GetChildren(id, "SearchArea")
    for pickupAreaID in pickupAreaIDs:
        pickupArea = fge.GetAreaSearch(pickupAreaID)
        foundIDs = pickupArea.GetFound()
        for foundID in foundIDs:
            foundType = fge.GetType(foundID)
            if (lenHeldItems == 0):
                if (foundType == "Processor"):
                    container = fge.GetCarrier(foundID)
                    processor = fge.GetProcessor(foundID)
                    if (len(container.GetItems()) > 0
                            and not processor.IsWorking()):
                        if (con.IsTriggered("Interact")):
                            containerOutputEvent = fge.GetContainerOutputEvent(
                            )
                            containerOutputEvent.mPlayerID = id
                            containerOutputEvent.mContainerID = foundID
                            containerOutputEvent.mNumItems = 1
                            fge.SendEvent(containerOutputEvent, foundID)
                        else:
                            containerModel = fge.GetModel(foundID)
                            if containerModel is not None:
                                containerModel.Highlight()
                        break
                if (foundType == "Block"):
                    container = fge.GetCarrier(foundID)
                    if (len(container.GetItems()) > 0):
                        if (con.IsTriggered("Interact")):
                            containerOutputEvent = fge.GetContainerOutputEvent(
                            )
                            containerOutputEvent.mPlayerID = id
                            containerOutputEvent.mContainerID = foundID
                            containerOutputEvent.mNumItems = 1
                            fge.SendEvent(containerOutputEvent, foundID)
                        else:
                            containerModel = fge.GetModel(foundID)
                            if containerModel is not None:
                                containerModel.Highlight()
                        break
                elif (foundType == "Container"):
                    continue
                elif (foundType == "Generator"):
                    inputType = ""
                    if (con.IsTriggered("Interact")):
                        inputType = "Interact"
                    if (con.IsTriggered("Sprint")):
                        inputType = "Sprint"
                    if (con.IsTriggered("action3")):
                        inputType = "action3"
                    if (con.IsTriggered("action4")):
                        inputType = "action4"
                    if (inputType != ""):
                        generatorInputEvent = fge.GetGeneratorInputEvent()
                        generatorInputEvent.mGeneratorID = foundID
                        generatorInputEvent.mPlayerID = id
                        generatorInputEvent.mInputType = inputType
                        fge.SendEvent(generatorInputEvent, foundID)
                    else:
                        highlightEvent = fge.GetHighlightEvent()
                        fge.SendEvent(highlightEvent, foundID)
                        itemModel = fge.GetModel(foundID)
                        if itemModel is not None:
                            itemModel.Highlight()
                    break
                elif (foundType == "GridCell"):
                    container = fge.GetCarrier(foundID)
                    if (len(container.GetItems()) > 0):
                        if (con.IsTriggered("Interact")):
                            containerOutputEvent = fge.GetContainerOutputEvent(
                            )
                            containerOutputEvent.mPlayerID = id
                            containerOutputEvent.mContainerID = foundID
                            containerOutputEvent.mNumItems = 1
                            fge.SendEvent(containerOutputEvent, foundID)
                        else:
                            containerModel = fge.GetModel(foundID)
                            if containerModel is not None:
                                containerModel.Highlight()
                        break
                elif (not fge.HasParent(foundID)
                      or fge.GetType(fge.GetParentID(foundID)) == "Platform"):
                    if (con.IsTriggered("Interact")):
                        pickupEvent = fge.GetPlayerPickupEvent()
                        pickupEvent.mPlayerID = id
                        pickupEvent.mItemID = foundID
                        fge.SendEvent(pickupEvent, id)
                    else:
                        itemModel = fge.GetModel(foundID)
                        if itemModel is not None:
                            itemModel.Highlight()
                    break
            else:
                if (fge.GetType(heldItems[0]) != "Game"):
                    if (foundType == "Processor"):
                        processor = fge.GetProcessor(foundID)
                        processorContainter = fge.GetCarrier(foundID)
                        if (processor.GetMaxInput() > len(
                                processorContainter.GetItems())):
                            if (con.IsTriggered("Interact")):
                                containerInputEvent = fge.GetContainerInputEvent(
                                )
                                containerInputEvent.mPlayerID = id
                                containerInputEvent.mContainerID = foundID
                                containerInputEvent.mNumItems = 1
                                fge.SendEvent(containerInputEvent, foundID)
                            else:
                                processorModel = fge.GetModel(foundID)
                                if processorModel is not None:
                                    processorModel.Highlight()
                            break
                    if (foundType == "Block"):
                        container = fge.GetCarrier(foundID)
                        block = fge.GetBlock(foundID)
                        if (1 > len(container.GetItems())
                                and block.CanInput()):
                            if (con.IsTriggered("Interact")):
                                containerInputEvent = fge.GetContainerInputEvent(
                                )
                                containerInputEvent.mPlayerID = id
                                containerInputEvent.mContainerID = foundID
                                containerInputEvent.mNumItems = 1
                                fge.SendEvent(containerInputEvent, foundID)
                            else:
                                processorModel = fge.GetModel(foundID)
                                if processorModel is not None:
                                    processorModel.Highlight()
                        break
                    if (foundType == "GridCell"):
                        cellContainter = fge.GetCarrier(foundID)
                        if (1 > len(cellContainter.GetItems())):
                            if (con.IsTriggered("Interact")):
                                containerInputEvent = fge.GetContainerInputEvent(
                                )
                                containerInputEvent.mPlayerID = id
                                containerInputEvent.mContainerID = foundID
                                containerInputEvent.mNumItems = 1
                                fge.SendEvent(containerInputEvent, foundID)
                            else:
                                cellModel = fge.GetModel(foundID)
                                if cellModel is not None:
                                    cellModel.Highlight()
                            break
                else:
                    if (foundType == "Container"):
                        if (con.IsTriggered("Interact")):
                            containerInputEvent = fge.GetContainerInputEvent()
                            containerInputEvent.mPlayerID = id
                            containerInputEvent.mContainerID = foundID
                            containerInputEvent.mNumItems = 1
                            fge.SendEvent(containerInputEvent, foundID)
                        else:
                            processorModel = fge.GetModel(foundID)
                            if processorModel is not None:
                                processorModel.Highlight()
                        break
        if (len(foundIDs) == 0 and lenHeldItems > 0
                and fge.GetType(heldItems[0]) != "Game"
                and con.IsTriggered("Interact")):
            dropEvent = fge.GetPlayerDropEvent()
            dropEvent.mPlayerID = id
            fge.SendEvent(dropEvent, id)
    body = fge.GetBody(id)
    vel = body.GetVelocity()
    xV = vel[0]
    zV = vel[2]