Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Imran

I'm currently building a side scroller game where the level is generated dynamically as the player progresses.

The way I have it set right now is if the player reaches a certain distance away from the middle of the previous level "chunk" a new chunk is generated on the next screen as he progresses forward (the player can only move from left to right, not from right to left).

I've basically tried doing this by doing something like this:

LevelTest.layer[2].data[this.nextchunkstart][2]=3;

The problem is, I don't think the data object can take the variable thischunkstart - does anyone have any suggestions of a better way to do this?

And let me also apologize for how terrible my programming is, I'm still learning here!

1 decade ago by dominic

Check the Drop source code. It procedurally generates the level as you play the game. In Drop, everytime the map is extended by one row at the end, the first row of the map is removed. This is to ensure that map doesn't grow too large, but you may not need this optimization for your game.

I think the problem you currently have, is that you try to index an undefined value when you set the tile. Here's an example:

var map = [
	[1, 2, 3],
	[4, 3, 2]
];

map[2]; // 'undefined' - the array only has 2 rows
map[2][1]; // error, you can't index [1] on 'undefined'
// i.e. undefined[1] makes no sense

// If you want to insert a new row, you first have to create the 
// new row as an array:
map[2] = [];
map[2][1] = 3;

1 decade ago by Imran

Dominic, thank you for the support!

I will give this a try.

Cheers,

Imran

1 decade ago by Imran

Thanks for the help Dominic, it turns out you were right on the money!

How would I go about deleting & generating columns where the first 100 columns of a level are defined in a level file built in Welmeister?

Basically, I want the game to be an "endless" platformer but I don't know how to extend a level beyond its endpoint.

Thanks!

Imran
Page 1 of 1
« first « previous next › last »