PDA

View Full Version : Cowon D2 Tower Defence (beta)


Ratshasa
08-19-2009, 19:44
Intro

Hello, users of this forum!

I haven't been active here, just lurking. I saw this (http://iaudiophile.net/forums/showthread.php?t=30206) thread, in which several users have requested a version of a Flash Tower Defence game that would work on the Cowon D2. Some games were posted, but they were too slow to be playable (or didn't work at all). Since I had some spare time and some experience in Flash, I decided to code a Tower Defence game myself.

!Warning! Long post is long

Links

You can grab the game from:

1) MediaFire (http://www.mediafire.com/download.php?0yy0lmon4oj);
2) Rapidshare (http://rapidshare.de/files/48158474/Cowon_D2_Tower_Defense.zip.html);
3) MEGAUPLOAD (http://www.megaupload.com/?d=7TTPWEXH).

You will download an archive, which contains the following:

1) D2_towerdef.fla;
2) D2_towerdef.swf;
3) map.xml.

1) D2_towerdef.fla
The source file, if anyone wants to check it out. It was saved as a CS4 file, if you use an earlier version than Flash CS4 and still want to check out the source, just tell me. I could use the help of a guy that has some experience in coding games (I have only worked on web sites until now) and making apps for the D2. !The code is not commented now! If you look through it and don't understand something, ask.

2) D2_towerdef.swf
This is the first file you'll have to copy on the Cowon D2. It was published for Flash 8, I don't know what firmware versions can run it. I've tested it on 3.11 for the D+, I guess it also works on the older 3.54.

3) map.xml
This is the second file you'll have to copy on the Cowon D2 (make sure it's in the same folder as the swf file). It contains alot of info, I'll cover it below.

How to play

Navigate through the menus to where you saved both the swf and the xml files and start the game. Choose the mouse control option (the one on the right). You'll get the following screen:

http://i32.tinypic.com/14ty9ex.jpg

Hit the "Play" button. Ooops, what't this? It asks me to restart the game, WTF man?! Frankly, I don't know. It refuses to open the xml file on the first go, although it works fine on a PC (if you know how to resolve this, please tell me). Just hit the "M" button, start the game from the menu again and it will work. After you hit "Play", this time you'll see the following:

