Saturday, March 31, 2007

Weapons are done!

I finished off the weapons. Well, most parts. There are a few minor things that I need to change. But most of the work is completed.

First of all: I changed how units keep track of their internal state. Initially, I had a unitState attribute in each unit class. Which worked reasonable, until I started adding attacking. I had to define several states, such as AttackGroundRotate, AttackGroundMove, AttackRotate, AttackMove, AttackGround and Attack. Yes, that's overkill...

What I did was implement the unit states as a stack. I then cut down the states to their basics: Move, Rotate, RotateTurret, Attack and AttackGround(There are a few more, but I'll safe you the hassle for those). When a unit is sitting idle, it's state contains just 1 state: Guarding. When moving the unit, it's a matter of pushing a bunch of states onto the stack and the unit manages after that. For moving, I just push Move and Rotate onto the stack. In the rotate state, it will determine the desired angle, rotate to it and pop the state. The next time the unit updates, it starts moving.

I also did the same with the gun, except I did make a different state for it, since some units have a seperate turret sprite. This will rotate the unit normally for units without a turret, and rotate the actual turret for those units who have one.

With the stack I also implement a CancelOrders function, which allows you to cancel whatever your unit is doing. However, it has a tiny bug(which I noticed after comitting my code, so I'll fix that after publishing this post): When moving, it stops the unit directly. The unit doesn't stop in the middle of a tile as it should.

The code for checking distance to the target, determining if the weapon is ready, etc. is very exciting to tell about. Only exciting thing I can think of is are the images below.

Only things left to do with weapons: Have the ornithopter fly attack patterns(Since it can't hover), have rockets leave smoke trails(Not in the original Dune 2 I believe) and have units spray smoke when their HP is below 50%.

As for now: Images!Medium Tank is being ordered to attack. Ornithopter is there for no reason

Medium Tank just fired it's weapon at the quad, which is doing nothing...

For those who are wondering why there isn't a healthbar showing in the first pic: I removed them, since I need to redo how healthbars work. The old way sucked donkey balls. Also, there is no image of the quad exploding, since I tried 4 times and still couldn't get to show the explosion.

Wednesday, March 28, 2007

Weapons are nearing completion

So, I got most of the weaponry in. I got a Weapon class to fire projectiles(Perhaps I have to add some more classes, such as a BulletWeapon and MissileWeapon, but not right now). The projectiles are in aswell, and this includes bullets and missiles(Which happen to be the only projectiles in the game). Also, the death hand missile is in, including 3x3 explosions.

I took a different way for missile weapons that the original. In the original there were 16 images of the missiles, where each image was rotated 22.5 degrees. Since the original had to run on 8 to 16 Mhz machines, rotating the images in real-time was probably impossible, so they just had a bunch of pre-made images. In assume they used a Cos/Sin lookup table during the game to calculate the trajectory of the missiles, since Cos/Sin calls are pretty expensive.

However, I wanted to save myself the hassle of having to calculate which of the images I had to use, so I cut up the images, took the 0 degree image, enlarged it and use that myself.

I did run into some serious trouble with the rotation tho. At first, I couldn't figure out how to rotate the 2D image without upsetting the entire world view. Turns out I forgot to restore the original Transform. Oops. And, I didn't quite understand that I needed to take the negative value of atan2() when the adjacent side of the triangle is below 0. Took me all day long to debug. But it works now.

As promised: The image. It shows randomly launched Death Hand missiles flying to their destination and explode. Oh, and a lone tank which I used to test the bullet and missile weapons on.

The next step is for weapons to have some intelligence: They have to determine if their target is in range, and if not, don't fire. After that, I can actually implement inflicting some damage based on armor stats. If that's all working, I can do some testing, and implement unit squashing. Oh, and corpses.

Monday, March 26, 2007

Rotation works... Finally...

Ok, so I finally managed to fix all the weird shit concerning rotation and movement. The large break from coding really helped on that.

Basically, what I did was this: I ditched all my previous movement and rotation code. I then re-build everything up from the ground using sheer logic. It was actually pretty easy.

I did make the same mistake I made the first time with my movement code. I rounded the location X and Y to an integer value(they're stored as floats). So, when a unit would move to x.86, it would round to x + 1, which obviously is somewhat correct. However, if I would start moving from this location, the angle wouldn't be correct anymore, and the unit would just move over a bunch of tiles it wasn't suppose to be on. I noticed this when I would start printing out the x,y locations after movement. Easily fixed.

After that, my rotation code was simple. The old code was overly complicated, while my current code(Including determination of which direction to turn in) is something like 20 lines.

Now I only need to re-work this code so that it also works for the turret, and the problem is solved. Then turretted buildings/units can share the same code.

So, later today I'll start adding weapons. I think I'll start out with the medium tank, since it's the coolest tank of all(coolest graphics, I have no idea why).

No images for now, perhaps after I got some weapons in.

Friday, March 23, 2007

Dual-Core ready!

I did some coding in the past days when riding the train. However, when I moved my code from my desktop to my laptop(which has an AMD x2 in it), I noticed movement had crawled to a slow.

I tried to fix the problems with setting ProcessAffinity, ThreadAffinity and whatnot, which all failed horribly. Eventually Mithrandir pointed out that DateTime.Now has a Ticks property, which holds the number of 100 nanosecond thinks since 1 jan 0001. I re-write my FpsCounter class to use that, and since then, it worked like a charm again.

So, if I recall correct, I was working on the unit rotation code, so I'm back to checking out the status of it, and probably re-write it completely. I remember it was flaky last time I was working on it. After that, I'll add some weapons.

On other news: These Tower-Defense games are all hawt all the sudden. Perhaps I'll write a little one myself using the current dune 2 remake engine. Shouldn't take too long once the building construction stuff is in.

Wednesday, March 21, 2007


I read some comments from people who wanted an update on the game and/or progress. So I figured, I'll do that now.

First on the game: I did some minor work on the game since the last update, but nothing major. The reason: I'm busy as hell with my own business and school. Especially school has the highest priority over anything else. Should be obvious why.

I intend to get the latest DirectX SDK on my laptop(Which I bought last december) and start doing some development for the game again. I need to fix the unit rotation a bit, since it's fucked up(The units sometime appear to wiggle, moving a pixel up and down while moving. Seems a bit odd, so I need to find out why.

After that, I intend to add weapons. Explosions are already in, so adding in the weaponry shouldn't be too much of a problem.

I want to spend some time today on coding, since I don't have an awful lot of to do(Except unpacking boxes. I moved again ;_;).