0 Favourites

More than one active layouts

  • Hello everyone.

    For two weeks now I am focused on a new project that I intend to share with you soon. But I feel a danger aproaching and would like to ask for your help before it's too late.

    In my (real time) game, I will need an interior level (an inn per se), and an exterior level(wilderness). There will be many npc's doing various jobs outside, and they will frequent the inn. So how will I handle wilderness events when the player is inside the inn? I will have switched the layout to inside, so wilderness events will stop, right? But I still need my rangers to scout for game, and hunt if they see them. I need my burglars to attack caravans, in real time, even when the player is inside.

    The reverse is also true, people inside the inn should be doing their jobs even when the player is outside, in realtime.

    And NPC's and player should be able to come in or get outside as they need to...

    AI part of the NPC's are done, but I don't know how to do both places active in the same time. I did a quick search but couldn't find something similar. Anyone had such an experience? Should I just hide inside of the inn far away from the wilderness in the same layout and switch camera positions?

    Thanks in advance,

    -Wind.

  • The best approach to games like this one is to separate the logic/ai from the visuals. All the scouting, hunting, attacking, cooking, serving drinks, etc. should be managed with variables, arrays and dictionaries. You can then hook in to whatever part of the world is currently visible and link the appropriate sprites with the data.

    Such seperation would be done with one or more global event sheets (for the calculation parts) that you include in every layout.

  • tulamide thanks. In fact I feared for such a thing, because it seems there is a lot to take into consideration when trying to move them into logic. (pathfingin location, destination, current state of HP, hunger, task, line of sight and all the other actions... How am I going to create a "virtual machine" layout that keeps track of all these and turns them into display when needed?

    I'm afraid I am not that hot with Construct 2 yet. Could you direct me to an example of how this can be implemented?

    Thanks again;

    -Wind.

  • Unfortunately I don't know of any C2 example. It sure is a huge project and you would be more of a database administrator than a developer, but once managed it is very easy to extend, for example.

    You wouldn't work on a layout but a separate event sheet. Create it on the first of all your layouts and use 'include event sheet' to add it to each layout (even the first one).

    Things, you'd have to manage, are not easy though. For example the hunting. Begin with the speed, direction and position of the animals. Some math will let you keep track of their positions that are stored in some table.

    animal a, 100, 120

    animal b, 200, 300

    etc.

    Now you need math for the scouting of the hunters. Where are their positions, what is their scout range, is any of the animals within range. If so, a hunter's table would be updated

    hunter a, 180, 240, in range, animal b

    Now he sneaks towards the animal and tries to kill it. Math again to keep track of position and luck/bad luck when trying to kill.

    And so on.

    But, when all this happens, while the player is inside the inn, it's simple math that's calculated fast. And whenever the player enters the wilderness, you just need to lookup your tables to see what you need to display (player is near a hunter, or near some animals, whatever). You look up those values and set the appropriate sprites to those coordinates, check the animations/frames) etc.

    Yes, it is a whole lot of effort. But I wouldn't know of any easier method that's equally versatile...

    But without above method you can of course try to work on one layout, offsetting all wilderness items when player is in the inn and vice versa. It makes it harder to maintain though.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • tulamide thanks for the explanation. I will have to try since it's the natural way and it would possibly be the first time it's done in C2 :) I know I will probably fail but I think it will be a challenge that teaches great amount of things. I am not very good with maths but will have to figure sth out.

    Meanwhile, any of you out there with any other aproach or more detailed explation on tulamide's offer for solution; all help is welcome :)

    Regards;

    -Wind.

  • Another option if you already have a lot done:

    You could hide the layers of the background, and make the layers of inside space appear. You could put all interaction with each environment in a group, and disable the group when that layer is hidden, so you can't click on the exterior door, or woodland creatures, for example.

  • Paradox thanks, I will try that as well. However, I really wish there was a way to keep more than one layout active while displaying only one of them. How do people manage NPC's chasing players between levels anyway?

    Regards;

    -Wind.

  • There is "Persist" behavior, but what you want sounds like it may still require tracking in the events, because Persist can return to a layer in progress, but it would be paused while you were away.

    https://www.scirra.com/manual/161/persist

  • Paradox yes, exactly. Doing it mathetmatically in a "game loop" is not impossible, though the hardest part is to simulate the pathfinding behaviour I think.

    The inn problem is not that hard. I can use the inn within the same layout with wilderness and prevent interaction between them. But inn is not the only place. There is also the mines, which is entirely something else. I thought of keeping everything in one huge layout but it will bog down eventually, especially with a hundred npc's trying to pathfind around, all the while searching for their prey or chasing whatever tasks they have.

    Will read more through the manual and tutorials, maybe something will come up. Meanwhile, please keep the advices flowing; especially any example of the mathematical solution would be welcome.

    Regards & thanks for help;

    Wind.

  • i.e. I need persistent events :)

  • Ok, If I was in your situation, I would probably pause the layout and record how long they were away. When I loaded it back up, I would sit the player on a load screen for a few seconds while I simulated that much time passed by. Hopefully there are shortcuts you could take, like finding one path (trip) for woodcutting, but retrieving a dozen trips worth.

  • I'm not 100% sure on how well it work performance wise, as I feel tulamide's idea would be the best in the long run, but you could use multiple layers.

    Separate layers for exterior, interior, npc's and player... when the player moves inside you hide the exterior layer and show the interior.

    You would probably need some kind of reference/spawn point to re-position the player during the transition.

    Then use a variable "location" for the npc's that could be checked for when they are outside or in the inn to enable/disable there visibility.

    Just a thought

  • arontwose thanks for the advice, though I am still worried about how to handle collision checks, line of sight and path finding in the invisible layers. Somehow they have to keep working but not interact with the currently active layer on top of them. Transitions and movement between them is the least of my worries :)

    If I cannot find a better way I will put them all in the same layer, lower the size and resolution of all objects and hope for the best in terms of performance. I think I will need a layout of 30000 x 30000. Anyone has experience with layouts of this size? Or any other ideas about my problem?

    Regards;

    -wind

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