pygame is
Simple DirectMedia Layer is
Site Swing
Python PyGame Tower Defence

Python PyGame Tower Defence - 0.3.4

Austin Morgan (duckfin)



I'm closing the gap to Beta status. I'll be giving this project the Beta tag when it hits version 0.9. I've got a lot of work to go before it gets there, but the game is already quite playable. The basics are typical to Tower Defense games all over.

There are only seven maps thus far, and only three playable. I have not put great effort into balancing them yet, as things change constantly. That said, I played through all of them before releasing this and found them to be fairly spot-on in difficulty, if a bit lacking in variety. Balance will not be a top priority until the Beta, version 0.9.

The art is nowhere close to tops and there is no sound whatsoever. I am neither an artist nor musician. If anyone would like to contribute either, I would happily give credit for your work.

Comments are welcome and encouraged!


*Explosions. *Enemy images. *Options in options.txt *Tower clipping detection. *Shooting lines option. *Max and min enemy health options. *Pause between waves, length option.


Home Page:


click to view original size


Python PyGame Tower Defence - 0.8.7 - Aug 27, 2013
Python PyGame Tower Defence - 0.8.6 - Dec 17, 2012
Python PyGame Tower Defence - 0.8.5 - Nov 18, 2012
Python PyGame Tower Defence - 0.8.3 - Jun 15, 2012
Python PyGame Tower Defence - 0.8.1 - Apr 14, 2012
Python PyGame Tower Defence - 0.8.0 - Mar 10, 2012
Python PyGame Tower Defence - 0.7.7 - Jan 28, 2011
Python PyGame Tower Defence - 0.7.6 - Jan 13, 2011
Python PyGame Tower Defence - 0.7.5 - Jan 9, 2011
Python PyGame Tower Defence - 0.5.7 - Apr 1, 2010
Python PyGame Tower Defence - 0.5.6 - Mar 14, 2010
Python PyGame Tower Defence - 0.5.5 - Mar 11, 2010
Python PyGame Tower Defence - 0.5.4 - Mar 9, 2010
Python PyGame Tower Defence - 0.5.3 - Mar 2, 2010
Python PyGame Tower Defence - 0.5.2 - Feb 25, 2010
Python PyGame Tower Defence - 0.5.1 - Feb 25, 2010
Python PyGame Tower Defence - 0.5.0 - Feb 21, 2010
Python PyGame Tower Defence - 0.3.5 - Oct 14, 2009
Python PyGame Tower Defence - 0.3.4 - Oct 13, 2009
Python PyGame Tower Defence - 0.3.2 - Oct 12, 2009
Python PyGame Tower Defence - 0.3.0 - Oct 11, 2009
Python PyGame Tower Defence - 0.2.6 - Oct 8, 2009
Python PyGame Tower Defence - 0.2.4 - Oct 7, 2009
Python PyGame Tower Defence - 0.2.2 - Oct 6, 2009
Python PyGame Tower Defence - 0.2.1 - Oct 6, 2009 account Comments

If you wish to leave a comment with your account, please sign in first.

September 1, 2013 6:56pm - Gummbum - nickname: (gummbum)
Nice work! Fun game.

Do you have an interest in changing the right-angle paths to curves? Figuring this out was a major challenge for me, but it was worth it. A fast bezier curve algorithm can gen curves in real time, and it's pretty easy to use. If you don't mind the offer, have a look at a little bit of code from

1) In lib/ see function calculate_bezier().
2) In bin/ see, a mini editor for developing curves.
3) If you need to see it in use and enjoy self-punishment :) see Enemy class and subclasses lib/

If you don't have an interest, ignore the suggestion. =)

January 15, 2011 6:21pm - Austin Morgan - nickname: (duckfin)
Kilon and Donpachi, thank you both for your feedback!

The big issue here is a result of my picking this up after so long an absence, and I apologize for this. The only map that currently works is "Simple". I wrote that in some document somewhere waaaay long ago, and just took it for granted that my players would know. Not a very good way to develop, eh? :P

I'll have it as the only selection in the next version... which should be out in the next few days. I apologize again for the issues, sometimes I am oblivious to the simplest issues :P

@Donpachi: Double thanks for the KEYDOWN suggestion. I only have the multiple-wave issue on rare occasions, but I never could figure out why... and that's why :)

