Make Doors

Started by , Mon 15/05/2006 01:56:47

Previous topic - Next topic

Sebaest

Can anybody tell me how to make doors to go from one room to another, and than could open and close correctly from any of the rooms?
Thank you from now, and sorry about my bad English^_^ :P

INDY54

 ;)One solution is This:

1)   Create the object Door open an closed and put them in the sprite manager.
2)   Insert the object Door in your room.
3)   Create a view with the two frame of the animation of the door for example i create a view 12
4)   Then if this is the object 0 in your room, put in the Interact with the object the follow code   
I have add in the code also a sound of a door open, so you need put a coorect sound2 file in the compiled folder The game will search for SOUNDx.OGG, SOUNDx.MP3, SOUNDx.WAV and SOUNDx.VOC (where x is SOUND_NUMBER) and play the first one it finds.ogg or wav file. In my case I create an ogg. Fila call:sound2.ogg
5)   Give the command for player to change room in my case change to room 4 at coord X: 100, Y:125.



object[0].SetView (12);
object[0].Animate(0,5);
object[0].StopAnimating();
PlaySound(2);
player.ChangeRoom(4, 100, 125);




Khris

You need a global variable to check if the door is open or not in "player enters room (before fadein)" and display the according image of the open or closed door.

If that's not what you wanted to know, please be more specific.

INDY54

#3
 ;) Alternatively you can create Three room frame. the frame 0 with a door closed and the frame 1  and two with the door partially open and with the frame 2  completely open,  and then use this code:

SetBackgroundFrame(0); // Door Closed
if (GetGlobalInt(1) == 1) {
PlaySouns(2);
SetBackgroundFrame(1); // Door Open
Wait(5);
SetBackgroundFrame(2);
player.ChangeRoom(4, 100, 125);
}

EDIT: Don't double post.

R4L

If you need space like doors that open automatically, thats not hard either. Do this:

1) Draw out 3 or 4 frames of a door going up.
2) Import the images and set up the object to use the door image.
3) Create a view and plug-in the frames for the view.
4) Set the view to the object.
5) Make a region outside the door.
6) Make another region outside of the region.
7) For the script in your first region, put this under player stands on region:

Code: ags
//Sorry, my coding in 2.7 isn't too good, I'll use an older version, shouldn't be too hard to port over.

SetObjectView(0,viewhere);//where 0 is object # and viewhere is the viewÃ,  Ã, that object uses

AnimateObject(0,0,3,0);//where the 1st zero is object, 2nd 0 is loop of the view it uses, 3 is the delay of the animation, and the 3rd 0 is the repeat.

FadeOut(putyourspeedhere);
Wait(30);
NewRoom(newroomnumberhere);


Now go to your views and go to the one with the animating door. Under loop 1, put in the door frames but this time go from open to close.

Now on the other region, the one that you drew outside the first one, put this code in under player stands on region.

Code: ags

AnimateObject(0,1,3,0);


Its been a while since I have done anything in AGS but I think this will work. It's only for automated doors but I didn't know if you wanted an automated door or a regular one. Just remember to draw the walkbehinds for the door if you plan to have a character go through it.

Sebaest

Thanks, I finnaly create a door whit the solution of INDY, but in my door, the player needs to move it self betwen rooms, so, my question is: How do you make a door than can't be crossed when it's closed?
;)

Khris

Draw another walkable area on the ground which the player won't we able to walk on if the door is closed. Then use RemoveWalkableArea(x); and RestoreWalkableArea(x); whenever you close/open the door.

Sebaest

Ok but, can you be a bit more specific? where do you put those codes?
And one more thing, my door can't be opened again, after you close it. ;)

Khris

Well, I guess you've already added a runscript interaction to the "Interact with object"-event of the door, right?

So the walkable area-commands would go in there just after the commands used to change the door's appearance.

Post your script, then I can be even more specific.

INDY54

 :) Yes you are right. Put the code  inside Object intection.

If  You want open the door only if the character has the key you can use the(GetGlobalInt(1) == 1) like in  my code, where i  put the global variable for this purpose. When is equal to 1 that means you have already collect the key and then you can open the door else is equal to 0 and the code is not executed.

SMF spam blocked by CleanTalk