Change room with keep player position[Solved]

Started by Mehrdad, Sat 09/12/2017 17:10:38

Previous topic - Next topic

Mehrdad

Hi

I want to switch between two rooms with keep character position. My mean is player appear in the new room with the same position in the previous room.
I want this occur automatically for any time player want to switch between the two rooms.for example with the press a key.

Thanks
My official site: http://www.pershaland.com/

Crimson Wizard

#1
If you mean same position in room coordinates, that's simply like:
Code: ags

player.ChangeRoom(roomnumber, player.x, player.y);


EDIT: lol, I actually forgot that, as Khris pointed out below, you do not have to pass x,y arguments if you want them to stay same in the new room, so it's really just
Code: ags

player.ChangeRoom(roomnumber); // it will keep same coords

Mehrdad

Yes, I know it. But my means is another things. I want to switch between two rooms and player get the last coordinate automatically and appear in new room in same coordinate. For example with press "F" in keyboard it changes room and stand in same previous room coordinate but in new room.
I hope was clear this time.
My official site: http://www.pershaland.com/

Crimson Wizard

#3
Quote from: Mehrdad on Sun 10/12/2017 06:34:35
Yes, I know it. But my means is another things. I want to switch between two rooms and player get the last coordinate automatically and appear in new room in same coordinate. For example with press "F" in keyboard it changes room and stand in same previous room coordinate but in new room.
I hope was clear this time.


Sorry, this is rather confusing. Your first sentence sounds like one thing, but second sentence sound like another thing.
What do you call "previous room" and "new room" exactly?

Could you mean, maybe, that for each room X last character coordinates should be remembered, and when you return to room X these saved coordinates should be applied again?

For that case:
Code: ags

#define MAX_ROOM_NUMBER Put max room number here
struct RoomPosition
{
    int x;
    int y;
    // you can add more here, like character's facing direction
}
RoomPosition LastRoomPos[MAX_ROOM_NUMBER + 1];

function on_event(EventType event, int data)
{
    if (event == eEventLeaveRoom)
    {
        LastRoomPos[player.Room].x = player.x;
        LastRoomPos[player.Room].y = player.y;
    }
    else if (event == eEventEnterRoomBeforeFadein)
    {
        player.x = LastRoomPos[player.Room].x;
        player.y = LastRoomPos[player.Room].y;
    }
}


The code above will apply the last coordinates all the time. If you want them applied only under certain conditions, like key press, then remove last part of the function above (under "if (event == eEventEnterRoomBeforeFadein)") and add this instead:
Code: ags

function ReturnToLastPosInRoom(int room)
{
    player.ChangeRoom(room, LastRoomPos[room].x, LastRoomPos[room].y);
}

Then you can call this function whenever you need to.


If this is still not what you want, then try breaking the task into steps, like -
1) When leaving room X, store player's coordinates.
2) ...

Khris


Mehrdad

Thanks CW
Done. works perfect.Thanks a lot.

@Khris
Strange... It works perfect too and don't need to another actions. Thanks so much.
My official site: http://www.pershaland.com/

SMF spam blocked by CleanTalk