Different keys for different doors

0 favourites
  • 6 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hello everyone!

    I have a simple game where I have different doors, so only one kind of key should open those doors.

    For start I have two kinds of keys, blues and reds. But I'm having trouble figuring out how I make the blue keys open only the blue doors and the red keys open only the red doors. Right now both keys are opening both doors.

    Can anyone take a look? Here is my .capx file: https://dl.dropboxusercontent.com/u/8017129/C2%20Forum%20Files/keys-and-doors.capx

    <img src="http://i.imgur.com/DV4fPKNl.png" border="0">

  • Use an instance variable

  • I still don't know much about arrays in construct, but it seems that the game doesn't know if the key is red or blue. It seems that it only identifies it as a key, regardless of the color. (I understood almost nothing in your file. I don't know if that's my lack of experience in using arrays in Construct 2 or lack of organization of your part)

    I don't know how to do it in inventory using an array, but I'll do something like this:

    Create a red key and blue key sprite

    Create a variable inside these sprites that holds a value of how many was found (redKeyQuantity = 0)

    If player collides with red key, adds a number to redKeyQuantity. Same with blue key, adding to blueKeyQuantity.

    When player collides with a red door, check to see if redKeyQuantity is greater than 0. If yes, open door and subtracts 1 from redKeyQuantity. If not, don't let the player pass! The same for blue.

    Well, that is the way I would do it. I don't know how to do it with an inventory array, but I guess the logic is the same. Maybe there's a more efficient way to do it, but I think this way is very easy to understand and not difficult to modify later if you need.

  • Well, me thinks this is what you're after. Do note I modified pretty much all of the code and removed unneeded items. The doors do not prevent you from crossing them, if you have no key, as I figure you can add such a simple lot of code.

    Hope you enjoy - dl.dropboxusercontent.com/u/108799982/Capx%20Demos/DoorsAndKeys.capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, me thinks this is what you're after. Do note I modified pretty much all of the code and removed unneeded items. The doors do not prevent you from crossing them, if you have no key, as I figure you can add such a simple lot of code.

    Hope you enjoy - dl.dropboxusercontent.com/u/108799982/Capx%20Demos/DoorsAndKeys.capx

    Thank you so much emoaeden! I really don't know how to thank you for that. It really helped me and it's well done, very well done. It's a lesson learned! Thank you again!

  • Anytime mate, maybe one day you can do the same:for ithers on here :-)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)