static orxSTATUS orxFASTCALL Run() { orxSTATUS eResult = orxSTATUS_SUCCESS; orxVECTOR vMousePos, vGravity; /* Updates generator's status */ orxObject_Enable(spstGenerator, orxInput_IsActive("Spawn")); /* Gets mouse position in world space */ if(orxRender_GetWorldPosition(orxMouse_GetPosition(&vMousePos), orxNULL, &vMousePos)) { orxVECTOR vGeneratorPos; /* Gets generator position */ orxObject_GetPosition(spstGenerator, &vGeneratorPos); /* Keeps generator's Z coord */ vMousePos.fZ = vGeneratorPos.fZ; /* Updates generator's position */ orxObject_SetPosition(spstGenerator, &vMousePos); } /* Gets gravity vector from input */ orxVector_Set(&vGravity, orxInput_GetValue("GravityX"), -orxInput_GetValue("GravityY"), orxFLOAT_0); /* Significant enough? */ if(orxVector_GetSquareSize(&vGravity) > orx2F(0.5f)) { static orxVECTOR svSmoothedGravity = { orx2F(0.0f), orx2F(-1.0f), orx2F(0.0f) }; /* Gets smoothed gravity from new value (low-pass filter) */ orxVector_Lerp(&svSmoothedGravity, &svSmoothedGravity, &vGravity, orx2F(0.05f)); /* Updates camera rotation */ orxCamera_SetRotation(orxViewport_GetCamera(spstViewport), orxMATH_KF_PI_BY_2 + orxVector_FromCartesianToSpherical(&vGravity, &svSmoothedGravity)->fTheta); } // Is quit action active? if(orxInput_IsActive("Quit")) { // Logs orxLOG("Quit action triggered, exiting!"); // Sets return value to orxSTATUS_FAILURE, meaning we want to exit eResult = orxSTATUS_FAILURE; } return eResult; }
orxSTATUS orxFASTCALL Run() { orxVECTOR mousePos; orxVECTOR mouseInWorld; // Get the mouse position on screen orxMouse_GetPosition(&mousePos); // Get the mouse position in the game world, // note that the mouse might not be in our game's window orxVECTOR * inWindow = orxRender_GetWorldPosition(&mousePos, viewport, &mouseInWorld); if(inWindow) { mouseInWorld.fZ = -0.1; } else { mouseInWorld.fZ = -2; // Out of camera frustum, so the light_bulb is hidden } orxObject_SetPosition(light_bulb, &mouseInWorld); return orxSTATUS_SUCCESS; }
/** Update callback */ void orxFASTCALL Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext) { orxVECTOR vPos, vSoldierPos; orxCAMERA *pstCamera; orxFLOAT fWidth, fHeight, fX, fY; /* *** CAMERA CONTROLS *** */ /* Gets first viewport camera */ pstCamera = orxViewport_GetCamera(pstViewport); /* Camera rotate left? */ if(orxInput_IsActive("CameraRotateLeft")) { /* Rotates camera CCW */ orxCamera_SetRotation(pstCamera, orxCamera_GetRotation(pstCamera) + orx2F(-4.0f) * _pstClockInfo->fDT); } /* Camera rotate right? */ if(orxInput_IsActive("CameraRotateRight")) { /* Rotates camera CW */ orxCamera_SetRotation(pstCamera, orxCamera_GetRotation(pstCamera) + orx2F(4.0f) * _pstClockInfo->fDT); } /* Camera zoom in? */ if(orxInput_IsActive("CameraZoomIn")) { /* Camera zoom in */ orxCamera_SetZoom(pstCamera, orxCamera_GetZoom(pstCamera) * orx2F(1.02f)); } /* Camera zoom out? */ if(orxInput_IsActive("CameraZoomOut")) { /* Camera zoom out */ orxCamera_SetZoom(pstCamera, orxCamera_GetZoom(pstCamera) * orx2F(0.98f)); } /* Gets camera position */ orxCamera_GetPosition(pstCamera, &vPos); /* Camera right? */ if(orxInput_IsActive("CameraRight")) { /* Updates position */ vPos.fX += orx2F(500) * _pstClockInfo->fDT; } /* Camera left? */ if(orxInput_IsActive("CameraLeft")) { /* Updates position */ vPos.fX -= orx2F(500) * _pstClockInfo->fDT; } /* Camera down? */ if(orxInput_IsActive("CameraDown")) { /* Updates position */ vPos.fY += orx2F(500) * _pstClockInfo->fDT; } /* Camera up? */ if(orxInput_IsActive("CameraUp")) { /* Updates position */ vPos.fY -= orx2F(500) * _pstClockInfo->fDT; } /* Updates camera position */ orxCamera_SetPosition(pstCamera, &vPos); /* *** VIEWPORT CONTROLS *** */ /* Gets viewport size */ orxViewport_GetRelativeSize(pstViewport, &fWidth, &fHeight); /* Viewport scale up? */ if(orxInput_IsActive("ViewportScaleUp")) { /* Scales viewport up */ fWidth *= orx2F(1.02f); fHeight*= orx2F(1.02f); } /* Viewport scale down? */ if(orxInput_IsActive("ViewportScaleDown")) { /* Scales viewport down */ fWidth *= orx2F(0.98f); fHeight*= orx2F(0.98f); } /* Updates viewport size */ orxViewport_SetRelativeSize(pstViewport, fWidth, fHeight); /* Gets viewport position */ orxViewport_GetPosition(pstViewport, &fX, &fY); /* Viewport right? */ if(orxInput_IsActive("ViewportRight")) { /* Updates position */ fX += orx2F(500) * _pstClockInfo->fDT; } /* Viewport left? */ if(orxInput_IsActive("ViewportLeft")) { /* Updates position */ fX -= orx2F(500) * _pstClockInfo->fDT; } /* Viewport down? */ if(orxInput_IsActive("ViewportDown")) { /* Updates position */ fY += orx2F(500) * _pstClockInfo->fDT; } /* Viewport up? */ if(orxInput_IsActive("ViewportUp")) { /* Updates position */ fY -= orx2F(500) * _pstClockInfo->fDT; } /* Updates viewport position */ orxViewport_SetPosition(pstViewport, fX, fY); /* *** SOLDIER MOVE UPDATE *** */ /* Gets mouse world position? */ orxRender_GetWorldPosition(orxMouse_GetPosition(&vPos), orxNULL, &vPos); /* Gets object current position */ orxObject_GetWorldPosition(pstSoldier, &vSoldierPos); /* Keeps Z value */ vPos.fZ = vSoldierPos.fZ; /* Moves the soldier under the cursor */ orxObject_SetPosition(pstSoldier, &vPos); }
/** Update callback */ static void orxFASTCALL orxBounce_Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext) { orxVECTOR vMousePos; /* Profiles */ orxPROFILER_PUSH_MARKER("Bounce_Update"); if((sbRecord == orxFALSE) && (orxInput_IsActive("Record") != orxFALSE)) { /* Starts recording with default settings */ orxSound_StartRecording("orxSoundRecording.wav", orxFALSE, 0, 0); /* Updates status */ sbRecord = orxTRUE; } if(orxInput_IsActive("ToggleTrail") && (orxInput_HasNewStatus("ToggleTrail"))) { /* Toggles trail rendering */ orxConfig_PushSection("Bounce"); orxConfig_SetBool("DisplayTrail", !orxConfig_GetBool("DisplayTrail")); orxConfig_PopSection(); } if(orxInput_IsActive("ToggleProfiler") && orxInput_HasNewStatus("ToggleProfiler")) { /* Toggles profiler rendering */ orxConfig_PushSection(orxRENDER_KZ_CONFIG_SECTION); orxConfig_SetBool(orxRENDER_KZ_CONFIG_SHOW_PROFILER, !orxConfig_GetBool(orxRENDER_KZ_CONFIG_SHOW_PROFILER)); orxConfig_PopSection(); } if(orxInput_IsActive("PreviousResolution") && orxInput_HasNewStatus("PreviousResolution")) { /* Updates video mode index */ su32VideoModeIndex = (su32VideoModeIndex == 0) ? orxDisplay_GetVideoModeCounter() - 1 : su32VideoModeIndex - 1; /* Applies it */ orxBounce_ApplyCurrentVideoMode(); } else if(orxInput_IsActive("NextResolution") && orxInput_HasNewStatus("NextResolution")) { /* Updates video mode index */ su32VideoModeIndex = (su32VideoModeIndex >= orxDisplay_GetVideoModeCounter() - 1) ? 0 : su32VideoModeIndex + 1; /* Applies it */ orxBounce_ApplyCurrentVideoMode(); } if(orxInput_IsActive("ToggleFullScreen") && orxInput_HasNewStatus("ToggleFullScreen")) { /* Toggles full screen display */ orxDisplay_SetFullScreen(!orxDisplay_IsFullScreen()); } /* Pushes config section */ orxConfig_PushSection("Bounce"); /* Updates shader values */ sfShaderPhase += orxConfig_GetFloat("ShaderPhaseSpeed") * _pstClockInfo->fDT; sfShaderFrequency = orxConfig_GetFloat("ShaderMaxFrequency") * orxMath_Sin(orxConfig_GetFloat("ShaderFrequencySpeed") * _pstClockInfo->fTime); sfShaderAmplitude = orxConfig_GetFloat("ShaderMaxAmplitude") * orxMath_Sin(orxConfig_GetFloat("ShaderAmplitudeSpeed") * _pstClockInfo->fTime); /* Updates color time */ sfColorTime -= _pstClockInfo->fDT; /* Should update color */ if(sfColorTime <= orxFLOAT_0) { orxConfig_PushSection("BounceShader"); orxConfig_GetVector("color", &svColor); orxConfig_PopSection(); sfColorTime += orx2F(3.0f); } /* Gets mouse world position */ orxRender_GetWorldPosition(&vMousePos, orxNULL, orxMouse_GetPosition(&vMousePos)); /* Updates position */ vMousePos.fZ += orx2F(0.5f); /* Has ball spawner? */ if(spoBallSpawner != orxNULL) { /* Updates its position */ orxSpawner_SetPosition(spoBallSpawner, &vMousePos); } /* Spawning */ if(orxInput_IsActive("Spawn")) { /* Spawns one ball */ orxSpawner_Spawn(spoBallSpawner, 1); } /* Picking? */ else if(orxInput_IsActive("Pick")) { orxOBJECT *pstObject; /* Updates mouse position */ vMousePos.fZ -= orx2F(0.1f); /* Picks object under mouse */ pstObject = orxObject_Pick(&vMousePos, orxU32_UNDEFINED); /* Found? */ if(pstObject) { /* Adds FX */ orxObject_AddUniqueFX(pstObject, "Pick"); } } /* Pops config section */ orxConfig_PopSection(); /* Toggle shader? */ if(orxInput_IsActive("ToggleShader") && (orxInput_HasNewStatus("ToggleShader"))) { /* Toggles shader status */ sbShaderEnabled = !sbShaderEnabled; } /* Profiles */ orxPROFILER_POP_MARKER(); }