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)
def on_event(id, event): global GRID_ID if (event.GetType() == "SetCellEvent"): GRID_ID = event.mGridID if (event.GetType() == "ContainerOutputEvent"): if (event.mContainerID == id): cellContainer = fge.GetCarrier(id) items = cellContainer.GetItems() items.reverse() outputItems = items[:event.mNumItems] for itemID in outputItems: itemCollider = fge.GetCollider(itemID) itemCollider.mIsTrigger = False itemBody = fge.GetBody(itemID) itemBody.mConstrainX = False itemBody.mConstrainY = False itemBody.mConstrainZ = False animator = fge.GetAnimator(itemID) if animator is not None: animator.ChangeState("None") cellContainer.RemoveItem(itemID) pickupEvent = fge.GetPlayerPickupEvent() pickupEvent.mPlayerID = event.mPlayerID pickupEvent.mItemID = itemID fge.SendEvent(pickupEvent, event.mPlayerID) if len(cellContainer.GetItems()) == 0: cellUpdateEvent = fge.GetCellUpdateEvent() cellUpdateEvent.mMatch = False cellUpdateEvent.mCellID = id cellUpdateEvent.mPlayerID = event.mPlayerID fge.SendEvent(cellUpdateEvent, GRID_ID)
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)
def on_event(id, event): if (event.GetType() == "PlayerPickupEvent"): if (event.mPlayerID == id): audio = fge.GetAudio(id) audio.Load("cartoon_jump-002.wav") audio.Play() audio.Volume(0.1) itemID = event.mItemID playerHands = fge.GetCarrier(id) itemBody = fge.GetBody(itemID) if (itemBody is None): itemBody = fge.GetRuntimeBody(itemID) itemBody.mConstrainX = True itemBody.mConstrainY = True itemBody.mConstrainZ = True playerHands.AddItem(itemID) playerScale = fge.GetTransform(id).GetScale() itemCollider = fge.GetCollider(itemID) if (itemCollider is None): itemCollider = fge.GetRuntimeCollider(itemID) itemCollider.mIsTrigger = True itemTransform = fge.GetTransform(itemID) if (itemTransform is None): itemTransform = fge.GetRuntimeTransform(itemID) itemScale = itemTransform.GetScale() itemTransform.SetLocalPosition( 0.0, playerScale[1] * 0.5, 0.5 + (itemScale[2] / playerScale[2]) / 2.0)
def on_update(id, dt): global CHANGE_TIME global TOGGLE_TIME global OPEN_ROTATION global CLOSED_ROTATION ob = fge.GetObserver(id) changeTime = ob.GetValue("changeTime") changeTime = changeTime - dt * .001 isOpen = int(ob.GetValue("isOpen")) == 1 toggleTime = ob.GetValue("toggleTime") if (changeTime < 0.0): isOpen = not isOpen collider = fge.GetCollider(id) if (isOpen): collider.mIsTrigger = False else: collider.mIsTrigger = True ob.SetValue("isOpen", isOpen) toggleTime = 0.0 changeTime = CHANGE_TIME if (toggleTime >= 0.0): toggleTime = toggleTime + (1.0 / TOGGLE_TIME) * dt * .001 if (toggleTime > 1.0): toggleTime = 1.0 transform = fge.GetTransform(id) newRot = [] if (isOpen): newRot = fge.lerp3(CLOSED_ROTATION, OPEN_ROTATION, toggleTime) else: newRot = fge.lerp3(OPEN_ROTATION, CLOSED_ROTATION, toggleTime) transform.SetRotation(newRot[0], newRot[1], newRot[2]) if (toggleTime >= 1.0): toggleTime = -1.0 ob.SetValue("changeTime", changeTime) ob.SetValue("toggleTime", toggleTime)
def on_event(id, event): global opName global counter if (event.GetType() == "ContainerOutputEvent"): if (event.mContainerID == id): processorContainer = fge.GetCarrier(id) items = processorContainer.GetItems() items.reverse() outputItems = items[:event.mNumItems] for itemID in outputItems: itemCollider = fge.GetCollider(itemID) itemCollider.mIsTrigger = False itemBody = fge.GetBody(itemID) itemBody.mConstrainX = False itemBody.mConstrainY = False itemBody.mConstrainZ = False processorContainer.RemoveItem(itemID) pickupEvent = fge.GetPlayerPickupEvent() pickupEvent.mPlayerID = event.mPlayerID pickupEvent.mItemID = itemID fge.SendEvent(pickupEvent, event.mPlayerID) item = fge.GetType(itemID) if (item == opName and counter == 0): particleEmitter = fge.GetParticles(id) particleEmitter.SetRunning(True) counter += 1 if (event.GetType() == "RecipeMatchEvent"): if (event.mProcessorID == id): processor = fge.GetProcessor(id) opName = fge.DecodeResource(event.mOutput) counter = 0
def on_init(id): global CHANGE_TIME ob = fge.GetObserver(id) ob.SetValue("changeTime", CHANGE_TIME) ob.SetValue("toggleTime", -1.0) transform = fge.GetTransform(id) collider = fge.GetCollider(id) collider.mIsTrigger = False ob.SetValue("isOpen", 1.0) if (transform.GetRotation()[0] < 0.0): ob.SetValue("isOpen", 0.0) collider.mIsTrigger = True
def on_event(id, event): if (event.GetType() == "PlayerDropEvent"): if (event.mPlayerID == id): playerHands = fge.GetCarrier(id) heldItems = playerHands.GetItems() for itemID in heldItems: audio = fge.GetAudio(id) audio.Load("cartoon_fall-002.wav") audio.Play() audio.Volume(0.1) itemCollider = fge.GetCollider(itemID) itemCollider.mIsTrigger = False itemBody = fge.GetBody(itemID) itemBody.mConstrainX = False itemBody.mConstrainY = False itemBody.mConstrainZ = False playerHands.Void()
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)
def on_event(id, event): if (event.GetType() == "ContainerOutputEvent"): if (event.mContainerID == id): blockContainer = fge.GetCarrier(id) items = blockContainer.GetItems() items.reverse() outputItems = items[:event.mNumItems] for itemID in outputItems: itemCollider = fge.GetCollider(itemID) itemCollider.mIsTrigger = False itemBody = fge.GetBody(itemID) itemBody.mConstrainX = False itemBody.mConstrainY = False itemBody.mConstrainZ = False blockContainer.RemoveItem(itemID) pickupEvent = fge.GetPlayerPickupEvent() pickupEvent.mPlayerID = event.mPlayerID pickupEvent.mItemID = itemID fge.SendEvent(pickupEvent, event.mPlayerID)
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)