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.

Code Snippets / [DBP] - Pseudo Random 3D Level Generator (no media req'd) (Matrix1 Utils)

Author
Message
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Aug 2011 00:33 Edited at: 18th Aug 2011 00:34
Here it is finally completed.

WLGfx's Pseudo Random 3D Level Generator for Dark Basic Pro.

This code will generate millions of random levels using the random seed and random generator. It will also generate random textures if you don't have your own to test it out. Each time it is run, the same levels will be generated from the same seed values.





Warning! May contain Nuts!

Attachments

Login to view attachments
aijing
12
Years of Service
User Offline
Joined: 18th Aug 2011
Location:
Posted: 18th Aug 2011 11:09
French gui
19
Years of Service
User Offline
Joined: 11th May 2004
Location: France
Posted: 18th Aug 2011 16:06
Quote: "ok"


@aijing: Come on, it's more than just 'ok'!

@WLGfx: Over ok!! Well done, thanks for the tut and sharing your code.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Aug 2011 16:33
Thanks 'French gui'... I'm just making a very crappy game using it with Sparkys then moving straight back on with C++ projects...

I release over 90% of my code to the public so that people can learn from it. Hope it's useful...

Warning! May contain Nuts!
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Aug 2011 20:48 Edited at: 19th Aug 2011 17:15
A quick Work In Progress sample of were I'm at. Uses Sparkys as well as Matrix1 Utils:

Uses keys - WASD+Space, Return-Jump, Mouse-Look



Warning! May contain Nuts!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Aug 2011 03:01 Edited at: 19th Aug 2011 03:02
I get ...Command out of place. Can't find the error though.



WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Aug 2011 06:36
The second piece of code replaced that function with the proper version of fmod(). Where the calls are placed they can actually be changed to leftval# %% rightval#
I was originally having trouble getting floats to work with the MODulus function, but I found out it was a typo instead...

Also the new function:

Hope it helps...

Warning! May contain Nuts!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 19th Aug 2011 14:45 Edited at: 22nd Oct 2011 14:25
This is a very impressive piece of code. I was wondering if the direction that draws the floor could be a user input instead of random. I can imagine this code being very useful random and possibly user defined as well.

[img][/img]
[ic:coffee

WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Aug 2011 16:15
Ok took out that code, and it works.

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Aug 2011 17:14
@Stab in the Dark software -
Quote: "I was wondering if the direction that draws the floor could be a user input instead of random."


By user input, the only way of doing this at the moment is by making some slight alterations to some of the variables before MG_generate() is called.

@Pincho Paxton - I'm made up you got it working finally. Hope some of the code helps you somehow.



There are a couple of vars that can be altered just before calling the MG_generate() function above that will make different levels.

MG_edge_angle, which is set to 45 degrees can be safely change between 30 and 70.

MG_rnd_mod, MG_rnd_add, MG_rnd_div, which is used in a formula to make a change to the new edges length. The current values will set the new edges length between 100 and 150. Tweaking these values will give the level a completely different look.

MG_max_faces, will define the maximum amount of floor faces (triangles) created. I believe this can upto a maximum of approx 20,000, but setting that will take a long time to generate.

count = array count( _OUT() ) will give the outer polygon edge count which is then used with these following functions:

x# = MG_center_x_out(edge) gets the center x coord of that edge
y# = MG_center_y_out(edge) gets the center y coord of that edge

NB: These coords are transformed into the 3D level object. Thus y# is transformed onto the Z axis.

angle# = MG_edge_angle_out(edge) gets the angle of that edge

The inner edges are very useful for the placement of objects, MG_center_x_in(edge), MG_center_y_in(edge), MG_edge_angle_in(edge) as I've demonstrated in the sample code demonstrating using it with Sparkys collision. This has been tested by adding this function


The last useful function I added was MG_clear_level() which removes all the data used by the level with a clean up, making it easier to switch to another level quickly.

NOTE: I've updated the previous sample code to use generate larger textures...

Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-02-25 15:28:07
Your offset time is: 2024-02-25 15:28:07