• Create Account

## [SFML 2.1] Growing Plants

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1SharkBaitHooHaHa  Members

271
Like
0Likes
Like

Posted 30 August 2013 - 05:56 PM

Hello everyone!

it's been a long while since I've posted. I'll keep this topic short and sweet.

I just finished C++ at school and decided to start a project. Main game mechanic revolves around growing plants and using them in combat(still have a few ideas on this floating around but that's for another post another day ). I am in the early stages and have decided to represent the plants as rectangles and have them slowly increase their height to grow upwards.

I have created a Plant class that inherits from sf::RectangleShape. Plant has width, height, x, and y floats.When I create a new plant it will take a constructor Plant(float w, float h, float x, float y). It will then use setSize(sf::Vector2f(w,h)) for its size and then position itself using setPosition(x,y).

As it is, when I change the height of the plant using setSize(), the plant would grow downward. If I were to have the plant grow upward I would have to increase its height while also shifting it down using either setPosition() or move(). This doesn't really seem optimal but I can't really think of any better way of doing this.

Another concern is whether the variable growthRate of plants should be handled by a varying multiplier, or "tick". Perhaps better phrased, should I "grow" all the plants at the same time and they vary how much they grow( every 10 seconds plants grow a variable height y), or should I grow all plants a universal height and they vary how often they grow( every plant grows 10px but they each grow every t seconds). Any thoughts?

EDIT:

I was being silly and completely forgot how inheritance worked, solved it quickly, and removed that part. The part pertaining to the actual plant growth still remains though. Sorry! I was too quick to post

Edited by SharkBaitHooHaHa, 30 August 2013 - 06:23 PM.

### #2kd7tck  Members

735
Like
0Likes
Like

Posted 30 August 2013 - 06:34 PM

Might want to go with a tree building algorithm. An L-system fractal generator would work for something like this.

### #3AllEightUp  Moderators

5611
Like
0Likes
Like

Posted 31 August 2013 - 01:34 PM

Another concern is whether the variable growthRate of plants should be handled by a varying multiplier, or "tick". Perhaps better phrased, should I "grow" all the plants at the same time and they vary how much they grow( every 10 seconds plants grow a variable height y), or should I grow all plants a universal height and they vary how often they grow( every plant grows 10px but they each grow every t seconds). Any thoughts?

Growing plants can be simple or complex, it depends on if you just want them as decoration or if they have actual gameplay importance. Without gameplay importance, simple random growing is probably fine and there is little reason to get all that fancy. With gameplay importance, it depends on how far you want to go and what level of complexity is appropriate.

I once wrote a tree growth system which paid attention to the following:

1. Surrounding tree's, too much higher and it stunts the tree's growth due to lack of light.
2. Fitness. Too many tree's in close proximity and the strongest survives, the others die out.
3. Terrain, rocky- slow growth, dirt- decent growth, tilled fields- fast growth.
4. Water availability. Both rainfall and relative distance to sources.
5. Local terrain curvature, i.e. locations water will likely catch and sink into the ground.
6. All sorts of other things like pollution, high wind whatever other nonsense you might want to plug in.

It was pretty silly over detailed but that was important to the game concept since tree's were an important resource. For something that "looks" OK and might not be so important to game play, 1+2 and a simple concept of local steepness would likely give plenty of variation and interest to a growth system.

### #4SharkBaitHooHaHa  Members

271
Like
0Likes
Like

Posted 31 August 2013 - 11:04 PM

Ah, thanks for the replies guys! Just giving a quick update and some clarification. I scrapped the idea of using the RectangleShape class and decided to inherit from Sprite, as that took care of a lot more stuff for me. Also, my trees and plants aren't going to be geometrical entities themselves. Instead they are going to be textures. When a plant grows to a certain point it will change out textures, and some plants will even get a bigger texture. For example my tree would go from being 8x8 to 8x16. At this point I believe if I pass a bigger texture to the sprite using setTexture it would automatically scale itself as Sprite does not have a setSize method like RectangleShape did.

kd7tck:
That sounds like something really cool to research but alas that falls outside of the scope of my current ability and project I am merely dealing with tree sprites and the such. But thanks anyway!

AllEightUp:
I like the rules you have set up there, I think though my system will only worry about the plant's current hydration,temperature(accounts for sunlight as well as climate), and something resembling overall health. As it stands my game is going to be sidescrolling and my character is going to plant plants in pots, water them, and defend until they grow, at which point he can use them as allies. Once they mature enough, he can transfer them out of the pot into the ground to defend a certain location or provide access to certain location.