Episode 10: Missions

Like items and entities, mission information is stored in a JSON file. This file is called missions.json, and it specifies the mission settings.

Unlike items and entities, missions don’t have presets (at least not yet). They just have a few properties that can be customized using the mission maker.

Stats

Here are the stats of a mission:

  • Entities: the entities
  • Size: number of entities
  • Speed: delay between entities
  • Level: level of entities
  • Ally faction: faction of rewards
  • Enemy faction: faction of entities
  • World: background image

I’ll talk more about how the mission maker works in the next episode. In the meantime, here’s how a mission is launched:

The player selects and activates the menu option that launches a mission…

The mission factory then starts the play state…

The reason that the menu doesn’t directly launch the play state is that we want each factory to be responsible only for its own stuff. If you think about it, the menu factory shouldn’t really be launching missions – it should be asking the mission factory to launch a mission.

After figuring out how to store missions as objects, I ended up storing all of the missions in a single file, but I originally had the mission factory pass the index into the play state so that we could read the JSON file for that specific mission. Here’s how that would work:

From the mission’s init function, we remember the index parameter…

Then  we ask the mission factory to load the mission by index from the preload function…

This would probably be more useful for large numbers of large files, but the missions are pretty small and simple.

Entities

Whatever way we choose to lead the mission, we update the mission factory from the play state’s update function…

The mission factory’s update method will create the mission’s entities, which are read row-by-row…

It may not be pretty, but it works.

Size

The mission’s entities are read row-by-row, like a two-dimensional array or a grid. The mission’s size determines how the width and number of rows. Here are the size presets listed in mission.json:

Speed

The mission’s speed determines the delay between the rows as well as the delay at the start of the mission. Here’s what the presets look like:

I’ve also considered having the mission’s speed determine the speed of scrolling entities as well as the background, but I haven’t decided how to implement that.

Level

The mission’s level just determines the level of the entities. For enemies, this determines the level of their items. For obstacles and drops, it affects the stats directly.

The rest of the mission stats are pretty self-explanatory. The enemy faction, like the level, determines the faction of entities. As it stands, obstacles aren’t affected by faction, but that could change.

Stay tuned for the next episode, when I’ll show you how missions are created using the mission maker!

Leave a Reply