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 LAUNCH_SPEED if (event.GetType() == "GeneratorOutputEvent"): if (event.mGeneratorID == id): outputItems = event.mOutputs playerPosition = fge.GetTransform(event.mPlayerID).GetPosition() generatorTransform = fge.GetTransform(id) generatorPosition = generatorTransform.GetPosition() generatorScale = generatorTransform.GetScale() for i in range(0, len(outputItems)): outputItem = fge.CreateEntity(outputItems[i]) itemBody = fge.GetRuntimeBody(outputItem) itemBody.Init() if (i == 0): pickupEvent = fge.GetPlayerPickupEvent() pickupEvent.mPlayerID = event.mPlayerID pickupEvent.mItemID = outputItem fge.SendEvent(pickupEvent, event.mPlayerID) else: itemTransform = fge.GetRuntimeTransform(outputItem) itemScale = itemTransform.GetScale() itemTransform.SetPosition( generatorPosition[0], generatorPosition[1] + 0.5 * (generatorScale[1] + itemScale[1]), generatorPosition[2]) toPlayer = [ playerPosition[0] - generatorPosition[0], playerPosition[1] - generatorPosition[1], playerPosition[2] - generatorPosition[2] ] itemBody.SetVelocity(LAUNCH_SPEED * toPlayer[0], LAUNCH_SPEED * toPlayer[1], LAUNCH_SPEED * toPlayer[2]) print("reached YEET")
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_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_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]