@Kilon: Try using the Simple map. I actually develop in Snow Leopard, so I know it should work. You're right that '.' files in OSX are hidden. That particular one is a special file created because I use svn as version control :)
January 15, 2011 3:19am - Donpachi - nickname: (donpachi)
I got it to crash immediately. Can't seem to reproduce it, but it involved normal gameplay of placing towers, upgrading them and launching a new wave. That final action put it back to the main menu without any console messages, and then clicking the same map (the topmost one) again brought up a traceback.

Traceback (most recent call last):
File "", line 103, in <module>
File "", line 83, in main
screen,selected,wavenum = MainFunctions.workEvents(screen, selected, wavenum, Sender)
File "/home/sami/python/outside/towerdefence/src/", line 114, in workEvents
wavenum = EventFunctions.nextWave(event, wavenum, Sender)
File "/home/sami/python/outside/towerdefence/src/", line 65, in nextWave
screen = pygame.display.set_mode((localdefs.scrwid,localdefs.scrhei))
NameError: global name 'pygame' is not defined

I think you should launch nextWave with a KEYDOWN event, not using pygame.key.get_pressed(). By pressing and holding keys, I can get the functions like nextWave to launch several times before the sanity check says that enemies are already on the screen. Highest amount of waves that can generate at once seems to be 8 for me. It wouldn't be a problem, but this sometimes happens even when trying to get only one new wave.
January 14, 2011 7:53pm - Kilon Alios - nickname: (kilon)
Does it not run in macos snow leopard

Error :

Traceback (most recent call last):
File "/Users/dimitrischloupis/Downloads/src/", line 103, in <module>
File "/Users/dimitrischloupis/Downloads/src/", line 47, in main
background = mapvar.loadMap((scrwid,scrhei),pickMap())
File "/Users/dimitrischloupis/Downloads/src/", line 132, in loadMap
File "/Users/dimitrischloupis/Downloads/src/", line 26, in getmovelist
f = open(os.path.join('mapfiles',str(self.current),'movefile.txt'))
IOError: [Errno 2] No such file or directory: 'mapfiles/.svn/movefile.txt'

cant find .svn folder . I think macos hides folders with "." in front of the name , so maybe its a good idea to rename your folder.
January 13, 2011 7:07pm - Austin Morgan - nickname: (duckfin)
Ok, fixed the Upgrading Towers issue, the others are still outstanding. I wanted to go ahead and get this release pushed out, so I'll grab those on the next go around :)
January 13, 2011 1:59pm - Austin Morgan - nickname: (duckfin)
Thanks for the feedback, Shanti!

*Starting waves: I was wondering how people would feel about this change. Previously, I had a button in a side panel. I didn't like the entire implementation of the panel, so I decided to remove it, along with the "Next Wave" button. I'll work to put a button back in :)
*Upgrading towers: The money issue is something I knew about, and is easy to fix... and I just never did, haha. That'll definitely get fixed up in the next release. As for explanation and cost, I'm going to add in a pop-up similar to the ones for tower icons. That'll take a few minutes of coding, but nothing major. It's on my to-do list for this next version.
*Not clearing data: Something I was totally unaware of! Thanks for pointing it out :) Again, an easy fix, so it should be worked up by the next release.

And, guys and gals, HOPEFULLY I'll get the next release out by Saturday (or even before...). Don't get too excited, most of the improvements have been "under the hood" so to speak, but they make the code much neater and easier to work with... meaning better and quicker releases in the future!
January 12, 2011 8:51pm - Shanti Pothapragada - nickname: (rgbdreamer)
Starting waves with the N key needs to be clearer. A button would be better.

Upgrading the towers does not check to see if you have enough money. I upgraded two towers until I had $-4000, then rapidly hit 'N'. There is no explanation of what the upgrade icons do. The icons are good, but how much does each upgrade cost? How much do they add?

After beating a map, it lets you select a new map, but it doesn't clear data from the last game.
January 9, 2011 12:42am - Austin Morgan - nickname: (duckfin)
So, I've gotten some free time recently and actually managed to push out a release! I had gotten Version 0.7.0 ready for release... and never posted/published it, for whatever reason....