http://i32.tinypic.com/123p8nq.jpg
Not looking so good, is it? Well, it will have to do for now. It's a 10x10 tile based map. Those solid gray blocks form a road, which the enemies will follow. You can't build anything on these gray blocks. You'll also see empty white areas, those will remain empty, you can't build on them (stupid? No, you'll see that everything can be changed if you have enough patience to read about the xml file). Finally, the third tile type, with thin gray outlines and a white fill. Those are the tiles you can build towers on. Press on one of those tiles and you'll then see the following:

http://i26.tinypic.com/2djqqo6.jpg

Wow, new stuff! The tile is now red, meaning it's selected. There's a white octogon surrounding the tile, that's the range of the tower - if an enemy is out of range, then the tower won't be able to fire upon it. Then you have two buttons. The first one says: "Buy tower 20 [gold]" (I used a small icon instead of just writing the word "gold"). The second button says: "Close menu", it will close the menu you have just opened. Below the second button you have some stats: what level you're on, how much health you have (meaning how many enemies may hit you before you lose the game), how much gold you have, how many towers you have and how many enemies you've killed. Hit the "Buy tower" button. You'll then see the following:

http://i25.tinypic.com/a46grc.jpg
Now that's one mean looking tower! So you've built your first tower. Now, enemies will start coming down the gray, blocky road...

http://i30.tinypic.com/21ozbdi.jpg
Oh no, a small red circle is coming down the road! Damn, there's more of them! Don't worry, your mighty tower will soon take care of them (very soon, in fact, if you don't edit the xml file). So now you have enemies dying left and right. When you kill enemies, you'll get gold. If you press on another buildable tile, you probably won't see the "Buy tower" button again. Why? Because you need 20 gold, and you can't afford that. If you press on the tower, and if you have 15 gold to spare, then you'll see a new button: "Upgrade". For 15 gold, you'll be able to increase the tower's damage. Great! For now, this is all you need to know: 3 tile types (1 blank, 1 road for enemies to follow, 1 buildable); 1 tower type (20 gold to build, 15 to upgrade); 1 enemy type (red circle, kill it to gain gold). If your health reaches 0, you'll be defeated. If you can kill all of your enemies, you'll be victorious! After you get a victory (or defeat) message, just press anywhere on the screen to play again.

The xml file

This little critter holds alot of info. You'll need to know how to work with xml to understand it (it's not that hard to learn). Let's dissect the file!

<map wpx='80,80,240,240' wpy='-12,180,180,-12' health='4' gold='30' tower='20' dmg='1' sp='10' upgrade='15' lvls='2' l1='3, 2, 1.5, 2, 3' l2='4, 2, 1.5, 2, 2'><map> is the root element. That other stuff, those are attributes.
wpx and wpy are the X and Y coordinates (separated by commas) for different points that the enemies will follow across the map.
If you can't work in Flash, you shouldn't mess with them, at least until I can come up with a nice map editor.
Health is the health you'll start with, the number of hits you can take before you're defeated.
Gold represents how much money you start with.
Tower represents how much a tower will cost; dmg, how much damage a tower will do at first; sp, the towers' projectile speed (I really recommend leaving it at 10 for now) and upgrade, how much you'll have to spend to upgrade a tower.
Next we have lvls, which represents how many levels the game will have (or how many waves of enemies you'll have to dispatch). Right now, there will be two waves, so there are two more attributes, with info about each of the two enemy waves. Let's find out what those numbers mean:

l1='3, 2, 1.5, 2, 3'This is info about the first wave. The attribute is called l1, so it's the letter "L" (small), followed by the number of the wave (1, in this case). This attribute stores 5 numerical values, separated by commas.
The first value represents how many enemies will attack on the first wave (in this case, 3).
The second value represents how much health the enemies of the first wave will have (in this case, 2).
The third value represents the speed of the enemies of the first wave.
The fourth value represents how much gold you'll receive for killing an enemy of the first wave.
The fifth value represents the time (in seconds) between the appearance of each enemy of the first wave.
So to sum it all up, on the first wave you'll be attacked by 3 enemies, with 2 health each, that will travel at a speed of 1.5 (need to experiment with this), they'll give you 2 gold if you kill them and they'll appear after intervals of 3 seconds.

Now with that in mind, the second wave is easy to understand:
l2='4, 2, 1.5, 2, 2'On the second wave, there will be 4 enemies, with 2 health each, traveling at speeds of 1.5, they will give 2 gold when killed and will appear at intervals of 2 seconds.

Now, let's say you want a third wave. Just modify the file, so you'll have lvls='3', and let's say you add a third wave that looks like this: l3='1, 12, 1.8, 10, 4' - you'll have a single enemy on the third wave, but he'll have much more health (12) and he'll travel faster (1.8), so he's a boss, let's say. But if you defeat this boss enemy, you'll also get alot more gold (10).

Now that we have enemy coordinates and waves covered, let's talk about the map. You'll see lot's of <row>, these are child elements of the root (<map>, in case you forgot). These also have (sub)child elements, <tile>.
If you count them, you'll find out that there are 10 <row>s, each with 10 <tile>s. Remember what I said earlier, about a 10x10 tile based map? Yes, now it's starting to make sense! Each tile has an attribute, called type.
If you have type='1', then in the game you'll get the blank tile.
If you have type='2', then you'll get the buildable tile.
If you have type='4', then you'll get the stone blocks, which the enemies walk on.
That's all there is to it!

Oh, and in case you were wondering what the /> or </row> and </map> are for, in xml all elements must have closing tags.

!Word of warning! The swf file won't handle errors nicely right now, so make sure you edit the xml file carefully.

How it all works

The swf file loads the xml document and interprets all the data there. It builds the map, tells you how much gold you have, it lets you build your towers and then it sends in the wave of enemies. If you want to know more, you'll have to start learning Flash and xml.

What needs to be done

Alot more (beta)! First, I have to find out how to load that xml file correctly, so you don't have to start the game twice. I could use the help of someone who has made other Flash apps for the Cowon D2 to resolve this issue.

Second, I have to come up with some formulas to calculate tower upgrades (right now you only get one more point of damage for each upgrade) and the price of the upgrades (they are all fixed now).

Third, improve the interface. This is where I could use tips and advice from anyone! The Cowon D2 has a small screen and a resolution of 320x240. Right now, the game has a 10x10 map, so each tile is 32x24px and there are 100 tiles. Would you like to see more smaller tiles (but, they will be harder to press)? Would you like to see the stats and the menu all the time? Would you like better looking graphics? Or do you have other ideas? Write them!

Fourth, I have to look through the code again and try to optimize everything and fix the bugs (also, comment the code so that other people can understand it). Sadly, the Cowon D2 just doesn't have enough power to handle this type of games (the game would work better if you could stand not seeing the projectiles). This game, as it is right now, will work with, let's say, 6 enemies on screen and 10 towers (maybe more), but you'll need alot of patience, 'cause it will move really slow.

Fifth, more content - more tower types, more enemy types, maybe more tile types.

Sixth, an easy to use map editor.

Credits

While I was the one who coded the game so far, I can't say the same for the graphics. I'm not good at drawing, so fortunately I've found some very nice collections at the Lost Garden (http://www.lostgarden.com/) site. I used stuff from Danc's Miraculously Flexible Game Prototyping Tiles (http://lostgarden.com/2007/05/dancs-miraculously-flexible-game.html) and Danc's Miraculously Flexible Game Prototyping Graphics for Small Worlds (http://lostgarden.com/2009/03/dancs-miraculously-flexible-game.html) (and now here's an idea for a game that would work better on the D2 - a turn-based strategy game).
Also, I didn't make the small picture with the tower in it, someone sent me the picture and I'm positive that person didn't make it, I'm not sure who to give credit to for this one. The nice, big font used is Black Castle, it's freely available from dafont (http://www.dafont.com/black-castle.font).

dmitankin
08-20-2009, 02:05
Yep, the D2 is not loading xml files from the first try. Here's how to do it:

var loadXmlTries:Number = 0;
var xml:XML = new XML();

xml.ignoreWhite = true;
xml.onLoad = function (success:Boolean) {
loadXmlTries++;

if (success) {
//load the settings here
}

xml.removeNode();
// Continue with initialization here
} else if (loadXmlTries < 2) xml.load("Settings.xml");
else {
// Load default settings here, the .xml file was not found
}
};
xml.load("Settings.xml");

Good luck with the game.

Doni
08-28-2009, 08:05
The tiles and the graphics are ok. The stats should be visible all the time. Maybe you coul add water ditches, swamps etc for the road to slow the enemies down.

R2D2-Ricki
09-05-2009, 07:42
its a nice game but I dont understand what i schould do with the code[confused]