Im working on my game for quite a while now and now unfortunately i ran into a couple of problems.
**1. **The first one is deleting stuff from arrays. When units die, when bullets impact, when explosions are done they should be removed from the array that loops em. I skimmed Charlehs guide (http://www.kirupa.com/forum/showthread.php?t=281507) and read the responses, some one said he added the ‘to-remove-objects’ in a remove array. I thought that was a very good idea and did so myself. I made a remove class and instead of deleting em right away, i delete em at the end of a loop. Unfortunately that still aint working correctly. Stuff like shells and explosions are created and removed too often, therefor things mess up when they are removed, removing not only those which should be removed but also those who are still halfway there. That means that shells do not hit their targets, no explosion follows and most importantly, not damage is done.
This is what I do, a turret or tank, doesnt really matters. Seeks the nearest target, fires if it can and reloads if not, repeat. When it fires it creates a shell, gives in the location of which it is launched and to where it is targeted to.
The shell then checks if its at the target position, if not: move, if so: remove. If it removes it plays a new explosion, it adds it self to the ‘to-delete-array’ and checks if it target position matches any of the objects position, if so it reduces it health.
The shell-class:
new Explosion (tx, ty);
_root.clDel.theArray.push(new Array(_root.shellsArray, nr));
checkHit(tx, ty);
The clDel class:
class clearDels
{
var theArray;
function clearDels()
{
theArray = new Array();
}
function action ()
{
for (var i = 0; i < theArray.length; i++)
{
theArray** = ArrayMan.deleteNr(theArray**, theArray*[i+1]);
}
theArray = new Array();
}
}
The ArrayMan class, deleteNr method:
static function deleteNr(array, nr)
{
var i
var deleteNr = undefined;
var theArray = array;
for (i = 0; i < theArray.length; i++)
{
if (theArray*.nr == nr)
{
deleteNr = i;
}
}
theArray.splice(deleteNr, 1);
return theArray;
}
All my object get pushed in different arrays, building in building arrays, unit in unitarrays, explosion in explosion arrays etc. I could reduce the number of total arrays but I still need a difference in building and unit arrays, as thats a matter of selection stuff…
I know this is pretty crappy coded, but im doing my best The truth is, i thought i knew enough about OOP to code an rts without knowing inheritance. Crappy, but true. Should have known better and now i do not want to recode my whole engine AGAIN. I just wanna finish a project in flash then go on with c# create a real game.
I also know that I shouldnt really do “hitTesting” this way. I should basically take a snapshot, calculate if the shell will hit anything, and then play the animation and health reduction stuff etc. However if you read the last paragraph you should know why I wouldnt do such a thing.
**2. **Okay I know that was alot of text and I doubt anyone would still try and help me so ill keep this second thing short.
My game uses bitmap rendering, shouldnt it be very easy to create a class that would copy the “what you see”-bitmap to a new bitmap and export it as a bitmap file to your computer? Sort of like a printscreen, but then with flash?
Whoever read it all, thx, hope you can help me, much appreciated