// Jetpac remake using Irrlicht // Copyright Gaz Davidson (gaz@bitplane.net) #ifndef __JETPAC_ENTITY_INCLUDED__ #define __JETPAC_ENTITY_INCLUDED__ #include #include namespace irr { namespace scene { class GameEntity : public ISceneNode { public: GameEntity(ISceneManager* mgr, core::vector3df position=core::vector3df(0,0,0), core::vector3df scale=core::vector3df(1,1,1)) : ISceneNode(mgr->getRootSceneNode(), mgr, -1, position), Velocity(0,0,0), ExpiryTime(0), HasGravity(false), IsDestructable(true), IsAlive(true), IsFragile(false), Expires(false), Resting(false), LastTime(0), IsCarryable(false), Score(0), PickUpStage(0), LevelUp(false), LeftFacing(false) { setAutomaticCulling(EAC_OFF); } virtual const core::aabbox3d& getBoundingBox() const { return Box; } virtual void OnAnimate(u32 timeMs) { if (!LastTime) LastTime=timeMs; f32 t = (f32)(timeMs-LastTime); LastTime = timeMs; if (!t) return; core::vector3df newP = getPosition(); if (HasGravity && !Resting) { newP -= core::vector3df(0,Gravity*t,0); Velocity -= Velocity * (1-powf(Resistance,t)); } newP += Velocity*t; // is the position off the screen? if (newP.X > MaxX || newP.X < -MaxX) { newP.X += (MaxX*2) * ( newP.X < 0 ? 1 : -1); } if (newP.Y < -MaxY) { newP.Y = MaxY *0.25f; } setPosition(newP); ISceneNode::OnAnimate(timeMs); } virtual void render() { } void setLeftFacing(bool facing) { LeftFacing = facing; setRotation(core::vector3df(0, LeftFacing ? 180.0f : 0, 0)); } core::vector3df Velocity; bool HasGravity, // does it fall IsDestructable, // can it be destroyed? IsAlive, // is it playing? IsFragile, // does it break if it hits something solid? Expires, // does it expire? Resting, // has it landed? IsCarryable, // is it something you carry round? LevelUp, // when it hits the ground, does the ship get more complete? LeftFacing; // is it flipped? u32 ExpiryTime; s32 Score, PickUpStage; core::aabbox3d Box; u32 LastTime; }; } // scene } // irr #endif