Add head bob
This commit is contained in:
parent
86ce3a20df
commit
71d15df2dd
3 changed files with 28 additions and 9 deletions
|
@ -809,7 +809,9 @@ void draw()
|
||||||
c.maxSteps = 20;
|
c.maxSteps = 20;
|
||||||
c.computeTextureCoords = 1;
|
c.computeTextureCoords = 1;
|
||||||
|
|
||||||
|
player.mCamera.height += player.mHeadBob;
|
||||||
render(player.mCamera,floorHeightAt,0,textureAt,pixelFunc,c);
|
render(player.mCamera,floorHeightAt,0,textureAt,pixelFunc,c);
|
||||||
|
player.mCamera.height -= player.mHeadBob;
|
||||||
|
|
||||||
if (shotFired)
|
if (shotFired)
|
||||||
{
|
{
|
||||||
|
|
14
demo3.cpp
14
demo3.cpp
|
@ -9,6 +9,9 @@
|
||||||
|
|
||||||
// redefine player's height
|
// redefine player's height
|
||||||
#define CAMERA_COLL_HEIGHT_BELOW ((3 * UNITS_PER_SQUARE) / 2)
|
#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"
|
#include "general.hpp"
|
||||||
|
|
||||||
|
@ -237,16 +240,9 @@ void draw()
|
||||||
c.maxSteps = 20;
|
c.maxSteps = 20;
|
||||||
c.computeTextureCoords = 0;
|
c.computeTextureCoords = 0;
|
||||||
|
|
||||||
|
player.mCamera.height += player.mHeadBob;
|
||||||
render(player.mCamera,floorHeightAt,0,colorAt,pixelFunc,c);
|
render(player.mCamera,floorHeightAt,0,colorAt,pixelFunc,c);
|
||||||
/*
|
player.mCamera.height -= player.mHeadBob;
|
||||||
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);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
21
general.hpp
21
general.hpp
|
@ -33,6 +33,14 @@ Pokitto::Core pokitto;
|
||||||
#define PLAYER_JUMP_SPEED 500
|
#define PLAYER_JUMP_SPEED 500
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HEAD_BOB_HEIGHT
|
||||||
|
#define HEAD_BOB_HEIGHT 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HEAD_BOB_STEP
|
||||||
|
#define HEAD_BOB_STEP 10
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef GRAVITY_ACCELERATION
|
#ifndef GRAVITY_ACCELERATION
|
||||||
#define GRAVITY_ACCELERATION ((3 * UNITS_PER_SQUARE) / 2)
|
#define GRAVITY_ACCELERATION ((3 * UNITS_PER_SQUARE) / 2)
|
||||||
#endif
|
#endif
|
||||||
|
@ -205,6 +213,8 @@ public:
|
||||||
Camera mCamera;
|
Camera mCamera;
|
||||||
Unit mVericalSpeed;
|
Unit mVericalSpeed;
|
||||||
bool mRunning;
|
bool mRunning;
|
||||||
|
Unit mHeadBob;
|
||||||
|
bool mHeadBobUp;
|
||||||
|
|
||||||
Player()
|
Player()
|
||||||
{
|
{
|
||||||
|
@ -217,6 +227,8 @@ public:
|
||||||
mCamera.shear = 0;
|
mCamera.shear = 0;
|
||||||
mVericalSpeed = 0;
|
mVericalSpeed = 0;
|
||||||
mRunning = false;
|
mRunning = false;
|
||||||
|
mHeadBob = 0;
|
||||||
|
mHeadBobUp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(Unit x, Unit y)
|
void setPosition(Unit x, Unit y)
|
||||||
|
@ -250,7 +262,16 @@ public:
|
||||||
|
|
||||||
moveOffset.x = (moveOffset.x * horizontalStep) / UNITS_PER_SQUARE;
|
moveOffset.x = (moveOffset.x * horizontalStep) / UNITS_PER_SQUARE;
|
||||||
moveOffset.y = (moveOffset.y * 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)
|
if (turnDirection != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue