# What is the best way to display a large number of levels?

**URL:** <https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119>\
**Category:** Newbie Questions\
**Created:** [May 12, 2017, 8:13pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119 "2017-05-12T20:13:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 12, 2017, 8:13pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/1 "2017-05-12T20:13:48Z")

</div>

In my game, I am thinking of having hundreds of levels. But I also want a system where there are beginning levels, than harder levels with the same enemies, just more buffed and so on so forth:

For example:&nbsp;

Korea, 1 Star, Enemy Buff = 100%&nbsp;

Korea, 2 Star, Enemy Buff = 120%

Korea, 3 Star, Enemy Buff = 140%

But with the same enemies.&nbsp;

How would I be able to accomplish this?

I am assuming with an array of level names, but I would not know how to call the names and .lua files to go to.

---

<div class="post-metadata">

**Author:** ![bjsorrentino](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bjsorrentino](https://forums.solar2d.com/u/bjsorrentino)\
**Post date:** [May 12, 2017, 9:08pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/2 "2017-05-12T21:08:07Z")

</div>

Hi @sdktester15,

Instead of designing hundreds of levels with minor variances, wouldn’t it be better to just increase/decrease the stats, number of enemies, power of enemies, etc. within the same core level? Just a thought… I mean, you could _present_ a list of hundreds of levels to the user, but the level code itself probably should be duplicated hundreds of times, since that would be a vast amount of extra work for you.

Brent

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [May 12, 2017, 10:06pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/3 "2017-05-12T22:06:46Z")

</div>

You should only have one _level.lua_ and have _level1.json, level2,josn_, etc.

The json files store the level definition and enemy stats. &nbsp;You then load each level into the single _level.lua_ and it processes the json and adapts accordingly. &nbsp;How you do this is up to you.

This is how all multi-level games work, like Candy crush for example.

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 12:31am UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/4 "2017-05-13T00:31:22Z")

</div>

> [@bjsorrentino](#):
>
> Hi @sdktester15,
> 
> Instead of designing hundreds of levels with minor variances, wouldn’t it be better to just increase/decrease the stats, number of enemies, power of enemies, etc. within the same core level? Just a thought… I mean, you could _present_ a list of hundreds of levels to the user, but the level code itself probably should be duplicated hundreds of times, since that would be a vast amount of extra work for you.
> 
> Brent

I’m not sure what you are talking about. Could you please explain more? What do you mean within the “same core level”?

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 12:31am UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/5 "2017-05-13T00:31:42Z")

</div>

> [@anon63346430](#):
>
> You should only have one _level.lua_ and have _level1.json, level2,josn_, etc.
> 
> The json files store the level definition and enemy stats. &nbsp;You then load each level into the single _level.lua_ and it processes the json and adapts accordingly. &nbsp;How you do this is up to you.
> 
> This is how all multi-level games work, like Candy crush for example.

Thanks, do you know of any good tutorials to do this?

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [May 13, 2017, 12:45am UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/6 "2017-05-13T00:45:25Z")

</div>

Your json will be a representation of your level map. &nbsp;You will load that and set up your level,

Maybe look into tiled for this? &nbsp;This is a good starting point -&nbsp;[https://coronalabs.com/blog/coronageek/corona-geek-186-using-tiled-map-editor-for-level-design-with-corona/](https://coronalabs.com/blog/coronageek/corona-geek-186-using-tiled-map-editor-for-level-design-with-corona/)

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 12:36pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/7 "2017-05-13T12:36:00Z")

</div>

> [@anon63346430](#):
>
> Your json will be a representation of your level map. &nbsp;You will load that and set up your level,
> 
> Maybe look into tiled for this? &nbsp;This is a good starting point -&nbsp;[https://coronalabs.com/blog/coronageek/corona-geek-186-using-tiled-map-editor-for-level-design-with-corona/](https://coronalabs.com/blog/coronageek/corona-geek-186-using-tiled-map-editor-for-level-design-with-corona/)

I am not going to be using tiled, it will just be a background, where enemies move toward the player’s base, and the player’s units move towards the enemy base and fight. Like this:

[![](https://forums.solar2d.com/uploads/default/original/2X/5/56e7cf6d55fc4606721c016af0601c57750b83ad.jpeg "The Battle Cats - Parade of the Dead (New Deadly Stage)") ](https://www.youtube.com/watch?v=ZoxOtSDETMc)

At 1 minute in, he explains the buffing.&nbsp;

Also, would JSON handle increasing the enemy stats?

I would just like a tutorial that covers JSON in general for Lua, I will be looking around as well.

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 1:07pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/8 "2017-05-13T13:07:53Z")

</div>

I found this tutorial:

[https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/](https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/)

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [May 13, 2017, 1:38pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/9 "2017-05-13T13:38:12Z")

</div>

Ah… you could just scale stats by level to keep things simple

```
attack = 100 + levelNumber hp = 50 + mfloor(levelNumber/2)

```

etc…

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 1:40pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/10 "2017-05-13T13:40:31Z")

</div>

Is there a way to set some sort of predetermined buff value? For example: if the stage is a 2 star stage, the buff will automatically be 120%.

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 1:41pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/11 "2017-05-13T13:41:22Z")

</div>

> [@anon63346430](#):
>
> Ah… you could just scale stats by level to keep things simple
> 
> ```
> attack = 100 + levelNumber hp = 50 + mfloor(levelNumber/2)
> 
> ```
> 
> etc..

Some levels will not be in numerical order, some will be special 1 time levels.

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [May 13, 2017, 2:26pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/12 "2017-05-13T14:26:07Z")

</div>

Here is an example json you could start from

```
[&nbsp; {"level":1, "star":1, "attack":100, "hp":50}, &nbsp; {"level":1, "star":2, "attack":120, "hp":75}, &nbsp; {"level":2, "star":1, "attack":115, "hp":60}, &nbsp; {"level":2, "star":2, "attack":135, "hp":80},

```

]

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 7:46pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/13 "2017-05-13T19:46:51Z")

</div>

Ok, so how would I spawn different enemies or change backgrounds? Assuming level1 in this case is entirely different level 2, how would I spawn different enemies?&nbsp;

Also, would I just make the one-time special levels separately?

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [May 13, 2017, 8:05pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/14 "2017-05-13T20:05:42Z")

</div>

I can’t write your game for you… btw, my entire game is stored in json.

You gotta work it out for yourself. &nbsp;Start small and then extend.

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 13, 2017, 8:36pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/15 "2017-05-13T20:36:19Z")

</div>

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [May 15, 2017, 2:38am UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/16 "2017-05-15T02:38:56Z")

</div>

JSON is a perfectly good way to do this, but so is a Lua file. &nbsp;Here’s a snippet from my game:

```
local M = {} M[1] = { droneType = 1, droneMovement = "straight", spawnSpeed = 3000, spawnCount = 20, bossType = 1, microDroneType = 0, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 100, freezeChance = 0, toxicChance = 0, nukeChance = 0 } M[2] = { droneType = 2, droneMovement = "sweep", spawnSpeed = 2750, spawnCount = 20, bossType = 2, microDroneType = 0, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 98, freezeChance = 2, toxicChance = 0, nukeChance = 0 } M[3] = { droneType = 3, droneMovement = "seek", spawnSpeed = 2500, spawnCount = 20, bossType = 1, microDroneType = 0, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 96, freezeChance = 4, toxicChance = 0, nukeChance = 0 } M[4] = { droneType = 0, droneMovement = "", spawnSpeed = 3000, spawnCount = 20, bossType = 2, microDroneType = 1, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 94, freezeChance = 6, toxicChance = 0, nukeChance = 0 } M[5] = { droneType = 0, droneMovement = "", spawnSpeed = 3000, spawnCount = 0, bossType = 9, microDroneType = 1, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 94, freezeChance = 6, toxicChance = 0, nukeChance = 0 } ... return M

```

In here I store the enemy for that level (droneType). I have a different table to managing the backgrounds, but I store the file names of the background&nbsp;

Rob

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [May 15, 2017, 10:00am UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/17 "2017-05-15T10:00:25Z")

</div>

What is your game Rob?

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 15, 2017, 11:00am UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/18 "2017-05-15T11:00:14Z")

