[2D Sidescroll] Generating terrain based on random templates

Get help using Construct 2

Post » Sat Nov 28, 2015 8:39 am

R0J0hound wrote:There is a system action to set the layout size, but it's probably easier to just set the layout to unbounded and not worry about the layout's size.


Image
B
18
S
2
Posts: 48
Reputation: 896

Post » Sat Nov 28, 2015 2:39 pm

R0J0hound wrote:If you design the starting plain in the editor then it's just a matter of creating other terrain where the plain ends.

Let's consider creating the terrain to the right. You'll need two global variables for the X and y of the end of the terrain. You can set these values manually. Next you'll need a global variable to keep track of a random number. Your events could then look like this if each terrain piece was an object. Note the "---" means the event is a sub event.

Global number X=400
Global number y=409
Global number terrain=0

Start of layout
Repeat 10 times
> set terrain to int(random(3))
--- terrain = 0
--- > create forest at (X,y)
--- > add 200 to X
--- terrain = 1
--- > create hills at (X,y)
--- > add 300 to X
--- terrain = 2
--- > create grass at (X,y)
--- > add 400 to X

Start of layout
> create right_cliff at (X,y)


This is also assuming the values added to X are the width of the objects and the hotspot of the objects are positioned to the left.

Anything more deluxe can be done in a similar fashion. For instance the terrain could consist of multiple created objects or you could even set tiles on a tilemap is you so desire, just be sure the tilemap is wide enough.


Hi R0J0hound,

thanks for this, great and slim, solution! This is pretty much exactly what I needed! Tryed it out with a Little example - later today I gonna test it out and will upload the *.capx. maybe others will find this helpful, too!

Thanks, again!

Have a great Weekend,
Tan
B
19
S
10
G
9
Posts: 118
Reputation: 6,269

Post » Sat Nov 28, 2015 10:40 pm

Hi again,

I modified it a bit:


@R0J0hound, would you even recommend using tilemaps in such a Project? In the end the ground isnt animated, but it should be a detailed graphic? Is there a difference in Performance, when it Comes to "big tilemaps" (detailed groundtextures) instead of just putting in sprites? The borders are limited, not endless, but I havent got enough experience to decide, if it is even noticable in that case. Even through, working with sprites could be a bit more Handy.

The empty spaces in the left-generation-part are fixable with a bit of math - havent done that yet.


Have a great Weekend,
Tan

(once again: sorry for the spellchecking and autocorrecting from my browser, it doesnt wants me to write in other languages except the OS one)
B
19
S
10
G
9
Posts: 118
Reputation: 6,269

Post » Sun Nov 29, 2015 4:40 am

Proxymity wrote:Hi again,

I modified it a bit:


@R0J0hound, would you even recommend using tilemaps in such a Project? In the end the ground isnt animated, but it should be a detailed graphic? Is there a difference in Performance, when it Comes to "big tilemaps" (detailed groundtextures) instead of just putting in sprites? The borders are limited, not endless, but I havent got enough experience to decide, if it is even noticable in that case. Even through, working with sprites could be a bit more Handy.

The empty spaces in the left-generation-part are fixable with a bit of math - havent done that yet.


Have a great Weekend,
Tan

(once again: sorry for the spellchecking and autocorrecting from my browser, it doesnt wants me to write in other languages except the OS one)


Hey man, I saw what you did there and have been trying to come up with a way that will continually create terrain without the repeat loop since I assume you would want it to keep generating regardless of how long the player is running left or right?

This is probably the most simplistic way I could come up with, if you wanna have a look.

You could make the blocks invisible and change the size of the floor so that it is building outside the window,

Anyway here it is

https://onedrive.live.com/redir?resid=E ... ile%2ccapx
B
18
S
2
Posts: 48
Reputation: 896

Previous

Return to How do I....?

Who is online

Users browsing this forum: Jazz813, OddConfection, RetroSpock and 11 guests