Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

object.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include "object.h"
00003 #include "sprite.h"
00004 #include "objmgr.h"
00005 
00006 GameObject::GameObject(ObjectManager &om, string n) : OM(om), sprite(NULL)
00007 {
00008         name = n;
00009         dead = false;
00010         collide = false;
00011         sprite = NULL;
00012         Xpos = Ypos = 0;
00013         layer = 0;      // sprite layer
00014         damagable = false;
00015 }
00016 
00017 GameObject::~GameObject()
00018 {
00021         if(sprite)
00022                 delete sprite;
00023 }
00024 
00025 int GameObject::SetPosition(double x, double y)
00026 {
00027         Xpos = x;
00028         Ypos = y;
00029         Xposi = (int)(x+0.5);
00030         Yposi = (int)(y+0.5);
00031 
00032         Recenter();
00033 
00034         return 0;
00035 }
00036 
00037 int GameObject::Recenter ()
00038 {
00039         if (sprite) {
00040                 Background &BKG = OM.GetSubWorld()->GetBackground();
00041                 // Convert subworld to screen coordinates
00042                 //
00044                 float xScr = (float) (((Xpos - (double)BKG.GetX())) - (sprite->GetWidth())/2.0);
00045                 float yScr = (float) (((Ypos - (double)BKG.GetY())) - (sprite->GetHeight())/2.0);
00046                 return sprite->SetPosition (xScr, yScr);
00047         }
00048         return 0;
00049 }
00050 
00051 // Returns a RECT in SUBWORLD space.
00052 Rect GameObject::GetBoundingRect()
00053 {
00054         Rect R;
00055         if(sprite) {
00056                 float x = (float)sprite->GetX();
00057                 float y = (float)sprite->GetY();
00058                 
00059                 // Convert to subworld (sprite stores it's position in screen-space)
00060                 OM.GetSubWorld()->ScreenToSubWorld (x, y);
00061                 
00062                 R = Util_BuildRect((int)x, (int)y, (int)sprite->GetWidth(), (int)sprite->GetHeight());
00063         } else
00064                 R = Util_BuildRect(0,0,0,0);
00065 
00066         return R;
00067 }
00068 
00069 double GameObject::GetX() const
00070 {
00071         return Xpos;
00072 }
00073 
00074 double GameObject::GetY() const
00075 {
00076         return Ypos;
00077 }
00078 
00079 int GameObject::GetXint() const
00080 {
00081         return Xposi;
00082 }
00083 
00084 int GameObject::GetYint() const
00085 {
00086         return Yposi;
00087 }
00088 
00089 int GameObject::GetLayer() const
00090 {
00091         return layer;
00092 }
00093 
00094 void GameObject::SetLayer(int l) 
00095 {
00096         layer = l;
00097 }
00098 
00099 void GameObject::Damage(double howmuch)
00100 {
00101         if (!IsDamagable())
00102                 return;
00103 
00104         damage -= howmuch;
00105 
00106         if (damage <= 0) {
00107                 SetDead (true);
00108         }
00109 }
00110 
00111 void GameObject::SetDamage(double howhigh)
00112 {
00113         damage = howhigh;
00114 }
00115 

Generated on Sun Dec 8 12:02:19 2002 for nnc by doxygen1.3-rc1