Adventure Game Studio | Forums

AGS Support => Advanced Technical Forum => Topic started by: tilapisha on 04 May 2022, 18:24

Title: Easymirrors help?
Post by: tilapisha on 04 May 2022, 18:24
I'm having trouble implementing easy mirrors, specifically in declaring a new mirror - I'm confused what the parameter 'center' is.

Code: Adventure Game Studio
  1. struct Mirrors2
  2. {
  3.  
  4.   //tells the module that character "c" can be used as a mirror reflection.
  5.   //Call this function at least once (i.e. give the module at least one character)
  6.   //otherwise it can't work!
  7.   //You should call this function as many times as there are mirrors in the room
  8.   // that has the most mirrors.
  9.   //For example if there are two mirrors in a room, and if that is the room
  10.   //of your game that has the most mirrors, then call this function twice.
  11.   //(with two different characters!).
  12.   import static void AddMirrorChar(Character* c);
  13.  
  14.   //Declares a new mirror in the current room. The player MUST be in that room when NewMirror is called!
  15.   // This must be done only ONCE in the entire game (in "first time enters room")
  16.   // The mirror starts disabled. It has to be enabled (using script) afterwards to be visible.
  17.   //
  18.   // 'mirror' is the object containing the sprite used as the mask.
  19.   // 'center' is a marker. The center of its sprite (width/2, height/2) should be where the player would stand (his feet coordinates) if he was glued to the mirror ;)
  20.   // 'symetry' is one of the symetries in the enum above
  21.   // 'x_offset' and 'y_offset' allow to shit the reflection by a constant number of pixels
  22.   // 'opacity' must be in 0.0, 1.0. Note: if the mirror's opcaity is 1.0 then it's fully opaque, therefore there's NO reflection!
  23.   // 'distance_attenuation' (recommended value '60.0'): if the player stands 0 pixels away from the mirror, his reflection will appear fully opaque. If he's standing 'distance_attenuation' pixels away from the mirror (or more), his reflection will be fully transparent
  24.   import static void NewMirror( Object* mask,  //set to null if no mask
  25.                                 Object* center,
  26.                                 Region* reg,   //set to null if mirror always on
  27.                                 Mirrors_Symmetries symmetry,  
  28.                                 float opacity,  
  29.                                 float distance_attenuation,  
  30.                                 int x_offset=0,  
  31.                                 int y_offset=0);
  32.  
  33.   //Tells the module that this mirror should use an entirely
  34.   //different character altogether as the reflection, instead of computing
  35.   //the reflection.
  36.   //That character should use Views that have the same number of loops and frames
  37.   //as the player character.
  38.   import static void SetSubstituteCharacter(Object* mask,  Character* c);
  39.  
  40.   //To modify the offset you've set in NewMirror
  41.   import static void SetOffset(Object* mask, int x_offset,  int y_offset);
  42.  
  43.   //To modify the opacity you've set in NewMirror
  44.   import static void SetOpacity(Object* mask, float opacity);
  45.  
  46.   //That doesn't delete the mirrors in memory (which is done automaticaly). It just disables them so that they're not rendered
  47.   import static void DisableAllMirrors();
  48.  
  49.   //Enables all mirrors in THIS room if they've been previously declared with 'NewMirror'
  50.   import static void EnableAllMirrorsInRoom();
  51.  
  52.   //Enables one mirror selectively
  53.   import static void EnableMirror (Object* mirror);

I'm confused what I should put for the center parameter.
Title: Re: Easymirrors help?
Post by: tilapisha on 04 May 2022, 18:41
This is the game: https://tilapisha.itch.io/gobyworld
Password: gummy

Github Repo: https://github.com/lishap/gobyworld
Title: Re: Easymirrors help?
Post by: Khris on 04 May 2022, 18:47
My guess is that object is used to specify the coordinates used to position the mirror image. Draw a small cross hairs sprite (like 9x9 pixels or something like that) and put it on a new room object. Then move the object to the floor below the mirror.
Title: Re: Easymirrors help?
Post by: tilapisha on 04 May 2022, 19:44
Hmmm, I did that, and still nothing.
Title: Re: Easymirrors help?
Post by: Khris on 04 May 2022, 23:31
"Still nothing"?
As in, nothing mirrory happens in-game?
Did you activate the mirror?

Quote
The mirror starts disabled. It has to be enabled (using script) afterwards to be visible.
Title: Re: Easymirrors help?
Post by: eri0o on 06 May 2022, 04:18
AddMirrorChar -> use this on game_start, if your room with most mirrors has 1 mirror, call once, if your room with most mirrors has 2 mirrors, call twice ...
You pass a dummy character to this function (NOT cGoby), this dummy character is going to be moved by the module, mirroring the character being reflected

NewMirror -> You are using this correctly in room_FirstLoad

You can also do something like the below

Code: Adventure Game Studio
  1. bool mirrorsCreated = false;
  2.  
  3. function room_Load()
  4. {
  5.  
  6.   //do this for each room that has mirrors
  7.   if (!mirrorsCreated) {
  8.   Mirrors2.AddMirrorChar(cDummy);
  9.   Mirrors2.NewMirror(oMirrorMask, oLeftMirrorCenter, null, eSymmetryHoriz,  1.0,  50.0, 0, 10);
  10.     mirrorsCreated = true;
  11.   }
  12.  
  13.   Mirrors2.EnableAllMirrorsInRoom();  
  14. }

Now there's a catch, this module is like super old and it has a scripting error, so I know it says you can make the region be null, but that is a lie

You actually have to make a region in your room, which is the area where the character can stand that will activate the mirror. If you use for instance region 2 you can then pass region[2] there.

the mask is more something like this, with a hole so the cDummy can walk through the mirror border

(https://i.imgur.com/8fvtLj7.png)

Finally, I don't understand why you are making the game using 16-bit colors, this causes all sorts of hard to use alpha values, I don't know how things work in 16-bit
Title: Re: Easymirrors help?
Post by: Crimson Wizard on 06 May 2022, 04:50
Finally, I don't understand why you are making the game using 16-bit colors, this causes all sorts of hard to use alpha values, I don't know how things work in 16-bit

16-bit games don't use alpha on sprites themselves (they are created fully opaque), but they still may use Transparency property on objects.
Title: Re: Easymirrors help?
Post by: tilapisha on 08 May 2022, 18:40

the mask is more something like this, with a hole so the cDummy can walk through the mirror border

(https://i.imgur.com/8fvtLj7.png)

Will you explain this to me? The picture is a bit confusing, I made a mask that covered the whole room, and left the mirror transparent, but the character still can be seen on the walls!

https://ibb.co/p0xqyGQ