Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Granade.cpp

Go to the documentation of this file.
00001 
00007 #include "Granade.h"
00008 
00009 /********************************************************************
00010  * Constructor
00011  */
00012 Granade::Granade() {
00013         m_life = 0.0f;
00014 }
00015 
00016 /********************************************************************
00017  * Destructor
00018  */
00019 Granade::~Granade() {
00020 }
00021 
00022 /********************************************************************
00023  * Create
00024  */
00025 void Granade::create(Vec3 p, Vec3 v, float l, float s) {
00026         this->m_position = p;
00027         this->m_velocity = v;
00028         this->m_life = l;
00029         this->m_strength = s;
00030 }
00031 
00032 /********************************************************************
00033  * Update
00034  * IMPORTANT! Returns TRUE if DEAD! (exploding!)
00035  */
00036 bool Granade::update(float dTime, ObjLevel *lvl) {
00037         if (m_life - dTime <= 0.0f) {
00038                 m_life = 0.0f;
00039                 return true;
00040         }
00041 
00042         m_life -= dTime;
00043 
00044         m_prevPosition = m_position;
00045 
00046         Vec3 dPos = m_velocity*dTime;
00047 
00048         m_position.y += dPos.y;
00049 
00050         Vec3 pos;
00051         if (m_position.y < 1.0f) {
00052                 if (lvl->isWall(m_position)) {
00053                         m_life = 0.0f;
00054                 }
00055 
00056                 // x dir
00057                 pos = m_position;
00058                 pos.x = m_position.x + dPos.x;
00059                 if (lvl->collission(pos, 0.05f)) {
00060                         m_velocity.x = -m_velocity.x;
00061                         m_position.x += m_velocity.x*dTime;
00062                 }
00063                 else {
00064                         m_position.x = pos.x;
00065                 }
00066 
00067                 // z dir
00068                 pos = m_position;
00069                 pos.z = m_position.z + dPos.z;
00070                 if (lvl->collission(pos, 0.05f)) {
00071                         m_velocity.z = -m_velocity.z;
00072                         m_position.z += m_velocity.z*dTime;
00073                 }
00074                 else {
00075                         m_position.z = pos.z;
00076                 }
00077 
00078         }
00079         else {
00080                 m_position.x += dPos.x;
00081                 m_position.z += dPos.z;
00082         }
00083 
00084         //m_position += m_velocity*dTime;
00085 
00086         m_velocity += GRAVITY*dTime;
00087 
00088         if (m_position.y < 0.05f) {
00089                 if (lvl->isWater(m_position)) {
00090                         m_life = 0.0f;
00091                 }
00092 
00093                 // bounce around
00094                 if (m_velocity.y < -2.0f) {
00095                         m_position.y = 0.05f;
00096                         m_velocity.y = -m_velocity.y*0.5f;
00097                 }
00098                 else {
00099                         m_position.y = m_prevPosition.y;
00100                         m_velocity.y = 0.0f;
00101                 }
00102 
00103                 m_velocity.x = m_velocity.x * 0.5f;
00104                 m_velocity.z = m_velocity.z * 0.5f;
00105         }
00106 
00107         return false;
00108 }

Generated on Sun Jun 5 15:47:04 2005 for Defacto by  doxygen 1.4.3