示例#1
0
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")
示例#2
0
def on_init(id):
    global REQUEST_UI_ID
    global INIT
    global RECIPE
    global OUTPUT
    if(INIT):
        REQUEST_UI_ID = fge.CreateEntity("UI")
        uiTransform = fge.GetRuntimeTransform(REQUEST_UI_ID)
        uiTransform.SetScale(128.0, 128.0, 0.0)
        uiModel = fge.GetRuntimeModel(REQUEST_UI_ID)
        uiModel.mpMaterial = ResourceManager.GetInstance().LoadMaterial("FPSRecipe")
        requestMadeEvent = fge.GetRequestMadeEvent()
        requestMadeEvent.mContainerID = id
        requestMadeEvent.mRequestUIID = REQUEST_UI_ID
        requestMadeEvent.mGameRecipe = RECIPE
        requestMadeEvent.mOutput = OUTPUT
        fge.SendEvent(requestMadeEvent, id)
    INIT = False
示例#3
0
def UpdateEnding(id, dt):
    global EXITING
    global TALLY
    global SCORE
    global METRIC
    global GRADES
    global LEVEL_NAME
    global STARTED_TALLY

    ob = fge.GetObserver(id)
    time = ob.GetValue("time")
    time = time + dt * 0.001

    pointsPerSecond = 25.0

    if (time + dt * 0.001 > 2.0):
        if (not STARTED_TALLY):
            STARTED_TALLY = True
            cameraID = CameraManager.GetInstance().GetCameraID()
            if (cameraID is not -1):
                windowID = fge.CreateEntity("Billboard", cameraID)
                windowTransform = fge.GetRuntimeTransform(windowID)
                cameraFront = CameraManager.GetInstance().GetFront()
                cameraPos = fge.GetTransform(cameraID).GetPosition()
                windowTransform.SetPosition(cameraPos[0] + cameraFront[0],
                                            cameraPos[1] + cameraFront[1],
                                            cameraPos[2] + cameraFront[2])
                windowTransform.SetScale(0.6, 0.6, 0.6)
                windowModel = fge.GetRuntimeModel(windowID)
                windowModel.mpMaterial = ResourceManager.GetInstance(
                ).LoadMaterial("WindowGrey")

    if (time > 2.0):
        if (not EXITING):
            TALLY = TALLY + pointsPerSecond * dt * 0.001
            if (TALLY > SCORE):
                TALLY = SCORE
            if (InputManager.GetInstance().IsTriggered("Interact")):
                TALLY = SCORE
                EXITING = True
                Renderer.GetInstance().Fade(False, 1.0)
        grade = "F"
        for i in range(len(METRIC)):
            if METRIC[i] <= TALLY:
                grade = GRADES[i]
            else:
                break
        result_str = ""
        if (math.isclose(TALLY, SCORE)):
            if grade == "F":
                result_str = "Fail"
            else:
                result_str = "Pass"
        score_str = "Score: {:0.0f}".format(TALLY)
        grade_str = "Grade: {}".format(grade)
        Renderer.GetInstance().RenderText(LEVEL_NAME, -110.0, 150.0, 2.0, 0, 0,
                                          0, 1)
        Renderer.GetInstance().RenderText(score_str, -100.0, -0.0, 2.0, 0, 0,
                                          0, 1)
        Renderer.GetInstance().RenderText(grade_str, -100.0, -100.0, 2.0, 0, 0,
                                          0, 1)
        Renderer.GetInstance().RenderText(result_str, -25.0, -250.0, 2.0, 0, 0,
                                          0, 1)
    if (Renderer.GetInstance().GetFadeMultiplier() <= 0.0):
        LevelCompleteEvent = fge.GetLevelCompleteEvent()
        LevelCompleteEvent.mScore = 50
        LevelCompleteEvent.mGrade = "A"
        fge.BroadcastEvent(LevelCompleteEvent)
        AudioManager.GetInstance().StopAll()
        fge.ChangeScene("LevelScreenFinal")

    ob.SetValue("time", time)