I've been silent for last few months and stopped my project due to various things (one of them becoming lazy after getting stuck at one point).
Few days ago I resumed working on it... and oh boy, working(!) features are starting to snowball one after another. Now, while progress is going on, I started to think about future improvements and several (higher level) questions appeared. Done with C# + XNA.
Please ask if you need any code, I currently don't know what to offer except for whole project. Also ask if there is anything unclear or that is not easily understandable, it's a bit hard to put in words what I exactly want.
This is how it looks currently:
Summary: metal tiles (and currently bricks) are indestructible, water is unpassable by tank but bullets fly over it, grass obstructs vision, blue tanks are AI controlled opponents, orange and green tanks are Player 1 and Player 2 respectively, 2 collided bullets disappear, non-allied tanks are destroyed when hit by allied bullet and instantly respawned.
Moving is restricted to 4 directions only; tiles and hitbox' are simple rectangles (a*a for tile and tank, a*b for bullet). Tiles and tanks with their bullets have their own separate class; each type of tile and tanks are stored into separate arrays.
So, the questions are:
1) Well, this one was quite hard for me to put into words. I already rewrote most of the code once (moved tanks and tiles to separate classes etc) and apparently I'll need to do it again - better right now white it isn't cluttered. Are there some tips on improving interactions between elements, adding new classes, detecting useless/redundant code etc. - in short, tips for writing a good code? I want to make that this project performs efficiently while having as much readable and adaptable code as possible.
For example, how can this:
// Definitions
public void MoveTank(bool HorAxis, int direction, bool cancel);
bool Collision(Rectangle Object, bool Projectile, string Direction, bool playerOwned);
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
Tanks[0].MoveTank(true, -1, false);
if (Collision(Tanks[0].TankHitbox, false, "Left", true)) Tanks[0].MoveTank(true, 1, true);
}
else if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
Tanks[0].MoveTank(true, 1, false);
if (Collision(Tanks[0].TankHitbox, false, "Right", true)) Tanks[0].MoveTank(true, -1, true);
}
else if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
Tanks[0].MoveTank(false, -1, false);
if (Collision(Tanks[0].TankHitbox, false, "Up", true)) Tanks[0].MoveTank(false, 1, true);
}
else if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
Tanks[0].MoveTank(false, 1, false);
if (Collision(Tanks[0].TankHitbox, false, "Down", true)) Tanks[0].MoveTank(false, -1, true);
}
if ((Keyboard.GetState().IsKeyDown(Keys.Enter)) && (Tanks[0].BulletLaunched == false))
{
Tanks[0].LaunchBullet();
}
be rewritten into something better and more clear? (Answer on my mind: using switch instead of multiple if..else)2) Can you recommend me some AI algorithms which could be useful for this? Current one is somewhat recreated by observing original NES game of the same name (some people may better know it under name of Tanks) which still needs to be fine tuned. It uses chance system of changing directions (almost 100% chance to keep current one, if collided with something selects between other 3 directions equally) which gives somewhat chaotic movement.
3) I need to implement destructible brick wall. My idea is to split a tile hitbox into 16 equal pieces and process collision with 2 or 3 closest adjactent pieces. Is that good solution, will it tax processing power and memory and do you have other suggestions?
Thank you very much for reading
Edited by Aurioch, 15 October 2012 - 07:21 PM.







