Add head bob

This commit is contained in:
Miloslav Číž 2018-09-10 19:28:36 +02:00
parent 86ce3a20df
commit 71d15df2dd
3 changed files with 28 additions and 9 deletions

View file

@ -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)
{

View file

@ -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()

View file

@ -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)
{