I have a sort of infrastructure thing going on for running my game, and everything works just about fine, except when I return a COORD type variable to a different object, it consistently returns -12851, regardless of the value of the actual COORD values. Here's the relevant code; the problem happens in the Collide function. The Player object is a derived class of the Entity virtual base class:
|
void SceneManager::Init(__int32 stateID, short info)
{
// initialize the level
Entities.push_back(new Player(10, 10));
Entities.push_back(new Block(25, 10));
for (short i = 0; i < Entities.size(); i++)
Entities[i]->Init();
}
void SceneManager::Tick()
{
for (unsigned short i = 0; i < Entities.size(); i++)
{
Entities[i]->Act(hOut);
Entities[i]->Draw(hOut);
for (unsigned short j = 0; j < Entities.size(); j++)
{
if (j == i)
continue;
else
Entities[i]->Collide(Entities[j]);
}
}
}
Collision Player::Collide(Entity* other)
{
Collision info;
COORD pos = other->GetPos();
if (pos.X == Position.X && pos.Y == Position.Y)
info.Contact = true;
else
info.Contact = false;
info.Intersection.X = 0;
info.Intersection.Y = 0;
info.Intersection.Z = 0;
info.OtherID = other->ID;
info.Velocity.X = 0;
info.Velocity.Y = 0;
info.Velocity.Z = 0;
if (other->ID == eIDBlock && info.Contact)
Velocity.X *= -1;
return info;
}
class Entity
{
static unsigned short Count;
public:
Entity();
virtual void Init() = 0;
virtual void Act (const HANDLE) = 0;
virtual void Draw(const HANDLE) = 0;
virtual Collision Collide(Entity*) = 0;
virtual bool Alive() = 0;
const COORD GetPos() { return Position; };
const bool GetDraw() { return Redraw; };
const __int32 ID;
protected:
virtual void Move() = 0;
virtual void Die() = 0;
COORD* Beacon;
COORD Position;
Vector Velocity;
Vector Dimensions;
bool Redraw;
char Flags;
char Frames[4];
short CurFrame, EndFrame;
short FrameDelay, FrameTimer;
unsigned short Timer;
};
|
Please let me know if you see anything else I did wrong, or if you need more code to work with. This is an ASCII game, so there aren't really any graphical considerations to take into account.