Anyhow, 0.7.5 is out! I actually headed back into Photoshop for a tad (for better or worse...). That ugly panel on the right is GONE! Upgrading and selling have been replaced by a radial menu of icons, ACTUAL ICONS, that pop up around a selected tower. Ranges are represented with alpha'd transparent filled circles, though they're a tad misleading (something I'll fix here soon). As for the balance of the game... eh, it hasn't gotten any help yet.

Here's what I'd like to get feedback on, should some people be so kind:
*Tower abilities (extend range and extra damage)
*Tower base statistics (how towers start out)

Thanks to all that have downloaded. I was PLEASANTLY SURPRISED to find the last version had 1,232 downloads. WHOA. I never thought one release would get to numbers like that. Thanks again, and hopefully I'll be able to push out some more updates here soon.
September 14, 2010 1:27am - boe - nickname: (rerako)
I found a simple way to boot up the enemies difficulty just by adding an exponential like around 1.3 to the end of the enemies self.hp and self.armor in the previous version 0.5.6, It became much more harder(I couldn't beat it...), though you kinda need to balance the reward, speed of enemies, tower abilities(It needs to show a bit more individual attributes). Though I can't change it with the new version, which is kind of a problem for me. I'm kinda hoping for someone to help me on this small problem.
April 14, 2010 10:30am - Donpachi - nickname: (donpachi)
I tested the new version, and was surprised to get 1500 money to start with. :) But even after fixing it back to 100 in the localdefs file, I think the maps are just way too easy. Or perhaps it's the overly effective upgrading that the towers have. I didn't use anything but a single cannon tower for any game, and always had heaps and piles of money at the end. I'd crank up the costs and drop the effectiveness of the attack upgrade to about 1/4 to 1/3 of what it now gives. Even after that the enemies need more armor, but the exact numbers would need a lot of testing... That would drive people to place more towers of lower levels along their paths, giving a more hard-fought feeling to winning the game.

Maybe you could include one super-hard map, that no one is even supposed to be able to manage to fight the end? But once the multiple entrances are working, that might help some. (But a super long range cannon tower near the base will cover everything anyway)
March 22, 2010 12:11am - Austin Morgan - nickname: (duckfin)
Hey all, quick post: Classes started back, and I've got a lot on my plate all at once. This is the reason I haven't released an update recently, and the reason I likely won't release one for a week or two. I love working on this project, but finishing up college is top priority.

I PROMISE that I'll get a new release out in the next two weeks, at least; and I'll make that an absolute maximum time between my updates.

Thanks to the players, and check back soon!
March 16, 2010 2:31pm - Austin Morgan - nickname: (duckfin)
Hey, Donpachi, I was hoping for some feedback on the mapmaker, and you came through!

Thanks for pointing out the lack of documentation. Having programmed it myself, I suppose I just took the instructions for granted and didn't pay much attention to them. I'll make them more detailed in the next update. Hmm, I didn't think it crashed, I'll definitely look into those bugs.

Lacking mapproperties editing was something I was aware of. The mapmaker was kind of a quick thought at the end of what I planned for the last update, but I got involved with it and took it further. When I got done with what's in the update, I realized I needed a way to edit mapproperties, but I foresaw that taking quite a while. I think the key to implementing it nicely is design, so I'm taking my time to plan it well. At the very latest, 0.6.0 should have a mapproperties editor :)

Thanks again!
March 16, 2010 6:49am - Donpachi - nickname: (donpachi)
Arg, message got wiped out by for having the nerve to idle for 5 minutes...

Anyway, the game is looking better now with some new graphics. The last couple versions did quite a bit for the game. The mapmaker is pretty underdocumented currently. I had to dig out the 's' key information from the source, and I'm still not sure what the four path values in the save menu are. It crashed on several occasions: Pressing the save button twice, clicking on an empty map before selecting a block, and trying to save a baseless map. I also figured out the values in the mapproperties.txt by looking at the source, but I suppose manipulating those values should be a part of the mapmaker program eventually. Anyways, nice work so far.
March 9, 2010 2:46am - Donpachi - nickname: (donpachi)
I'll try it out for sure. When you mentioned treasures, I started to think about a roguelike treasure environment, for whatever reason. It would be fun if you could get equippables from the enemies, either for the towers or for the player. The problem is that it would pull the game sharply to a wholly different direction. Anyway once everything from the basic stuff works and is bug-free, a new layer or two of gameplay and/or management would bring the game up to another level. Graphically it needs just a little polish, which is easy to fix if you find someone who can draw stuff...
March 5, 2010 12:18pm - Austin Morgan - nickname: (duckfin)
Donpachi, thanks for the feedback! Most of what you've suggested has been "on the back burner" so to speak, for quite a while now: multiple maps, research, and moving towers. There are actually two maps in the distro, just rigged to only play the first because the second is quite untested. When they were both active (0.3.2 maybe? somewhere along there) you were allowed to move towers at every map switch, something I will implement again soon.

