2

And by "practical way" I mean in such a way that it may not hinder the game's speed.

I'm programming an RPG, and as many of you know, they're FULL of events:

  1. you walk into a new room where an event triggers

  2. some conversation happens to develop the story between the chars and npcs

  3. but then when you reenter that room nothing happens.

I coded my game so that every time the map changes (let's say it goes to map 6) it checks in the class EventReg.hx the Array of Bool if the value (in 6 in this case) is true and it is copied into the variable eventAvailable in PlayState.hx.

Then in the update function it runs the event according to the map number, but I feel that this approach would require a hell lot of code cramped in PlayState.hx in form of a switch (taking the value of the current map as reference).

Does anyone know of some open-source RPG, examples or tutorials that deal with this? TIA!

Example:

//Event Helper
private var eventAvailable:Bool;
private var currentMap:Int = MapReg.currentMap;

override public function create():Void
{
    //Checks if there's an even in the current map.
    eventAvailable = EventReg.isEvent[currentMap];
    if (eventAvailable)
        setupEvent();
}

private function setupEvent():Void
{
    switch(currentMap)
    {
        case 0: //code
        case 1: //code
    }
}
Gama11
  • 31,714
  • 9
  • 78
  • 100
  • Just some links that might help. Here's a haxeflixel rpg basecode project, which has events: https://github.com/kevinresol/flixel-rpg. And I also love msignal for events, which is not tied into haxeflixel (and thus doesn't have any sort of loop, may or may not be good.) https://github.com/massiveinteractive/msignal – 5Mixer Mar 30 '16 at 03:57
  • Where do you expect a performance bottleneck? The check for available events? A frame update function? I don't think this would make any difference to the performance at all unless you have hundreds of events going off in every room, which is unlikely. In general, performance is affected by image rendering, graphics, audio, loading and unloading of assets, et cetera, not game logic. – Aurel Bílý Mar 31 '16 at 13:09
  • I see, then I'll stick to that approach, thank you! – Gabriel Reinhart Allard Apr 02 '16 at 15:33

0 Answers0