Page 1 of 1

Tower Defense

PostPosted: Sat Nov 22, 2008 4:38 pm
by Killagram
:wink:
tdscreen.jpg

Re: Tower Defense

PostPosted: Sat Nov 22, 2008 8:09 pm
by makslane
The game looks nice and like the health bar by player demo.
Can you post the instructions of the game?

Re: Tower Defense

PostPosted: Sat Nov 22, 2008 10:47 pm
by Killagram
Click on a tower from the menu, then click the map to place that tower.
Press 'next wave' at the bottom to send the next wave of creeps.
Click on a tower to select it. Use upgrade button to upgrade it, $$$ button to sell it.
Click anywhere else to deselect it.

Actorname_______Contents

control__________startup variables(lives, cash), music
start____________Round changes, creep spawning
creep____________animation controls located in 'create actor', stat updating located in draw actor
laser(canvas)_____draws all health bars and laser beams
sizzle___________deals damage for lasers
button__________spawns towers, other functions
tower___________upgrades, targeting, cost all located in timers
button__________triggers timers for towers
clickr(filled)_____handles tower deselection
deselector(filled)_handles deselection in menu area
cursor__________handles mouseover events
next ___________displays next creep

Known problems:
damage/range towers are off the screen because their tower counterparts do not yet function correctly.
tower range seems to upgrade on its own
sometimes towers do not fire
sometimes upgrading/selling towers causes glitches
money/wave/costs/level difficulty have not been adjusted(testing needed)

Re: Tower Defense

PostPosted: Thu Nov 27, 2008 1:55 pm
by jimmynewguy
wow pretty amazing! :D

I searched through the code but i couldn't find how you did all the creeps having their own health bar, how did you do it?

Yea there are the bugs you mentioned; but the only thing i had trouble with is the towers not shooting, i dont know how you made that, and i probably never will understand.....YOUR AWESOME!! :wink:

Re: Tower Defense

PostPosted: Thu Nov 27, 2008 5:38 pm
by Killagram
Its simple once you understand.
First you create some arrays. The size doesn't matter as long as its 100 or more.
Then you reposition view and the canvas so that game center is in the upper left corner.
In this way, canvas x and y is now the same as game x and y.

Then the creep reports its x, y, and health into the arrays.

Creep>draw Actor>
Code: Select all
creeph[cloneindex]=health;
creepx[cloneindex]=x;
creepy[cloneindex]=y;


Then the canvas actor performs a loop to draw the bars.
canvas>draw Actor>
Code: Select all
int i;
    for (i=0; i<=100; i++){  // performs loop 100 times. The array size didn't matter as
                                       //long as its larger than this.
if (creepx[i]!=0){             // if creepx[i] equaled zero, then the creep isn't alive,
                                     //and we wouldn't want to draw. And any creep array
                                      //would work; creepx, creepy, or creeph.
 
    setpen(255,0,0, 0, 3);
    moveto(creepx[i]-10, creepy[i]-25);
    lineto((creepx[i]+10), creepy[i]-25);  // This part draws the red background bar
     setpen(0,255,0,0,3);
    moveto(creepx[i]-10, creepy[i]-25);
    testvar=rtb(creeph[i], thishealth, 20);          // rtb is a function to return
                                                         //the health/distance (see below).
                                                         //var 'thishealth' is the creep starting
                                                         // health, same for all creeps but
                                                         //goes up each wave
    lineto((creepx[i]-10)+testvar, creepy[i]-25); // This part draws the green bar
      }
                  }


global code>
Code: Select all
int rtb(float health, float maxhealth, int numbars)
{
    return (int)((health*20)/maxhealth);   //returns health as a range
                                                   // from zero to numbars(20)
}                                                 //numbars would need to be
                                           //the length of the total bar we want to draw
                                            //(20 in this case)
 


This wouldn't have had to be a function; i could have written it right into the canvas draw actor loop. I was just having fun with it.

Re: Tower Defense

PostPosted: Sat Nov 29, 2008 1:39 am
by Fuzzy
See this line?
Code: Select all
    for (i=0; i<=100; i++){  // performs loop 100 times. The array size didn't matter as


Well, you can simplify it.

Code: Select all
   for(i=0; i<sizeof(array)-1; i++)


array is the actual name of the array of course, and you use its "sizeof" -1 because an array is listed from 0 to n-1. So if your array is listed as 20 units when you make it, it will fill the space of 0 to 19.

It goes against my usual habit of not making the compiler figure out anything it doesnt need to, but this is a rather non critical spot. In a lot of cases I would just fill in the size by hand and be done with it. But if you are making code for someone else, it pays to be adaptive.

Re: Tower Defense

PostPosted: Sat Nov 29, 2008 10:25 pm
by BlarghNRawr
like vr defender y3k

Re: Tower Defense

PostPosted: Sat Nov 29, 2008 11:39 pm
by Killagram
Fuzzy wrote:See this line?
Code: Select all
    for (i=0; i<=100; i++){  // performs loop 100 times. The array size didn't matter as


Well, you can simplify it.

Code: Select all
   for(i=0; i<sizeof(array)-1; i++)




Using the number 100 is for demonstration purposes only (and this is the old version).

The new version uses actorcount(creep) in that space. This way we will avoid running the loop more than we need to.
(not actually in that space, another actor calculates it based off creep spawn/death, in this way actorcount will be calculated only 'actorcount("creep")x2 times perlevel....

:P

Some of the other loops do not utilize the full array; for instance, the targetid array is used by both towers and homing missiles, but homing missiles use 100-199 in the array, while towers use 0-99.

The targetid array is actually 1000 currently, because other objects may use parts of it, too.



The new version is underway, has little or no bugs, and is fully documented. It is well over halfway complete, and will be posted when finished.

The new engine can be altered to make rts/golem games too.