Wednesday, May 14, 2008

Make Trees, Not War

Latest version of the Treemaker.
Perhaps the last version?
It works!

Thursday, April 24, 2008

Wednesday, April 23, 2008

Trees Hate One Another

New version of Treemaker. It's automatically set in a two-player mode, to test, so realize that you are taking turns placing seeds and then branches and such for alternate trees. The player turn switches when you place a knot (not a branch with a leaf or root or an additional leaf). Sunlight gathering finally actually works, but resources are not properly-balanced (I'm working on it... but I'll probably get all of the basic parts working first).

Tuesday, April 8, 2008

More Things to Do:

1. Turn the branches into objects so that I may add a "IsAStem" Boolean property to each.
This property will be marked "true" if the branch ends up placing roots or leaves, and branches with "IsAStem == true" will have their growth handled differently. Turning branches into objects will also allow me to add properties like OriginalScale, which might be useful in setting the growth limits for said Stems (or perhaps these stems are simply not allowed to grow?), and ParentKnotIndex, which would allow me to delete branches and knots whose parents have been destroyed.

2. Figure out how to destroy branches, and make it so that destroying a branch kills all branches connected to the seed by it. Making the new branches AddChild onto the knot they sprang from (may need to use event.target, or even track the index of the event.target knot in a public variable) might just accomplish this.

3. Incorporate an "IsPlaceable" Boolean into the branch placement functions- it should change to "false" if the branch is overlapping an object that it cannot be placed upon (underground obstacles and enemy branches which are larger than it), and the branch placement function should recognize this and not allow branch placement there.

Treemaker Version 9

