diff --git a/demo2.cpp b/demo2.cpp index 37abbb6..4b8fd56 100644 --- a/demo2.cpp +++ b/demo2.cpp @@ -809,7 +809,9 @@ void draw() c.maxSteps = 20; c.computeTextureCoords = 1; +player.mCamera.height += player.mHeadBob; render(player.mCamera,floorHeightAt,0,textureAt,pixelFunc,c); +player.mCamera.height -= player.mHeadBob; if (shotFired) { diff --git a/demo3.cpp b/demo3.cpp index fb4ecca..2c6c775 100644 --- a/demo3.cpp +++ b/demo3.cpp @@ -9,6 +9,9 @@ // redefine player's height #define CAMERA_COLL_HEIGHT_BELOW ((3 * UNITS_PER_SQUARE) / 2) +#define FPS 40 +#define HEAD_BOB_HEIGHT 150 +#define HEAD_BOB_STEP 20 #include "general.hpp" @@ -237,16 +240,9 @@ void draw() c.maxSteps = 20; c.computeTextureCoords = 0; + player.mCamera.height += player.mHeadBob; render(player.mCamera,floorHeightAt,0,colorAt,pixelFunc,c); -/* -pokitto.display.setColor(rgbToIndex(7,7,3)); -pokitto.display.setCursor(1,1); -pokitto.display.print(player.mCamera.position.x); -pokitto.display.print(" "); -pokitto.display.print(player.mCamera.position.y); -pokitto.display.print(" "); -pokitto.display.print(player.mCamera.direction); -*/ + player.mCamera.height -= player.mHeadBob; } int main() diff --git a/general.hpp b/general.hpp index 83fa89f..6893a85 100644 --- a/general.hpp +++ b/general.hpp @@ -33,6 +33,14 @@ Pokitto::Core pokitto; #define PLAYER_JUMP_SPEED 500 #endif +#ifndef HEAD_BOB_HEIGHT +#define HEAD_BOB_HEIGHT 100 +#endif + +#ifndef HEAD_BOB_STEP +#define HEAD_BOB_STEP 10 +#endif + #ifndef GRAVITY_ACCELERATION #define GRAVITY_ACCELERATION ((3 * UNITS_PER_SQUARE) / 2) #endif @@ -205,6 +213,8 @@ public: Camera mCamera; Unit mVericalSpeed; bool mRunning; + Unit mHeadBob; + bool mHeadBobUp; Player() { @@ -217,6 +227,8 @@ public: mCamera.shear = 0; mVericalSpeed = 0; mRunning = false; + mHeadBob = 0; + mHeadBobUp = true; } void setPosition(Unit x, Unit y) @@ -250,7 +262,16 @@ public: moveOffset.x = (moveOffset.x * horizontalStep) / UNITS_PER_SQUARE; moveOffset.y = (moveOffset.y * horizontalStep) / UNITS_PER_SQUARE; + + mHeadBob += mHeadBobUp ? HEAD_BOB_STEP : -HEAD_BOB_STEP; + + if (mHeadBob > HEAD_BOB_HEIGHT) + mHeadBobUp = false; + else if (mHeadBob < -HEAD_BOB_HEIGHT) + mHeadBobUp = true; } + else + mHeadBob /= 2; if (turnDirection != 0) {