Tower Defense

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

Tower Defense

Postby Killagram » Sat Nov 22, 2008 4:38 pm

:wink:
tdscreen.jpg
Attachments
TowerDefense-v1.zip
(9.32 MiB) Downloaded 468 times
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
-Brian W. Kernighan
User avatar
Killagram
 
Posts: 31
Joined: Sun Aug 10, 2008 8:49 pm
Score: 5 Give a positive score

Re: Tower Defense

Postby makslane » Sat Nov 22, 2008 8:09 pm

The game looks nice and like the health bar by player demo.
Can you post the instructions of the game?
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Tower Defense

Postby Killagram » Sat Nov 22, 2008 10:47 pm

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)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
-Brian W. Kernighan
User avatar
Killagram
 
Posts: 31
Joined: Sun Aug 10, 2008 8:49 pm
Score: 5 Give a positive score

Re: Tower Defense

Postby jimmynewguy » Thu Nov 27, 2008 1:55 pm

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:
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Tower Defense

Postby Killagram » Thu Nov 27, 2008 5:38 pm

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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
-Brian W. Kernighan
User avatar
Killagram
 
Posts: 31
Joined: Sun Aug 10, 2008 8:49 pm
Score: 5 Give a positive score

Re: Tower Defense

Postby Fuzzy » Sat Nov 29, 2008 1:39 am

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Tower Defense

Postby BlarghNRawr » Sat Nov 29, 2008 10:25 pm

like vr defender y3k
Download Game Music
current projects:
Bold! ?% Started mechanics
Unnamed puzzle game 60% --i need a name!--
User avatar
BlarghNRawr
 
Posts: 767
Joined: Wed Jun 25, 2008 12:36 am
Location: Not using G-E anymore. Now using Source SDK.
Score: 27 Give a positive score

Re: Tower Defense

Postby Killagram » Sat Nov 29, 2008 11:39 pm

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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
-Brian W. Kernighan
User avatar
Killagram
 
Posts: 31
Joined: Sun Aug 10, 2008 8:49 pm
Score: 5 Give a positive score


Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron