Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sort of procedurally generated landscape?

Author
Message
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 21st Aug 2015 19:53 Edited at: 21st Aug 2015 19:55
I've been enjoying making classic games in AppGameKit and I was thinking that my next project should be Lunar Lander.

I was thinking about an approach regarding procedurally generating the landscape that the lander must travel over. And it's probably quite difficult to explain, but I'll try.

If I define a high of my landscape, for example between 0 and 10, this is not pixels but a arbitrary unit, And I then make a sprite where the mountain starts at say 8 on the left side and end on 5 on the right and as long as I then pick a sprite that starts with 5 these two sprites will appear to fit together.

So my approach is that I can randomly pick a starting sprite and as long as the next sprite has the same starting value as the previous sprites ending value the level would always appear new but also appear to fit together. The biggest drawback that I see is that I would have to create several sprites for each starting value in order to get a big variation of the levels.

Does this seem like a usable solution or can you see any big flaws, except for the fact that I can't draw anything?
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 26th Aug 2015 01:28 Edited at: 26th Aug 2015 01:42
Do you mean than the sprites would be trapezoid in shape?

If so then I'd generate the height map and then work out the triangle top that would be needed, something like this:



In this case I've limited to the height increments to +/-2 units, this would then require five triangles. So the difference between columns one and two is +1 so this would get top "a", the height difference between five and six is -2 so gets top "d".

To randomly generate the landscape you could do something like this:



Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB

Attachments

Login to view attachments
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Aug 2015 09:27 Edited at: 26th Aug 2015 09:51
I would recommend looking into the midpoint-displacement algorithm. It's a very easy way to generate a random 2D landscape. You could 'seed' it with initial values if you need particular heights along the 'mountain range' or just leave it to do its thing.

A very similar algorithm is often used for 3D terrains and it is then more commonly known as diamond-square but since I presume you are talking 2D then midpoint-displacement is fine

That will get you the 'points' on your terrain. As for getting them on screen - that's a whole different ballgame and it really depends on how you want it to appear.

1. If you want to go for the vector graphics look of the original than drawing lines across the top of the terrain would be fine.
2. If you prefer a filled terrain then having carried out step 1 you could use a fill algorithm on it.
3. If you want a textured surface then things gt a little more tricky.
   a. You could try creating a textured sprite and then warp the UVs to fit the terrain but I suspect it might stretch the texture a bit.
   b. If the sky (space) is a uniform colour then you could perhaps draw a flat landscape and cut the top out of it by overlaying warped sky sprites on it.

As for collision detection. Regardless of which method you use to draw the landscape, you can use the points array from the midpoint-displacement algorithm to generate a polygon and perform collision calculations on that.

I've just thought of another idea for drawing a textured terrain and I like it a lot!
Create an image that will cover the screen left to right (or tiled) and as far up as your mountain range will go. Put that image into a memblock and then run through it and check against the result of the M-D algorithm. If the point is outside the range (i.e not part of the landscape) then change the pixel value to full alpha making it invisible

AGK V2 user - Tier 1 (mostly)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Aug 2015 09:49
I used the same method as 29 Games in the game below.

Scraggle, useful link, bookmarked for another day



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 26th Aug 2015 20:34
@29 games, @BatVink, do I need to create sprites for every possible angle for the sprites on top of the "pilars" for the solution to work? Have I understood the problem correctly?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Aug 2015 11:17
It depends on your tiles. If they are textured, you will need sprites that are 1 tile and 2 tiles high for example. If your tile is textured in a specific direction (e.g horizontal bricks) then you will also need 1 and 2-tile wide sprites.

If they are just one colour, you can create a 1-tile angled sprite and stretch it. You can also rotate and mirror it to get everything you need.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 27th Aug 2015 12:00 Edited at: 27th Aug 2015 12:01
This thread inspired me to make a simple canon shooting game.

http://forum.thegamecreators.com/?m=forum_view&t=215283&b=48&p=0

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
gwargl
9
Years of Service
User Offline
Joined: 31st Aug 2015
Location:
Posted: 31st Aug 2015 21:15
Hi,

I think i've managed to port code from scraggle link.
I'm new to agk so it isn't perfect (as my english ).
For example, I've lost a couple of hour with integer/float (no) implicit conversion...

Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Sep 2015 00:11 Edited at: 1st Sep 2015 00:20
That's a nice scrolling terrain you have there

Rather coincidentally, I did one of these too.

Press W to toggle edge wrapping
Press Enter to change the seed

Hold Up or down and then press:
S to change the scale of the terrain.
P to change the amount of points to calculate along it.
R to change the roughness.

And since this thread was brought up because of a lunar lander project:
Press F to create a flat spot on the terrain to land on.

I was going to handle the collision next but I've got side-tracked (or rather, stopped being side-tracked) and got on with my main project.
However, all of the ponints that make up the terrain are stored in an array so it will be a very easy job to create a polygon collision mesh from them.

This is the terrain code. I've kept it separate so that it can be dropped into any project:


And this the 'main' file used to call the terrain functions and provide user input:


Oops!
I forgot about this. You will need to drop my display set up in there too:


If you are going to use this in a game then I would recommend using a different method to draw it.

AGK V2 user - Tier 1 (mostly)
gwargl
9
Years of Service
User Offline
Joined: 31st Aug 2015
Location:
Posted: 1st Sep 2015 10:49

Thanks for sharing !

Login to post a reply

Server time is: 2024-11-16 20:33:45
Your offset time is: 2024-11-16 20:33:45