BGE: Adding a jumpCount to KX_CharacterWrapper. This can be used to have different logic for a single jump versus a double jump. For example, a different animation for the second jump.
This commit is contained in:
@@ -3755,6 +3755,12 @@ Types
|
|||||||
|
|
||||||
:type: int
|
:type: int
|
||||||
|
|
||||||
|
.. attribute:: jumpCount
|
||||||
|
|
||||||
|
The current jump count. This can be used to have different logic for a single jump versus a double jump. For example, a different animation for the second jump.
|
||||||
|
|
||||||
|
:type: int
|
||||||
|
|
||||||
.. method:: jump()
|
.. method:: jump()
|
||||||
|
|
||||||
The character jumps based on it's jump speed.
|
The character jumps based on it's jump speed.
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ PyAttributeDef KX_CharacterWrapper::Attributes[] = {
|
|||||||
KX_PYATTRIBUTE_RO_FUNCTION("onGround", KX_CharacterWrapper, pyattr_get_onground),
|
KX_PYATTRIBUTE_RO_FUNCTION("onGround", KX_CharacterWrapper, pyattr_get_onground),
|
||||||
KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_CharacterWrapper, pyattr_get_gravity, pyattr_set_gravity),
|
KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_CharacterWrapper, pyattr_get_gravity, pyattr_set_gravity),
|
||||||
KX_PYATTRIBUTE_RW_FUNCTION("maxJumps", KX_CharacterWrapper, pyattr_get_max_jumps, pyattr_set_max_jumps),
|
KX_PYATTRIBUTE_RW_FUNCTION("maxJumps", KX_CharacterWrapper, pyattr_get_max_jumps, pyattr_set_max_jumps),
|
||||||
|
KX_PYATTRIBUTE_RO_FUNCTION("jumpCount", KX_CharacterWrapper, pyattr_get_jump_count),
|
||||||
{ NULL } //Sentinel
|
{ NULL } //Sentinel
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -99,6 +100,14 @@ int KX_CharacterWrapper::pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE
|
|||||||
self->m_character->SetMaxJumps((int)param);
|
self->m_character->SetMaxJumps((int)param);
|
||||||
return PY_SET_ATTR_SUCCESS;
|
return PY_SET_ATTR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *KX_CharacterWrapper::pyattr_get_jump_count(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||||
|
{
|
||||||
|
KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
|
||||||
|
|
||||||
|
return PyLong_FromLong(self->m_character->GetJumpCount());
|
||||||
|
}
|
||||||
|
|
||||||
PyMethodDef KX_CharacterWrapper::Methods[] = {
|
PyMethodDef KX_CharacterWrapper::Methods[] = {
|
||||||
KX_PYMETHODTABLE_NOARGS(KX_CharacterWrapper, jump),
|
KX_PYMETHODTABLE_NOARGS(KX_CharacterWrapper, jump),
|
||||||
{NULL,NULL} //Sentinel
|
{NULL,NULL} //Sentinel
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
static int pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
static int pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||||
static PyObject* pyattr_get_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
static PyObject* pyattr_get_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||||
static int pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
static int pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||||
|
static PyObject* pyattr_get_jump_count(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||||
#endif // WITH_PYTHON
|
#endif // WITH_PYTHON
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -92,6 +92,11 @@ void BlenderBulletCharacterController::setMaxJumps(int maxJumps)
|
|||||||
m_maxJumps = maxJumps;
|
m_maxJumps = maxJumps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BlenderBulletCharacterController::getJumpCount() const
|
||||||
|
{
|
||||||
|
return m_jumps;
|
||||||
|
}
|
||||||
|
|
||||||
bool BlenderBulletCharacterController::canJump() const
|
bool BlenderBulletCharacterController::canJump() const
|
||||||
{
|
{
|
||||||
return onGround() || m_jumps < m_maxJumps;
|
return onGround() || m_jumps < m_maxJumps;
|
||||||
|
|||||||
@@ -412,6 +412,8 @@ public:
|
|||||||
|
|
||||||
void setMaxJumps(int maxJumps);
|
void setMaxJumps(int maxJumps);
|
||||||
|
|
||||||
|
int getJumpCount() const;
|
||||||
|
|
||||||
virtual bool canJump() const;
|
virtual bool canJump() const;
|
||||||
|
|
||||||
virtual void jump();
|
virtual void jump();
|
||||||
|
|||||||
@@ -305,6 +305,11 @@ public:
|
|||||||
{
|
{
|
||||||
m_controller->setMaxJumps(maxJumps);
|
m_controller->setMaxJumps(maxJumps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int GetJumpCount()
|
||||||
|
{
|
||||||
|
return m_controller->getJumpCount();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CcdOverlapFilterCallBack : public btOverlapFilterCallback
|
class CcdOverlapFilterCallBack : public btOverlapFilterCallback
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public:
|
|||||||
virtual int GetMaxJumps()= 0;
|
virtual int GetMaxJumps()= 0;
|
||||||
virtual void SetMaxJumps(int maxJumps)= 0;
|
virtual void SetMaxJumps(int maxJumps)= 0;
|
||||||
|
|
||||||
|
virtual int GetJumpCount()= 0;
|
||||||
|
|
||||||
#ifdef WITH_CXX_GUARDEDALLOC
|
#ifdef WITH_CXX_GUARDEDALLOC
|
||||||
MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter")
|
MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter")
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user