Author Topic: Objects, Object Manager and objects in maps?  (Read 5220 times)

Offline SharQueDo

  • Newbie
  • *
  • Posts: 3
Objects, Object Manager and objects in maps?
« on: February 24, 2006, 04:58:24 AM »
Hi,

How would I create an Object Manager using vector/stack? And how would I put multiple objects in a map?

I'm thinking of this:

Code: [Select]
Map structure:

(int)map_width
(int)map_height
(int)[height*width]mapdata
while(!eof)
{
(int)object_id (type)
(int)object_x
(int)object_y
(int)object_state
}


Help please. :)

SQD
« Last Edit: December 31, 1969, 07:00:00 PM by SharQueDo »

Offline Two52

  • Administrator
  • Posts Very Often
  • *
  • Posts: 1890
(No subject)
« Reply #1 on: February 24, 2006, 01:29:31 PM »
The object manager would contain a vector of objects.  Every game object you have should inheirit from this object class.  Each object should have an update() and a draw() method.  Update should move the object on the screen based on velocity, framerate, user input, etc.  It should also animate the object.  The draw() method should just draw the object to the screen based on vars the update() method has updated.  Then your object manager should just run through each object in the vector and call update().  After that is done, run thorugh each object and call draw().

Does this answer your question?
« Last Edit: December 31, 1969, 07:00:00 PM by Two52 »

Offline Anonymous

  • On the Bright Side: You came close to your record for damage healed as Medic
  • *
  • Posts: 3712
(No subject)
« Reply #2 on: March 02, 2006, 07:52:15 AM »
Eh, code snippits please? :P
« Last Edit: December 31, 1969, 07:00:00 PM by Anonymous »

Offline Two52

  • Administrator
  • Posts Very Often
  • *
  • Posts: 1890
(No subject)
« Reply #3 on: March 02, 2006, 01:15:14 PM »
Here is some pseudo code:
Code: [Select]
class CObject
{
    virtual void Update() { }
    virtual void Draw() {}
}

class CEnemy: public CObject
{
    void Update() { //update the position and animation }
    void Draw() { //stuff to draw here }
}

class CPlayer: public CObject
{
    void Update() { //update the position and animation }
    void Draw() { //stuff to draw here }
}

void main()
{
    List<CObject> objectlist;

    CPlayer * player = new CPlayer();
    CEnemy * enemy = new CEnemy();

    List.Add(player);
    List.Add(enemy);

    for each(object in List)
    {
        object->Update();
    }

    for each(object in List)
    {
        object->Draw();
    }
}
« Last Edit: December 31, 1969, 07:00:00 PM by Two52 »

Offline Anonymous

  • On the Bright Side: You came close to your record for damage healed as Medic
  • *
  • Posts: 3712
(No subject)
« Reply #4 on: March 04, 2006, 04:15:00 PM »
Thank you! :)
« Last Edit: December 31, 1969, 07:00:00 PM by Anonymous »