## Creating an "endless runner" that isnt random?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

### Creating an "endless runner" that isnt random?

I couldnt think of a short way to describe what i mean. Basically I'm making a game like an endless runner, except it isnt endless. I want to have levels that you can complete, but it still plays like an endless runner. What I'm trying to do is make each level have a planned x,y coor for each platform to spawn, but I dont know how i would go about this. I've thought about having a "level_1" function or class, with a table that lists each x and y coor, but I feel like this is wrong. I haven't tried it yet but that was my main way of thinking it would be done, but I feel like that either wouldnt work, or would just be really slow. So I'm wondering if there is a better solution?

I'm not looking for exact code, just the general principle of how it would work (although i wouldnt say no to examples c;)

Thanks to anyone willing to help me

raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### Re: Creating an "endless runner" that isnt random?

If you don't want it random, just straight up use a level editor. Otherwise, use specific random seed: the random is actually pseudo-random and is deterministic, if you start with specific value you'll get the same string of random numbers every time. Same applies to noise, except it requires that you specify seed value each time - "normal" random generator will use its last return value as next seed.

Jasoco
Inner party member
Posts: 3651
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: Creating an "endless runner" that isnt random?

If you do use a specific random seed, make sure to use love.math instead of just math so that the level ends up being the same across platforms.

But yeah, just make levels manually.

Santos
Party member
Posts: 383
Joined: Sat Oct 22, 2011 7:37 am

### Re: Creating an "endless runner" that isnt random?

Try thinking about "what makes each level different?" and then storing that information in tables.

For example... (I'm thinking of a Canabalt style game here)

"The only difference between each platform the runner jumps on is its height, everything else is the same or random (width of platform, gap between platforms, etc.), so I only need to store the heights."

Code: Select all

level = {
22,
198,
74,
130,
128,
87,
9,
127,
}


"Each platform has its own height, length and gap until the next platform, and there are items on some of the platforms."

Code: Select all

level = {
{
height = 22,
length = 300,
gap = 18,
items = {
{
type = 'coin',
xOffset = 98,
},
{
type = 'barrel',
xOffset = 208,
},
{
type = 'coin',
xOffset = 280,
},
},
},
{
height = 198,
length = 103,
gap = 25,
items = {},
},
{
height = 74,
length = 180,
gap = 10,
items = {
{
type = 'barrel',
xOffset = 98,
},
},
},
{
height = 130,
length = 403,
gap = 31,
items = {
{
type = 'barrel',
xOffset = 98,
},
},
},
}


"There are multiple levels and each level has a name which is displayed when you enter it, and the player runs at different speeds in different levels."

Code: Select all

levels = {
[1] = {
name = 'The first level',
speed = 10,
platforms = {
{
height = 22,
length = 300,
},
{
height = 198,
length = 103,
},
{
height = 74,
length = 180,
},
},
},
[2] = {
name = 'Faster level',
speed = 33,
platforms = {
{
height = 122,
length = 200,
},
{
height = 198,
length = 103,
},
{
height = 74,
length = 180,
},
},
},
[3] = {
name = 'Faster still!',
speed = 41,
platforms = {
{
height = 22,
length = 300,
},
{
height = 198,
length = 103,
},
{
height = 74,
length = 180,
},
},
},
}


(But, I would suggest doing one thing at a time. Like, gets heights working first, then lengths of platforms, etc.)

I'd also suggest trying something out even if you think it won't be a great solution, because you may get an idea of what a better solution would be, and plus if you post what you have on the forums then people might be able to give more precise suggestions.

### Who is online

Users browsing this forum: AlexYeCu, ReFreezed and 27 guests