38 #include "Core-Level-JR.h"
42 laMovingCreature::laMovingCreature(
rpgSheet* pSheet)
46 if(pSheet) _pSheet = pSheet;
51 _bExplicitFacing = M_FALSE;
53 _nMovementDirection = 0;
56 _ttTurn.parameters(0.4);
59 _ttSomersault.parameters(0.4);
60 _ttSomersault.enable(M_FALSE);
66 fxParticleSystem_params param;
68 strcat(strFilePath,
"creature_trail.fx");
69 fxp.fileOpen(strFilePath);
70 fxp.readObj(¶m, M_FALSE);
73 _fxTrail.create(param);
74 _fxTrail.enable(M_TRUE);
75 _fxTrail.enableGeneration(M_TRUE);
81 laMovingCreature::~laMovingCreature(
void)
87 void laMovingCreature::respawn()
89 laStateObject::respawn();
92 _ptPivot = _ptOriginPos;
95 _nMovementDirection = 0;
96 _bExplicitFacing = M_FALSE;
106 laStateObject::load(fp);
112 _ptPivot.mass = getObject()->getDouble(
"mass");
114 catch(laError_PropertyNotDefined&){ _ptPivot.mass = 1; }
116 _ptOriginPos = _ptPivot;
119 _pSheet->load( getObject()->getChild(
"rpg-sheet") );
124 void laMovingCreature::setFaceDirection(
int nDirection)
134 if( nDirection!=_nFaceDirection )
141 _nFaceDirection = nDirection;
148 if(!isControlEnabled())
return;
150 if( direction!=_nMovementDirection )
153 double NewSpeedModifier = ((
rpgSheet_Acrobate*)_pSheet)->modSpeed() * direction ;
156 if(_nMovementDirection)
161 _ptPivot.velocity.x(0);
168 _ptPivot.velocity.x(NewSpeedModifier);
171 _nMovementDirection = direction;
174 _update_facing( (
double) _nMovementDirection );
177 void laMovingCreature::move_v(laPoint3 dir)
179 if(!isControlEnabled())
return;
183 if(dir.lenght() > 1) dir.normalize();
184 _ptPivot.velocity = dir * NewSpeedModifier;
186 _nMovementDirection = (int) ceil(dir.x());
187 _update_facing( dir.x() );
192 void laMovingCreature::_update_facing(
double dir_x )
194 if( (!_bExplicitFacing) && (_ttTurn.isEnabled()) )
197 if(dir_x<0) setFaceDirection(-1);
198 else if(dir_x>0) setFaceDirection(+1);
211 M_BOOL laMovingCreature::jump()
213 if(!isControlEnabled())
return M_FALSE;
217 if( (_ptPivot.bOnGround) && (!_bJumping) )
221 _ptPivot.velocity.y( _ptPivot.velocity.y() - NewSpeedModifier);
232 if(!isControlEnabled())
return;
238 if( (_ptPivot.velocity.y()<0) )
240 fxMessages.add(0.8, laColor(255,255,0),
"Hop!");
243 _ptPivot.velocity.y( _ptPivot.velocity.y() - NewSpeedModifier);
245 _ttSomersault.reset();
246 _ttSomersault.enable();
250 unsigned laMovingCreature::_next_state(
unsigned nCurrentState )
256 if( _ttSomersault.isEnabled() && (!_ttSomersault.isElapsed()) )
257 return M_STATE_SOMERSAULT;
259 if(_ptPivot.bOnGround)
266 return M_STATE_STAND;
270 if(_ptPivot.velocity.y()>0)
271 return M_STATE_JUMP_D;
273 return M_STATE_JUMP_U;
276 return laStateObject::_next_state(nCurrentState);
281 void laMovingCreature::animate(laTimer &t)
287 _ptPivot.simulate(t);
288 _ptPivot.projectShadow();
292 if( _ptPivot.velocity.y()>0 ) _bJumping = M_FALSE;
297 _fxTrail.enableGeneration( (_nMovementDirection!=0) || (!_ptPivot.bOnGround) );
298 _fxTrail.position( _ptPivot );
303 if(_ptPivot.bOnGround)
304 _ttSomersault.enable(M_FALSE);
306 if( _ttSomersault.isEnabled() && (!_ttSomersault.isElapsed()) )
308 _ptPivot.angleZ = -360*_ttSomersault.reminder();
311 else _ptPivot.angleZ = 0;
313 _ttSomersault.animate(t);
318 laStateObject::animate(t);
324 void laMovingCreature::_drawFx_positioned(
laRenderer *r) {
325 laStateObject::_drawFx_positioned(r);
328 r->transTranslate( -1*_ptPivot );
338 void laMovingCreature::drawGeometry(
laRenderer *r, laPoint3 ptBasePos)
342 if(_nFaceDirection>0) _ptPivot.angleY = -180*_ttTurn.reminder() ;
343 else _ptPivot.angleY = -180*(1-_ttTurn.reminder());
345 laStateObject::drawGeometry(r, ptBasePos);
#define M_UNIT
Unit of 1 meter.
#define M_DIR_FX
Visual effects directory.
Abstract RPG Properties Sheet.
#define M_ABS(a)
Return abs(a)
Acrobatics RPG Properties.
Virtual interface for the Engine graphics renderer.
virtual void move(int direction)
virtual void somersault()