BGE: Change character jumping to char

* Change the character jumping variables and methods from int to char.
* Limit the maxJumps integer value from 0 to 255.
* Allow to set the minimum jump amount to 0.

Reviewers: panzergame, lordloki, moguri

Reviewed By: lordloki, moguri

Subscribers: agoose77

Projects: #game_engine

Differential Revision: https://developer.blender.org/D1305
This commit is contained in:
Thomas Szepe 2015-10-11 15:41:40 +02:00
parent 5295202c2c
commit 83721682bb
5 changed files with 20 additions and 17 deletions

View File

@ -25,7 +25,7 @@ base class --- :class:`PyObjectPlus`
The maximum number of jumps a character can perform before having to touch the ground. By default this is set to 1. 2 allows for a double jump, etc.
:type: int
:type: int in [0, 255], default 1
.. attribute:: jumpCount

View File

@ -25,6 +25,7 @@
#include "KX_CharacterWrapper.h"
#include "PHY_ICharacter.h"
#include "KX_PyMath.h"
#include "BLI_utildefines.h"
KX_CharacterWrapper::KX_CharacterWrapper(PHY_ICharacter* character) :
PyObjectPlus(),
@ -116,7 +117,9 @@ int KX_CharacterWrapper::pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE
return PY_SET_ATTR_FAIL;
}
self->m_character->SetMaxJumps((int)param);
CLAMP(param, 0, 255);
self->m_character->SetMaxJumps((unsigned char)param);
return PY_SET_ATTR_SUCCESS;
}

View File

@ -81,24 +81,24 @@ void BlenderBulletCharacterController::updateAction(btCollisionWorld *collisionW
m_motionState->setWorldTransform(getGhostObject()->getWorldTransform());
}
int BlenderBulletCharacterController::getMaxJumps() const
unsigned char BlenderBulletCharacterController::getMaxJumps() const
{
return m_maxJumps;
}
void BlenderBulletCharacterController::setMaxJumps(int maxJumps)
void BlenderBulletCharacterController::setMaxJumps(unsigned char maxJumps)
{
m_maxJumps = maxJumps;
}
int BlenderBulletCharacterController::getJumpCount() const
unsigned char BlenderBulletCharacterController::getJumpCount() const
{
return m_jumps;
}
bool BlenderBulletCharacterController::canJump() const
{
return onGround() || m_jumps < m_maxJumps;
return (onGround() && m_maxJumps > 0) || m_jumps < m_maxJumps;
}
void BlenderBulletCharacterController::jump()

View File

@ -407,19 +407,19 @@ class BlenderBulletCharacterController : public btKinematicCharacterController,
{
private:
btMotionState* m_motionState;
int m_jumps;
int m_maxJumps;
unsigned char m_jumps;
unsigned char m_maxJumps;
public:
BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight);
virtual void updateAction(btCollisionWorld *collisionWorld, btScalar dt);
int getMaxJumps() const;
unsigned char getMaxJumps() const;
void setMaxJumps(int maxJumps);
void setMaxJumps(unsigned char maxJumps);
int getJumpCount() const;
unsigned char getJumpCount() const;
virtual bool canJump() const;
@ -432,9 +432,9 @@ public:
virtual bool OnGround(){ return onGround(); }
virtual float GetGravity() { return getGravity(); }
virtual void SetGravity(float gravity) { setGravity(gravity); }
virtual int GetMaxJumps() { return getMaxJumps(); }
virtual void SetMaxJumps(int maxJumps) { setMaxJumps(maxJumps); }
virtual int GetJumpCount() { return getJumpCount(); }
virtual unsigned char GetMaxJumps() { return getMaxJumps(); }
virtual void SetMaxJumps(unsigned char maxJumps) { setMaxJumps(maxJumps); }
virtual unsigned char GetJumpCount() { return getJumpCount(); }
virtual void SetWalkDirection(const MT_Vector3& dir)
{
btVector3 vec = btVector3(dir[0], dir[1], dir[2]);

View File

@ -23,10 +23,10 @@ public:
virtual float GetGravity()= 0;
virtual void SetGravity(float gravity)= 0;
virtual int GetMaxJumps()= 0;
virtual void SetMaxJumps(int maxJumps)= 0;
virtual unsigned char GetMaxJumps() = 0;
virtual void SetMaxJumps(unsigned char maxJumps) = 0;
virtual int GetJumpCount()= 0;
virtual unsigned char GetJumpCount() = 0;
virtual void SetWalkDirection(const class MT_Vector3& dir)=0;
virtual MT_Vector3 GetWalkDirection()=0;