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

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: 

Korea, 1 Star, Enemy Buff = 100% 

Korea, 2 Star, Enemy Buff = 120%

Korea, 3 Star, Enemy Buff = 140%

But with the same enemies. 

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.

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

You should only have one level.lua and have level1.json, level2,josn, etc.

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

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

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

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

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

Maybe look into tiled for this?  This is a good starting point - 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://www.youtube.com/watch?v=ZoxOtSDETMc

At 1 minute in, he explains the buffing. 

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.

I found this tutorial:

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

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

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

etc…

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%.

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

Here is an example json you could start from

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

]

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? 

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

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

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

Thanks for the help!

JSON is a perfectly good way to do this, but so is a Lua file.  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 

Rob

What is your game 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?

You would do something like:

local levelData = require("leveldata") local currentLevel = 1 local function spawnSomething( )        local thisEnemy = levelData[currentLevel].droneType        local spawn = display.newImageRect(drones[thisEnemy].filename, drones[thisEnemy].width, drones[thisEnemy].height)        spawn.movement = thisEnemy.droneMovement        ... -- 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

Wow, this is incredibly helpful. Thanks!