Interest is actually implemented, though it isn't balanced very well. In the latest version, you will need to buy the ability (upper right hand corner) before it is active, I believe.

I'm hoping to get some interesting and one-of-a-kind features in there at some point, I'm just trying to get a basic yet good game going first :)

Yes, you've read my mind! Haha, I actually re-wrote the Tower class way back in the 0.2 versions, but decided it was heavily un-optimized; HOWEVER, my programming skills were also very rusty back then, and I'm hoping to retry it in an upcoming version!

Thanks again for playing, I encourage you to try it out again, maybe after 0.6 comes out? :D

By The Way: Thanks for the 4/5 vote!
March 5, 2010 5:01am - Donpachi - nickname: (donpachi) - 4/5
I like it. Maybe you could add "more enemies" to your list of to-do items? Especially once you have some varied towers in. They could be immune to some type(s), etc.

The game is pretty quickly over and done with at the moment. Just adding more waves works to some degree, however I'd like to see something tangible and persistent to work with. Things I've seen in other TD games have been base building, technology research, moving towers, and money loans/interest, just off the top of my head. Currently this game has no "gimmick" which makes it an unique TD game (...or yet another copy of the same idea). Well, that's something to consider when everything else is in place.

The Tower class you have might be easier to work with in the future if you refactor it into smaller pieces. Having the general methods common to all towers of every type in a superclass could cut down the effort of adding new towers later. Then you just do a class Basictower(Tower) that fills in the blanks for the shooting method and all necessary data for upgrading. - Or then it could be more difficult, that's hard to say for sure. :)
March 4, 2010 12:08pm - Austin Morgan - nickname: (duckfin)
Thanks for the feedback! I'm glad you like the gameplay thus far :)

Haha that'd be amazing if you could do that, I'll take help from just about anywhere, especially with graphics! lol
February 28, 2010 4:08pm - An Ony Mouse - nickname: (anonymouse)
YES! Love the update! Kept trying to post a comment on 0.5.0 but it never worked. I LOVE 0.5.2! One thing: you REALLY need better graphics, especially for the base. You've already said somewhere you're not so good with graphics, but I'll have a shot at the base for you, in case you're interested ;)
February 25, 2010 12:38am - Austin Morgan - nickname: (duckfin)
Hey guys, if you haven't tried 0.5.0 or above, check out the latest version!
November 19, 2009 2:25pm - Dylan J. Raub - nickname: (dylanjraub)
1,000,000,000 dollars by the 360th wave...
November 19, 2009 2:22pm - Dylan J. Raub - nickname: (dylanjraub)
100,000,000 by 300th wave...
November 19, 2009 2:18pm - Dylan J. Raub - nickname: (dylanjraub)
Whoa... 2,000,000 dollars on the 240'th wave with just one slower and 16 cannons... that's not a good sign...
November 19, 2009 2:03pm - Dylan J. Raub - nickname: (dylanjraub) - 5/5
A game should be challanging, have many options, and also stay fun. This has the fun part, but the challanging part leaves after the 25 wave. I mannaged to get twentny cannons and ten slowers with 30000 dollars by wave 120. There needs to be more variaty, too. Other thatn that stuff, It's still as addictive as ever and as fun.
October 17, 2009 9:17pm - Mystex - nickname: (mystex)
Oh and another suggestion, can you get more money from monsters you kill so you can get more towers? Maybe do that instead of tweaking the towers.
October 17, 2009 9:16pm - Mystex - nickname: (mystex)
I could successfully download it this time. I still think the game is too hard tho. The towers are too weak. And, why did you remove the feature where the monsters come back around if you haven't killed them? I thought it was cool. Last thing, nothing happens when I click on "upgrade" or "sell".
October 14, 2009 6:45pm - Austin Morgan - nickname: (duckfin)
Yes, this is a Sourceforge issue. New files take up to a day to be posted and download-able, though they say it's temporary. Although I uploaded 0.3.4 yesterday, it just popped up about 3 hours ago. I just downloaded successfully, though I'm now thinking about hosting it elsewhere. Give it another shot next time you have some free time, and let me know if it still doesn't work. If it's still not working correctly, I'll re-host it asap.
October 14, 2009 2:59pm - Mystex - nickname: (mystex)
I can't download the game! It says the newest version is 0.3.2, which is obviously false. Also, the older download links don't work either.
October 13, 2009 6:49pm - Austin Morgan - nickname: (duckfin)
Hey guys, thanks again for the feedback and this new version should solve some of the problems. I have it where, at the beginning, if you have 0 cash, it automatically goes into the game. However, I don't know of that many times where you end up with exactly 0 dollars. Anywho, you can always press Space to move on. Towers on towers was solved. There's now an options file, and you can change the difficulty by lowering the enemy health multipliers there. There are explosions now, though they don't look very good. New enemy image, but it looks pretty bad on the background (I'm not color-coordinated at all). I'm always working on graphics, but being bad at arts in general... it always ends up bad. Gameplay has been slowed down with the introduction of 'downtime' between waves. The default is 10 seconds, but you can change it in options.txt. The shooting line was a great idea, and I've got that in there, though it's also an option in options.txt.

