static void State_ParkourController_Rotate(State* state) { //Get a reference to the camera Camera* cam = RenderingManager_GetRenderingBuffer()->camera; //Grab the state members struct State_ParkourController_Members* members = (struct State_ParkourController_Members*)state->members; //If the player's mouse is locked if(InputManager_GetInputBuffer().mouseLock) { //Get the change in mouse position int deltaMouseX = (InputManager_GetInputBuffer().mousePosition[0] - InputManager_GetInputBuffer().previousMousePosition[0]); int deltaMouseY = (InputManager_GetInputBuffer().mousePosition[1] - InputManager_GetInputBuffer().previousMousePosition[1]); //If there is X rotation if(deltaMouseX != 0) { //Rotate the camera Camera_ChangeYaw(cam, (float)deltaMouseX * members->angularVelocity); } //If there is Y rotation if(deltaMouseY != 0) { //TODO: Prevent camera from looking "Too high" //Rotate the camera Camera_ChangePitch(cam, (float)deltaMouseY * members->angularVelocity); } } }
/// //Rotates the runner controller // obj: A pointer to the game object to rotate // state: A pointer to the runner controller rotating the object void State_RunnerController_Rotate(GObject* obj, State* state) { // create a camera object Camera* cam = RenderingManager_GetRenderingBuffer()->camera; //Grab the state members struct State_RunnerController_Members* members = (struct State_RunnerController_Members*)state->members; // if player's mouse is locked if(InputManager_GetInputBuffer().mouseLock) { int deltaMouseX = (InputManager_GetInputBuffer().mousePosition[0] - InputManager_GetInputBuffer().previousMousePosition[0]); int deltaMouseY = (InputManager_GetInputBuffer().mousePosition[1] - InputManager_GetInputBuffer().previousMousePosition[1]); Vector* axis = Vector_Allocate(); Vector_Initialize(axis,3); if(deltaMouseX != 0) { axis->components[1] = 1.0f; // rotate the camera Camera_ChangeYaw(cam, members->angularVelocity * deltaMouseX); axis->components[1] = 0.0f; } if (deltaMouseY != 0) { Vector forwardVector; Vector_INIT_ON_STACK(forwardVector, 3); Matrix_SliceRow(&forwardVector, cam->rotationMatrix, 2, 0, 3); // Keep camera from overextending it's boundaries. if (deltaMouseY > 0) { if (Vector_DotProduct(&forwardVector, &Vector_E2) < 0.7f) { axis->components[0] = 1.0f; Camera_ChangePitch(cam, members->angularVelocity * deltaMouseY); axis->components[0] = 0.0f; } } else if (deltaMouseY < 0) { if (Vector_DotProduct(&forwardVector, &Vector_E2) > -0.7f) { axis->components[0] = 1.0f; Camera_ChangePitch(cam, members->angularVelocity * deltaMouseY); axis->components[0] = 0.0f; } } } } }
/// //Updates the object attached to a runner controller //This object will always accelerate forward while on a surface unless the velocity is already at the max velocity. // //Parameters: // obj: A pointer to the gameobject to update as a runner // state: A pointer to the runner controller state void State_RunnerController_Update(GObject* obj, State* state) { struct State_RunnerController_Members* members = (struct State_RunnerController_Members*)state->members; //If the object is colliding with something, allow it to possibly wall run if(obj->collider->currentCollisions->size > 0) { //If the user is pressing RMB if(InputManager_IsMouseButtonPressed(2)) { State_RunnerController_Wallrun(obj, state); } else if(members->verticalRunning || members->horizontalRunning) { //Wall jump if(members->verticalRunning) { members->spinningTimer = 0.0f; } State_RunnerController_WallJump(obj, state); members->verticalRunning = members->horizontalRunning = 0; } else { if(State_RunnerController_IsOnGround(obj, state)) { State_RunnerController_Accelerate(obj, state); } } //If the user is pressing LMB if(InputManager_IsMouseButtonPressed(0)) { State_RunnerController_Jump(obj, state); } } else if(members->verticalRunning || members->horizontalRunning) { //Wall vault if(members->verticalRunning) { State_RunnerController_WallVault(obj, state); } members->verticalRunning = members->horizontalRunning = 0; } Camera* cam = RenderingManager_GetRenderingBuffer()->camera; if(members->spinningTimer < members->spinningTime) { float dt = TimeManager_GetDeltaSec(); members->spinningTimer += dt; Camera_ChangeYaw(cam, spinningRate * dt); } else { //Rotate runner State_RunnerController_Rotate(obj, state); } //Grab the camera // Set position of Camera to the body Camera_SetPosition(cam, obj->body->frame->position); }
/// //Updates a GObject using a Template state // //Parameters: // obj: A pointer to the GObject being updated // state: A pointer to the state updating the GObject void State_ParkourController_Update(GObject* obj, State* state) { //Get a reference to the state members struct State_ParkourController_Members* members = (struct State_ParkourController_Members*)state->members; //If it needs to be updated, update the shoot timer if(members->shootTimer < members->shootCooldown) { float dt = TimeManager_GetDeltaSec(); members->shootTimer += dt; } //If the left mouse button is down, shoot if(InputManager_IsMouseButtonPressed(0)) { State_ParkourController_Shoot(obj, state); } //Get a reference to the camera Camera* cam = RenderingManager_GetRenderingBuffer()->camera; //Determine if the object is colliding with anything if(obj->collider->currentCollisions->size > 0) { //Determine if the object is on the ground if(State_ParkourController_IsOnGround(obj)) { //Allow the object to accelerate State_ParkourController_Accelerate(obj, state); if(InputManager_IsKeyDown(' ')) { State_ParkourController_Jump(obj, state); } } //If the spacebar is being pressed even if the object is not on the floor if(InputManager_IsKeyDown(' ')) { //Attempt to wallrun! State_ParkourController_Wallrun(obj, state); } else if(members->verticalRunning || members->horizontalRunning) { //Wall jump! State_ParkourController_WallJump(obj, state); //If vertically wallrunning, start spinning right round baby right round! if(members->verticalRunning) members->spinningTimer = 0.0f; //The object was wallrunning but now (s)he stopped before the wall ended members->verticalRunning = members->horizontalRunning = 0; } } else if(members->verticalRunning || members->horizontalRunning) { if(members->verticalRunning) { State_ParkourController_WallVault(obj, state); } //The character was wallrunning but now there is no wall members->verticalRunning = members->horizontalRunning = 0; } //If the parkour controller currently spinning off a wall, let it continue, else let the player rotate the controller if(members->spinningTimer < members->spinningTime) { float dt = TimeManager_GetDeltaSec(); members->spinningTimer += dt; Camera_ChangeYaw(cam, spinningRate * dt); } else { //Allow the user to rotate the parkour controller State_ParkourController_Rotate(state); } //Set the position of the camera to match the object Camera_SetPosition(cam, obj->frameOfReference->position); }