blitzxion / Tanks.js

Using Javascript and HTML5, watch the AI build up their army and battle each other!
12 stars 4 forks source link

Planes can render below other 'tanks' #14

Open derekgates opened 12 years ago

derekgates commented 12 years ago

Due to the rendering pipeline, we can draw planes under other 'tanks'.

        for (var n in Tanks) {
            if (Tanks.hasOwnProperty(n) && Tanks.contains(Tanks[n])) {
                if(TankTeam == null)
                    TankTeam = Tanks[n].getTeam();
                else if(Tanks[n].getTeam() != TankTeam)
                    AllOneTeam = false;

                Tanks[n].draw(ctx);
                Tanks[n].doStuff();
            }
        }

Since we don't sort by the type, a plan can render under a tank depending on where it is in the list.

blitzxion commented 12 years ago

Sorting the array of units on every iteration would be taxing on the system right? I wouldn't bother with it if it will.

derekgates commented 12 years ago

Well, I wouldn't suggest sorting every time.

We can have the master list of all tanks, like we have now (so we can check ALL units). Then include other sets of specific types; one for planes, one for tanks (and whatever else that needs Z-Index to be taken into account).

An item is created and put into the main Tanks Set and then the corresponding set for it's type (again, only for ones that need accurate z-index).

A draw comes in, paints the items from the actual tanks (low-zindex set) and then the planes (high z-index set).

blitzxion commented 12 years ago

Wouldn't the special set (purpose of knowing the pseudo z-index) require the X,Y coordinates, the angle, etc to properly read out the draw requirements? Also, removing two entries when a unit is defeated and maintain indexes, that could prove difficult.

I don't know, suppose I'm missing the idea here. We could shelf this issue until we rework the structure and other things of Tanks.js.