Jump to content

Numerous files vs large states


Drakira
 Share

Recommended Posts

I'm kind of a newbie at this, and working on a project that is probably way over my head.  But so far so good, I would just like some input from some more experienced programmers :)

The game involves the main character walking around on a top-down map, similar to Legend of Zelda: A Link to the Past or Chrono Trigger (when not fighting).  But when arriving at certain coordinates, I would like to trigger some sort of minigame, like when walking on a big stone overlooking a river, instead of the controls moving the character left/right/up/down using velocity, the character would jump from one lilypad to another (somehow, some of them can hold the character's weight) to cross the river, in a more frogger-like fashion.  Once the river is crossed, the movement with velocity resumes, creating a somewhat fluid experience.

I can get all that done with an event indicator in the update function.  If eventInd == null, then check for the arrow keys to move the character.  If eventInd == "riverJump", then check the arrow keys and do the jumping across the river.  That is the only "minigame" I currently have in mind for the maps, but I do want to expand on the game and add more.

Now my question:  My understanding is that at the start of the game, all states should be loaded and good to launch when needed.  So I either have my main game state with all those checks built in to the update function, and have one massive update function, or create multiple states, such as a regular game state for maps that have no minigames, a state for the map with the river crossing minigame, a state for the map with another minigame, etc, and have lots of duplicated code (player movement), making the states easier to keep track of and read, but more code loaded in memory.  Which would be preferable?

Thank you for taking the time to read my long post :)

Link to comment
Share on other sites

Instead of having your movement logic coded in the states themselves you can instead keep the code for movements in their own files. Whenever you make a state you can include whichever file has the movement code in the preload function for that state and in your update function call the movement file's own update function. That way you code each of your different movement types once and can reuse them in as many files as you want. Your code will be modular, that is, any changes you make to each movement file will be, by design, consistent on every state you use them in... etc

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...