def on_event(id, event): #print(event.GetType()) if (event.GetType() == "SetCellEvent"): resource = event.mResource ob = fge.GetObserver(id) ob.SetValue("resource", resource) cellResource = fge.DecodeResource(resource) cellModel = fge.GetModel(id) if cellResource == "ProgrammingResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "Programming") if cellResource == "ArtResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "Art") if cellResource == "DesignResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "Design") if cellResource == "PhysicsResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "Physics") if cellResource == "AudioResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "Audio") if cellResource == "AIResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "AI") if cellResource == "GraphicsResource": cellModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial( "Graphics") if (event.GetType() == "CreateGameEvent"): cellContainer = fge.GetCarrier(id) items = cellContainer.GetItems() for itemID in items: cellContainer.RemoveItem(itemID) fge.DeleteEntity(itemID)
def on_update(id, dt): processor = fge.GetProcessor(id) processorContainer = fge.GetCarrier(id) processorRecipes = processor.GetRecipes() for recipe in processorRecipes: recipeMap = recipe[1] recipeOutput = recipe[0] recipeMatch = True for resource in recipeMap: recipeMatch = recipeMatch and (len( processorContainer.GetItems(fge.DecodeResource(resource))) == recipeMap[resource]) if (recipeMatch): recipeMatchEvent = fge.GetRecipeMatchEvent() recipeMatchEvent.mProcessorID = id recipeMatchEvent.mOutput = recipeOutput fge.SendEvent(recipeMatchEvent, id) if (processor.IsWorking()): t = processor.GetCurrentProcessingTime( ) / processor.GetMaxProcessingTime() processorContainer = fge.GetCarrier(id) itemIDs = processorContainer.GetItems() for itemID in itemIDs: itemTransform = fge.GetTransform(itemID) itemPosition = itemTransform.GetLocalPosition() x = (t - 1.0) * itemPosition[0] y = (t - 1.0) * itemPosition[1] + 1.25 * t z = (t - 1.0) * itemPosition[2] itemTransform.SetLocalPosition(x, y, z)
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_update(id, dt): ob = fge.GetObserver(id) resource = fge.DecodeResource(int(ob.GetValue("resource"))) cellContainer = fge.GetCarrier(id) cellItems = fge.GetCarrier(id).GetItems() for item in cellItems: if resource == fge.GetType(item): animator = fge.GetAnimator(item) if animator is not None: animator.ChangeState("Float")
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)