Cecil: I use sys.exit() to quit when your life is zero. I don't know of a better way to do it. I so far haven't had any errors with it. What system are you running on? Python version?
October 13, 2009 1:10am - CecilSunkure - nickname: (cecilsunkure)
After you lose and you select the no option from the popup, the window freezes. In order for me to close the window I had to select re open the file

As for gameplay, everything is too fast paced. This doesn't really allow you to test out strategies that might include buying certain towers and selling them later, since the entire game is going so darn fast..

Also, it might not be too difficult to add in shooting animations by drawing a line between the firing turret and an enemy, and then removing the line very soon after. Just a thought. Good Luck!
October 12, 2009 9:05pm - Mystex - nickname: (mystex)
Again, nice updates! :) It's nice to see how much each tower costs and having a little build time in the beginning. My suggestions: first off, the game is way too hard. Can you set different difficulties? Also, start the game by setting the "Tim e Left" to 0 when the player has finished building (out of money). Another thing, why can players put towers on top of other towers? It looks kind of ugly. And my last suggestion, can you have some better enemies, instead of just blue boxes? Maybe some explosion-animation for when an enemy dies?
October 11, 2009 4:54am - Austin Morgan - nickname: (duckfin)
Thanks for the feedback! It's so much easier to develop when I'm hearing what people want in the game! The balancing is still a little off, but I've got it to where I can do really well pretty equally across the different towers. Each tower should be a good improvement from the one before it. I can barely wait until the next time you try it out!
October 10, 2009 3:15pm - Mystex - nickname: (mystex) - 3/5
Nice updates! Thought now I would suggest improving the Sniper / Flame tower, make the player able to place a few towers before the game starts, and showing how much each tower costs. Other than that, nice game so far! :)
October 6, 2009 6:09pm - Austin Morgan - nickname: (duckfin)
You're absolutely right! Haha, actually when I started out, I was going to make something completely different. By the time I realized 1440x900 fullscreen was not what I wanted, I had already coded the entire program around that idea. I'm actually working on making it sizing-optional, so check back soon :) Thanks for your input!
October 6, 2009 3:54pm - Mystex - nickname: (mystex)
Nice game. Although the screen size is way to big. My screen is 1280x1024, so your game window won't fit on my screen. Plus, the game crashed in the beginning because it went fullscreen mode at once, and i got an error that said "No video mode large enough for 1440x900". I would make the game window smaller and make the game not fullscreen as soon as it starts. Give the players an options menu :P

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Feb 21, 2017

Jan 31, 2017

Jan 24, 2017

Jan 18, 2017

Jan 7, 2017

Dec 30, 2016

Dec 8, 2016

Nov 28, 2016

Nov 27, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)