Terraria Style Tree Generation From Saplings?

Get help using Construct 2

Post » Sun Jun 23, 2013 4:33 pm

Whatsup peeps,

I got a question about trees. How can i make trees that are in parts spawn as a whole trees
But at the same time having the tree still able to be destroyed?

I will have it so the player can grow trees at any time. I know how to do this with regular code I just dont understand how to do it in construct 2
B
9
S
5
Posts: 126
Reputation: 1,295

Post » Sun Jun 23, 2013 9:25 pm

Anybody have a clue?
The only anwser I would have is just making it easier but I dont want that. If someone has aclue im all Ears.thanks in advance
B
9
S
5
Posts: 126
Reputation: 1,295

Post » Sun Jun 23, 2013 9:57 pm

Let's see...
You could have something like this :

globals :
- treeGrowingTick
- treeMinHeight
- treeRandomHeight

treeBase sprite :
- isActive (boolean, true on create)
- currentHeight (int, 1 on create)
- targetHeight (int)
treePart sprite :
- treeBaseID (int)
- initial frame is the top of the tree

TreeSpawning :
- spawn a "treeBase" sprite,
- set targetHeight to round(random(treeRandomHeight)+treeMinHeight),
- call "treeActualise"(treeBase.UID)

on Function treeActualise,
Pick treeBase by UID,
if treeBase.currentHeight < treeBase.targetHeight
Pick TreePart by comparaison (treeBaseID = treeBase.UID):
- wait (treeGrowingTick)
- set TreeBase frame to something more suitable
- set treePart Frame to the middle of the tree
- Spawn treePart at X=treeBase.X, Y=treeBase.Y+(treePart.PickCount+1)*treePart*height
- set treePart.treeBaseID to treeBase.ID

on Function treeDestroy (called with the treeBase UID as a parameter, making the tree base a good candidate for a "HP" variable ^^)
Pick TreePart by comparaison (treeBaseID = treeBase.UID):
- spawnLoot
- treePart.destroy
- treeBase.destroy

As you can see @TheNewGuy , I've written this directly on the forums, didn't test it. I hope it does the trick :)Guizmus2013-06-23 21:58:19
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Sun Jun 23, 2013 10:02 pm

@Guizmus   Thanks bro,

I was looking for a way to do this.Alot of what you said is foreign to me but I will do some research on alot of what you posted. Thanks for being detailed with the different options I have in front of me.
B
9
S
5
Posts: 126
Reputation: 1,295

Post » Sun Jun 23, 2013 11:00 pm

@TheNewGuy Here is a capx example.
Click on the ground to spawn a seed, it will then grow. 5 events. You can change speed and height with the globals.
capx
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Mon Jun 24, 2013 12:32 am

This is pretty cool.You didnt have to go though all this bro! But I am very grateful to have had the chance to learn from you.Will this samestyle work if I have more tree parts?
B
9
S
5
Posts: 126
Reputation: 1,295

Post » Mon Jun 24, 2013 6:45 am

@TheNewGuy
More tree part ?
If you mean a higher tree, no problem.
If you are looking for a tree with horizontal branches too, it should, you will have to create a "branch" sprite, and spawn it randomly every 3 successful growth for example.
There is no need for any more sprite that this for the tree, as the tree can always be separated in 3 parts : the base, the middle and the top (top and middle being the same sprite : "treePart")
B
17
S
8
G
4
Posts: 461
Reputation: 6,097


Return to How do I....?

Who is online

Users browsing this forum: Darknessed, ismael123, Yahoo [Bot] and 8 guests