Tree Data Structure

Get help using Construct 2

Post » Mon Mar 18, 2013 10:48 am

Hello guys,

Any idea how to save tree data structures in C2 - e.g. SpriteUID's? I need it to save a BSP tree of sprites for procedurally generated dungeon.

http://roguebasin.roguelikedevelopment.org/index.php?title=Basic_BSP_Dungeon_generation

I can save this information in local variables of sprites, but i think may be using data structures is nicer.

Cheers
B
45
S
11
G
4
Posts: 515
Reputation: 7,389

Post » Mon Mar 18, 2013 11:00 am

Use arrays/dictionaries. The data structures behind them are (probably) the most efficient for the use anyways. If you want to build a tree structure of some sort, you'll probably do it as a list anyway and use functions to read/save items as a tree.
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Tue Mar 19, 2013 7:41 pm

You can also use a sprite per leaf of the tree with three instance variables: parent,child1 and child2 to store the UIDs of those leafs or -1 for nothing.

Example of building a tree:
http://dl.dropbox.com/u/5426011/examples17/bsp.capx
B
88
S
30
G
90
Posts: 5,114
Reputation: 60,839

Post » Tue Mar 19, 2013 7:43 pm

Edit : nevermind...Whiteclaws2013-03-19 19:44:46
B
41
S
17
G
17
Posts: 2,247
Reputation: 17,436

Post » Tue Mar 19, 2013 10:55 pm

Oh, thanks R0J0hound for an example (it's very clean). I managed to do it like this:

https://www.dropbox.com/s/yjjfdwxw0dxtqji/roglike.capx

Right now I'm trying to figure out what is the best way to connect chambers. I thought about using a test-sprite and scaling it into a 4 directions and than test if it overlaps. Or may be pathfinding. Is there any C2 specific techniques for this kind of stuff?xoros2013-03-19 22:57:59
B
45
S
11
G
4
Posts: 515
Reputation: 7,389

Post » Tue Mar 19, 2013 11:16 pm

Well , I'm also doing a procedural dungeon generator myself , And yes , pathfinding ... If I find something , I'll hook you up with it :D

@R0J0hound , hay , R0J0 how about a sprite that find it's way to the nearest checkpoint and then deletes it and goes the the neareast again in a loop ? How would you do that ?
B
41
S
17
G
17
Posts: 2,247
Reputation: 17,436

Post » Wed Mar 20, 2013 7:49 am

[QUOTE=Whiteclaws] Well , I'm also doing a procedural dungeon generator myself , And yes , pathfinding ... If I find something , I'll hook you up with it :D

@R0J0hound , hay , R0J0 how about a sprite that find it's way to the nearest checkpoint and then deletes it and goes the the neareast again in a loop ? How would you do that ?[/QUOTE]

sprite is lookingForCheckpoint
for each sprite
pick checkpoint nearest to sprite x,y
.. sprite.lookingForCheckpoint = false;
.. sprite find path to checkpoint
.. go there

sprite arrives to checkpoint
.. delete checkpoint
.. sprite.lookingForCheckpoint = true;
B
24
S
9
G
7
Posts: 756
Reputation: 7,292


Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, Baidu [Spider], dzert14, FabianB, hossein, reddragon09 and 9 guests