More on Puzzle-Design

Started by Gabarts, Fri 10/01/2014 12:25:15

Previous topic - Next topic

Gabarts

Question for advanced programmers or game creators:

Suppose you need to design a standard puzzle as seen in many games, like for example a 5 digit-code to open a door or like in Last Crusade, a skull-organ to play to open the passage...

Ok, I can do single sprites for the objects to click that I can animate and each object will have a condition.
What kind of code you would use? Where to start... just the basics to start making this kind of puzzle.

I'm using the M9 verb, that one with function_item_AnyClick(); and verbs

Thanks

Andail

#1
Let's say you need to click four buttons in the correct order to open the door.
The buttons are:
A    B    C    D

And the right combination is
C    D    A    B

What you need to do now is declare an int, that we call "code."
Before any buttons are pushed, code is 0.
(at the top of room script)
int code;

Then you just start adding conditions.

For button C:
if (code == 0) code ++;   //increase "code" by one
else code = 0;   // otherwise reset "code"

For button D:
if (code == 1) code ++;
else code = 0;

For button A:
if (code == 2) code ++;
else code = 0;

For button B:
if (code == 3) code ++;
else code = 0;

So, whenever a button is pushed when it's not supposed to, the mechanism will be reset. If you keep pushing the buttons in the right order, the integer will increase.

You can use the repeatedly_execute to decide what will happen as soon as "code" is 4.

Khris

Or just unlock the door here:
Code: ags
  // button B
  if (code == 3) unlock_door();
  else code = 0;

Gabarts

#3
Nice :)

Thanks for this, I will try...

Ah, would be nice to add also a custom animation in case of wrong combination, in that case I need to assign the sprite view loop when code = 0?

SMF spam blocked by CleanTalk