</div>

> [@rob](#):
>
> JSON is a perfectly good way to do this, but so is a Lua file. &nbsp;Here’s a snippet from my game:
> 
> ```
> local M = {} M[1] = { droneType = 1, droneMovement = "straight", spawnSpeed = 3000, spawnCount = 20, bossType = 1, microDroneType = 0, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 100, freezeChance = 0, toxicChance = 0, nukeChance = 0 } M[2] = { droneType = 2, droneMovement = "sweep", spawnSpeed = 2750, spawnCount = 20, bossType = 2, microDroneType = 0, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 98, freezeChance = 2, toxicChance = 0, nukeChance = 0 } M[3] = { droneType = 3, droneMovement = "seek", spawnSpeed = 2500, spawnCount = 20, bossType = 1, microDroneType = 0, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 96, freezeChance = 4, toxicChance = 0, nukeChance = 0 } M[4] = { droneType = 0, droneMovement = "", spawnSpeed = 3000, spawnCount = 20, bossType = 2, microDroneType = 1, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 94, freezeChance = 6, toxicChance = 0, nukeChance = 0 } M[5] = { droneType = 0, droneMovement = "", spawnSpeed = 3000, spawnCount = 0, bossType = 9, microDroneType = 1, microDroneMovement = "straight", microDroneSpawnPattern = "wall", spawnHealthRate = 20000, spawnPickupRate = 30000, energyChance = 94, freezeChance = 6, toxicChance = 0, nukeChance = 0 } ... return M
> 
> ```
> 
> In here I store the enemy for that level (droneType). I have a different table to managing the backgrounds, but I store the file names of the background&nbsp;
> 
> Rob

So, how would you put these to use as a level? I understand its a module, so do you have some preset parameters and tell which the level which table to use?

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [May 15, 2017, 4:10pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/19 "2017-05-15T16:10:31Z")

</div>

You would do something like:

```
local levelData = require("leveldata") local currentLevel = 1 local function spawnSomething( ) &nbsp; &nbsp; &nbsp; &nbsp;local thisEnemy = levelData[currentLevel].droneType &nbsp; &nbsp; &nbsp; &nbsp;local spawn = display.newImageRect(drones[thisEnemy].filename, drones[thisEnemy].width, drones[thisEnemy].height) &nbsp; &nbsp; &nbsp; &nbsp;spawn.movement = thisEnemy.droneMovement &nbsp; &nbsp; &nbsp; &nbsp;... -- etc. end

```

Now I have other tables that hold other information like:

```
local droneData = {} droneData[1] = {} droneData[1].exhaustOffset = { x = -5, y = 0 } droneData[1].fireOffset = { x = 0, y = 0 } droneData[1].health = 1 droneData[1].points = 100 droneData[1].speed = 1 droneData[1].damage = 1 droneData[1].guns = 1 droneData[1].fireSpeed = 900 droneData[1].seeks = false droneData[1].sweeps = false droneData[2] = {} droneData[2].exhaustOffset = { x = -18, y = 5 } droneData[2].fireOffset = { x = -20, y = 12 } droneData[2].health = 2 droneData[2].points = 200 droneData[2].speed = 1 droneData[2].damage = 1 droneData[2].guns = 1 droneData[2].fireSpeed = 850 droneData[2].seeks = false droneData[2].sweeps = true

```

which olds the table for each enemy. The levelData has things like spawn rates, speeds, etc. I have another table that holds things like the different background images for each level:

```
M.levelsPerCampaign = 5 M.campaign = {} M.campaign[1] = {} M.campaign[1].name="San Fransciso" M.campaign[1].startLevel = 1 M.campaign[1].endLevel = 5 M.campaign[1].minimumStars = 0 M.campaign[1].mapLocation = { x = -98, y = -11 } M.campaign[1].layers = 3 M.campaign[1].layer = {} M.campaign[1].layer[1] = {} M.campaign[1].layer[1].type = "gradient" M.campaign[1].layer[1].start = { 0.0666, 0.0319, 0.0000} M.campaign[1].layer[1].stop = { 0.5906, 0.2542, 0.0000} M.campaign[1].layer[2] = {} M.campaign[1].layer[2].type = "image" M.campaign[1].layer[2].images = {} M.campaign[1].layer[2].images[1] = { filename = "images/sanfran01.png", width = 1201, height = 375 } M.campaign[1].layer[2].images[2] = { filename = "images/sanfran02.png", width = 1201, height = 375 } M.campaign[1].layer[2].images[3] = { filename = "images/sanfran01.png", width = 1201, height = 375 } M.campaign[1].layer[2].images[4] = { filename = "images/sanfran02.png", width = 1201, height = 375 } M.campaign[1].layer[3] = {} M.campaign[1].layer[3].type = "image" M.campaign[1].layer[3].images = {} M.campaign[1].layer[3].images[1] = { filename = "images/buildings01.png", width = 1024, height = 512 } M.campaign[1].layer[3].images[2] = { filename = "images/buildings02.png", width = 1024, height = 512 } M.campaign[1].layer[3].images[3] = { filename = "images/buildings03.png", width = 1024, height = 512 }

```

In this case I have two parallax images going at different speeds. The buildings are closer to the player so they move faster. The skylines are further away so they move slowly and the gradient is used to create different sky conditions (bright and sunny, overcast, night time, dusk, etc.)

@Sphere Game Studios, it’s a side-scrolling sci-fi shooter. You have a ship and blast your way through waves of alien ships, picking up health/repair pods and weapons to use. Killing each enemy has a chance to drop coins that you can pick up to buy upgrades to your ship.

It’s nearly ready to show publicly, but I’ve been so busy with life, I’ve not touched it in a couple of months. It’s built from the ground up to be played with a keyboard/mouse, controller and touch and designed for TV shaped screens. But lets not hijack this tread. I need to man-up and post it in the Works in Progress forum.

Rob

---

<div class="post-metadata">

**Author:** ![Blex](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@Blex](https://forums.solar2d.com/u/Blex)\
**Post date:** [May 15, 2017, 8:37pm UTC](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119/20 "2017-05-15T20:37:15Z")

</div>

Wow, this is incredibly helpful. Thanks!

[Next page](https://forums.solar2d.com/t/what-is-the-best-way-to-display-a-large-number-of-levels/344119.md?page=2)
