Sprite.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 5 -*- */
00002 
00003 /*
00004  * Combination of a first person action and a real time strategy battle game.
00005  */
00006 
00007 /*
00008  * Sprite.cpp
00009  * MetalWarriors
00010  * $Revision: 1.26 $
00011  *
00012  * Created by Daniel Aarno on Sun Oct 12 2003.
00013  * Copyright (c) 2003 Daniel Aarno and Erik Ytterberg - All rights reserved.
00014  *
00015  *     This program is free software; you can redistribute it and/or modify
00016  *     it under the terms of the GNU General Public License as published by
00017  *     the Free Software Foundation; either version 2 of the License, or
00018  *     (at your option) any later version.
00019  *
00020  *     This program is distributed in the hope that it will be useful,
00021  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *     GNU General Public License for more details.
00024  *
00025  *     You should have received a copy of the GNU General Public License
00026  *     along with this program; if not, write to the Free Software
00027  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00028  */
00029 
00030 #ifndef _SPRITE_
00031 #define _SPRITE_
00032 
00033 #include "Physics.h"
00034 #include "Network.h"
00035 
00036 #include <string>
00037 #include <iosfwd>
00038 #include "opengl.h"
00039 
00040 
00041 typedef GLuint TexID;
00042 class CompModel;
00043 
00044 typedef enum {
00045      NO_DAMAGE = 0,
00046      EXPLOSION_DAMAGE,
00047      SHATTER_DAMAGE,
00048      FIRE_DAMAGE,
00049      ICE_DAMAGE
00050 } DamageType;
00051 
00067 class Sprite : public Physics
00068 {
00069 public:
00070      typedef Network::uri_t uri_t;
00071      typedef CompModel* ModelPtr;
00072      typedef CompModel* ConstModelPtr;
00073 
00074      static int time;            
00075      static float dTime; 
00076      float radius;  
00077      unsigned int spaceId;  
00078      float camRelFollow[3]; 
00079      float camRelTrack[3];  
00080      int owner;
00081 
00082 
00083 protected:
00085      uri_t uri;
00087      bool visible;
00089      bool active;
00091      bool alive;
00093      const static char* spriteDataDir;
00096      ModelPtr m_model;
00097      
00098 
00099 public:
00103      Sprite();
00104      
00105      virtual ~Sprite();
00106      
00111      virtual void paint() = 0;
00112      
00118      virtual void update() = 0;
00119      
00124      inline bool isVisible() const { return visible; }
00125 
00131      inline void setVisible(bool b) { visible = b; }
00132 
00137      inline bool isActive() const { return active; }
00138 
00144      inline void setActive(bool b) { active = b; }
00145 
00149      inline bool isAlive() const { return alive; }
00150 
00157      inline void setAlive(bool b) { alive = b; }
00158 
00163      virtual void suspend();
00168      virtual void restore();
00169 
00181      virtual bool checkCollision(Sprite *with, bool fromSelf = false) { 
00182           return false; 
00183      }
00184 
00193      virtual bool notifyCollision(Sprite *sender) { return false; }
00194 
00204      virtual void inflictDamage(DamageType dmg, float strength) { }
00205     
00211      virtual const uri_t getURI() const;
00212 
00213      virtual void setURI(const uri_t &u) { uri = u; }
00214 
00218      int getOwner() { return owner; }
00219 
00220      virtual ConstModelPtr getModel() const { return m_model; } 
00221      virtual ModelPtr getModel() { return m_model; }
00222      virtual void computeTransform();
00223   
00232      virtual Packet packObject() const;
00233 
00239      virtual void setObject(Packet &p);
00240 
00241      virtual void resetView() {
00242           camRelFollow[0] = -15.0f;
00243           camRelFollow[1] = 2.0f;
00244           camRelFollow[2] = 5.0f;
00245      }
00246 
00251      bool operator==(const Sprite& rhs) const {
00252           return getURI() == rhs.getURI();
00253      }
00254      
00255 protected:
00257      virtual void print(std::ostream &os) const;
00258      
00260      friend std::ostream& operator<<(std::ostream &os, const Sprite& s);
00261 
00262      void setModel(ModelPtr model);
00263 
00264 private:
00265      //Prevent copy
00266      Sprite(const Sprite&);
00267      Sprite& operator=(const Sprite&);
00268 };
00269 
00271 std::ostream& operator<<(std::ostream &os, const Sprite& s);
00272 //std::ostream& operator<<(std::ostream &os, const Sprite::uri_t &uri);
00273 
00274 #endif //_SPRITE_

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7