forked from bartvdbraak/blender
BGE object.life - gives you the life countdown for temporary objects.
Whenever using AddObject actuator, this feature gives you control over morbid events (a.k.a. trigger events before the object ends). Demo file here: http://blenderecia.orgfree.com/blender/tmp/cube_life.blend Feature implemented as part of the BGE development workshop in BlenderPRO 2010 - Fortaleza, Brazil
This commit is contained in:
parent
e444c77714
commit
4814ffa07b
@ -1496,6 +1496,7 @@ PyMethodDef KX_GameObject::Methods[] = {
|
||||
PyAttributeDef KX_GameObject::Attributes[] = {
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("name", KX_GameObject, pyattr_get_name),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject, pyattr_get_parent),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("life", KX_GameObject, pyattr_get_life),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin", KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax", KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max),
|
||||
@ -1787,6 +1788,19 @@ PyObject* KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DE
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
|
||||
CValue *life = self->GetProperty("::timebomb");
|
||||
if (life)
|
||||
// this convert the timebomb seconds to frames, hard coded 50.0 (assuming 50fps)
|
||||
// value hardcoded in KX_Scene::AddReplicaObject()
|
||||
return PyFloat_FromDouble(life->GetNumber() * 50.0);
|
||||
else
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
|
@ -856,6 +856,7 @@ public:
|
||||
static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static PyObject* pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
|
||||
static PyObject* pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static PyObject* pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
|
@ -812,6 +812,8 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
|
||||
// add a timebomb to this object
|
||||
// for now, convert between so called frames and realtime
|
||||
m_tempObjectList->Add(replica->AddRef());
|
||||
// this convert the life from frames to sort-of seconds, hard coded 0.02 that assumes we have 50 frames per second
|
||||
// if you change this value, make sure you change it in KX_GameObject::pyattr_get_life property too
|
||||
CValue *fval = new CFloatValue(lifespan*0.02);
|
||||
replica->SetProperty("::timebomb",fval);
|
||||
fval->Release();
|
||||
|
Loading…
Reference in New Issue
Block a user