Here's the newest version of the Treemaker!
(Yes, I know it's been a while since my last post, and yes, I realize I skipped a version; version 8 incorporated things like resource calculation and the precursor to the current growth/shrinkage system.)

Instructions:
Click on the white screen to place a seed. Click on the seed to start placing branches. Branches below a certain length will spawn leaves or roots, depending upon whether they are above or below ground.
Press "a" on your keyboard to activate one round of resource calculation/growth. Pressing it quickly over and over again allows you to see lots of growth over time.

What is new:

1. Resources. Pressing "a" (make sure if you are playing with it in Flash itself, you disable keyboard shortcuts while you try it out) will activate a round of Growth. This calculates resources (including a function that, theoretically at least, tests whether each leaf is blocked by something else from the sun), meaning sunlight and roots, and then grows or shrinks each tree based upon its resource surplus/deficit.

2. Sunlight. I haven't gotten around to putting in the functions that will allow for two or more players, but they are almost there. The sunlight function draws a line from each leaf to the sun, then tests to see if anything breaks that line. It should(!) work.

3. Growth. Everything has been built and tweaked so that things should grow more or less like they are supposed to... Roots grow and shrink faster than branches/knots, and leaves do not shrink at all. The branch placement system has been changed to allow for this sort of thing without odd-looking graphical mishaps (for instance, all branches now start at the center of the knot which spawned them).
On a side note, there are now a few tree-type variables available for implementation. They're already in there as properties.

What I forgot to do:

1. Add a function that removes listeners from other knots while a branch is awaiting placement. There is still a bug remaining that will end a branch placement without a new knot, or with a leaf or something instead, if you click on a knot while you are placing a new branch.

Next time:

1. The Unlistener/Relistener functions (should be simple enough- just add a for loop that runs through each knot and removes its listener while the branch is being added, and another that adds the listeners again after its placement).

2. Multiplayer.

3. Resource limiting? Rather than not letting a player place new branches when they have negative resources (which could straight-out kill their chances of recovery), I think the shrinkage system is better- players can still come back from a bad turn, but they are penalized for poor building techniques by losing the strategic upper hand (their tree will shrink, and therefore the other player will be able to break through their branches). We'll have to see what happens through playtesting.

Tuesday, March 11, 2008

Idea for Multiplayer and Levels:

While one person takes his tree-building turn, the other player(s) expend resources on abilities to slow them down.
have a column of icons for different abilities for each player. keyboard controls their selection, activation, and control.

Example: While player 2 builds, player 1 decides to spawn a fire, which burns up random branches, destroying leaves and preventing growth for a certain number of turns.

Or: While player 3 builds, player 2 takes control of the pigs that spawn !!

Other ideas: root-eating/leaf-eating insects, squirrels that spawn seeds for sneak attacks, disease (contagious!), bomb fruits.

Ideas for levels so far: Normal field level, wherein one must capture pigs that fly by; Cave level, in which spots of sunlight are very important; Post-Apocalyptic city level, with underground and overground obstacles and bomb fruits? mines? lasers? something.

New Version of Treemaker

Treemaker version 7.

This is a huge update, though much of it is behind-the-scenes slickness.

New implementations:

1. Instead of click-and-drag, a click-and-click-again method is now used for branch placement. This helped fix a lot of the graphical errors...

2. Fixed rotation arc of roots and leaves. They now have a maximum rotation from the angle of branch placement, meaning awkward-looking leaves and roots are now less likely. Roots also sense when they are close to the surface and rotate down instead of looking at the angle of placement.

3. Extra leaves now appear from a leaf's stem when one clicks on a leaf. They have similar rotational properties as the normally-placed leaves, in fact they are identical, besides having been created by a different function. addRoot(), addLeaf(), and addKnot() are all separate functions, now. Much more streamlined. Too bad I was sloppy and ended up using two functions for the leaves- addLeaf() and addAdditionalLeaf(). But maybe the latter can be turned into addAdditionalLeaves(), and it can produce two leaves at once for the same cost as a branch+leaf. Or something. Trying to think in the context of strategy, here.

4. New branches now have a maximum scale equal to the scale of the knot they are building off of. This means no more huge branches coming off of tiny ones! This is a huge thing, and took much time. My solution involved recording the scale of the knot that is clicked on to begin the startAddBranch() method and then using it as a limiter. The syntax (and finding the event.target.scaleX command) was the difficult thing to figure out... event.target lets you access the clip (/object, perhaps?) that has been clicked on to start the current Listener method.

5. The Treemaker now keeps track of number of players and makes a newTree object that includes (so far) separate arrays for knots, branches, leafs, and Roots, the numbers of each, the branchLength for the tree (they can now be different!), and the player's resources, for each player. The newTrees are created and added to an allTrees array in a function called by the constructor function. Number of players and current player are now kept track of, as well, and all of this new organizational stuff is implemented (the program actually works with all of it, so far). This also took a long time, but it was mostly trying to translate hacked-together code into nice, neat code.


Fixed bugs (and how I fixed them):

1. Full-scale branch flashing for a moment at first click: I added a call for the rotate() method before the addChild for the branch (so the branch is rotated and scaled before it's placed). The rotate() method (along with pretty much everything else) received and overhaul.

2. Extra leaves appearing when trying to click-and-drag a new branch from an overcrowded knot: Making the branch building click-and-click-again fixed this; I actually decided to implement it correctly after it had been removed as a bug (#3).

3. Ground-level bug- sometimes leaves would appear below ground level, or roots above: This was fixed (more or less) by moving the seed slightly below ground level and having roots and leaves sense where they've been placed in relation to the ground level (instead of trying to use the coordinates of the point they've been built off of). Trace commands of groundLevel and the corresponding leaf/root variables were helpful.

4. Ends of new branches slowly cover up knots: I played around with this, ended up moving the registration for the branches up one point on the x axis, but decided that there needed to be some sort of limiter for the number of branches coming off of a single knot.

5. Roots scaling too small: I made them scale up according to a certain formula, instead. They start at half scale and go up from there. Looks pretty decent.


Bugs that Remain:

1. Once in a while, a new branch is placed slightly off of its knot, or a new knot is placed slightly off of its branch. No big deal; I also have no idea why it happens. Might not be happening in latest version.


Treemaker Parts Left to Implement:

1. Try adding new branches onto the ones they grow from with addChild(). Hopefully, this will make removing everything after a break in a branch as simple as removing the segment that broke.

2. Need a method to remove branch segments, for fighting and perhaps for own-tree-tweaking.

3. Add resources, including a method of calculating them (take lower number of sunlight & soil), a way of calculating sunlight and soil (need to figure out hit detection for the sunlight, probably), and something that keeps track of the resources as they are used (and prevents the player from using more than they have).

4. Add growth, after resources are sorted out. Each branch and knot's scale should be incremented by a certain amount for a certain resource cost, once the player's turn is over and remaining resources are calculated.

5. Add wind effect (leaves move in tandem according to some sort of timer-based formula function)- have to send each player's array of leaves through a function that changes their rotation.

Metagame Parts Left to Implement:

1. Title screen, with buttons that allow the user(s) to change the settings- pick number of players and each player's tree type, as well as level select. Need to make art for title screen, buttons, and different trees. Plus the graphics for every level.

2. Figure out the whole "level background" thing. This means turning the parallax scrolling level I made into a nice, neat com package that can be imported by my document class. And designing and drawing new levels. Eventually. This includes adding wind, sun, etc.

3. The actual turn structure! This is big, but probably not that difficult to figure out. Players each have a turn, starting from player one and rotating through until the number of players has been reached. Each player's first turn consists of placing their seed. Subsequent turns allow the player to spend resources on branches (MAKE SURE THERE'S A COUNTER TO KEEP TRACK OF RESOURCES OF EACH PLAYER) or bank them to make their tree's scales larger. Fighting comes into play. When every player's turn is over, the SUN comes by and grants a refill on resources (up to each player's resource cap, determined by number of leaves and roots). This means there needs to be a way to determine how much sunlight each tree gets (sunlight needs to be blockable by branches/knots). This is while the win conditions are not met, of course-- CAPTURE THE FLAG, wherein every tree tries to rack up points by controlling (being the only one with branches in) a certain area, seems like a good idea.

RESOURCE NOTES: Additional leaves should cost less than original ones (maybe?), smaller branches should cost less (maybe?)

4. Results screen, after the game has ended (player reaches goal (or number of capture points) or destroys first branch of all other players). Have some player stats (number of branches, leafs, and roots broken, number built, number of players killed, time in capture area, resources collected, etc.

IDEA: Maybe make this a capture-the-flag sort of game? Or have options for different playing modes- capture the area, deathmatch, grab the pig, or twixt (get across the opponent to the other side).

5. Additional game elements: squirrels/new seed placements, rain?, disease, fire?