Archived

This topic is now archived and is closed to further replies.

gpr

door on tile-based engine

Recommended Posts

gpr    122
I have a simple engine to show my map and a simple character. how to know what''s the door the character is entering? how to know what''s the right coords to position my character? What is the best way to implement doors on tile-based game? GPR - Game Programming Resources

Share this post


Link to post
Share on other sites
SikCiv    122
You should keep an array or struct of all your doors like followed:

  
struct DOORS
{
RECT rcDoorPos;
bool bOpen;
etc..
}



Fill them in on game init:

DOORS Doors[MAX_DOORS];

  
Game_init()
{
Doors[0].rcDoorPos.left = 100;
Doors[0].rcDoorPos.right = 132;
Doors[0].rcDoorPos.top = 50;
Doors[0].rcDoorPos.bottom = 82;
Doors[0].bOpen = true;
}




Then at every frame, check if your character is within a door:

  

Game_Update()
{
for(int i=0;i<MAX_DOORS;i++)
{
if(PtInRect(&Doors[i].rcDoorPos, ptCharacter))
{
EnterDoor(i);
}
}
}







  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
acraig    471
You could also have a "trigger" on each tile. This could be a trigger to open a door, load a new map, do dialog, etc.

  
class MapCell
{
// Tile Stuff


private:
Trigger *m_Trigger;
};


You then check to see what tile the person is on and if there is a trigger there and then execute it. Of course, you still have to figure out how to design your Trigger class.

Share this post


Link to post
Share on other sites
gpr    122
Thanks.
Now i have an idea.

  
class DOOR
{
RECT DoorPos; // door position

RECT TargetPos; // target position in the new map

bool Open;
MapId MapTarget; // the target map

void Enter(void); // method to enter in the door

// change the map and position

// the character on it.

}

class MAP
{
DOOR Door[MAX_DOORS];
void CheckDoor(void); // check all doors

...
}


something like this?


http://dway.cjb.net

Share this post


Link to post
Share on other sites